tie.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <tuple>
  9. // template <class... Types> class tuple;
  10. // template<class... Types>
  11. // tuple<Types&...> tie(Types&... t);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <string>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #if TEST_STD_VER > 11
  18. constexpr bool test_tie_constexpr() {
  19. {
  20. int i = 42;
  21. double f = 1.1;
  22. using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>;
  23. auto res = std::tie(i, std::ignore, f);
  24. static_assert(std::is_same<ExpectT, decltype(res)>::value, "");
  25. assert(&std::get<0>(res) == &i);
  26. assert(&std::get<1>(res) == &std::ignore);
  27. assert(&std::get<2>(res) == &f);
  28. // FIXME: If/when tuple gets constexpr assignment
  29. //res = std::make_tuple(101, nullptr, -1.0);
  30. }
  31. return true;
  32. }
  33. #endif
  34. int main(int, char**)
  35. {
  36. {
  37. int i = 0;
  38. std::string s;
  39. std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
  40. assert(i == 42);
  41. assert(s == "C++");
  42. }
  43. #if TEST_STD_VER > 11
  44. {
  45. static constexpr int i = 42;
  46. static constexpr double f = 1.1;
  47. constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
  48. static_assert ( std::get<0>(t) == 42, "" );
  49. static_assert ( std::get<1>(t) == 1.1, "" );
  50. }
  51. {
  52. static_assert(test_tie_constexpr(), "");
  53. }
  54. #endif
  55. return 0;
  56. }