tie.pass.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <tuple>
  10. // template <class... Types> class tuple;
  11. // template<class... Types>
  12. // tuple<Types&...> tie(Types&... t);
  13. // UNSUPPORTED: c++98, c++03
  14. #include <tuple>
  15. #include <string>
  16. #include <cassert>
  17. #include "test_macros.h"
  18. #if TEST_STD_VER > 11
  19. constexpr bool test_tie_constexpr() {
  20. {
  21. int i = 42;
  22. double f = 1.1;
  23. using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>;
  24. auto res = std::tie(i, std::ignore, f);
  25. static_assert(std::is_same<ExpectT, decltype(res)>::value, "");
  26. assert(&std::get<0>(res) == &i);
  27. assert(&std::get<1>(res) == &std::ignore);
  28. assert(&std::get<2>(res) == &f);
  29. // FIXME: If/when tuple gets constexpr assignment
  30. //res = std::make_tuple(101, nullptr, -1.0);
  31. }
  32. return true;
  33. }
  34. #endif
  35. int main()
  36. {
  37. {
  38. int i = 0;
  39. std::string s;
  40. std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
  41. assert(i == 42);
  42. assert(s == "C++");
  43. }
  44. #if TEST_STD_VER > 11
  45. {
  46. static constexpr int i = 42;
  47. static constexpr double f = 1.1;
  48. constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
  49. static_assert ( std::get<0>(t) == 42, "" );
  50. static_assert ( std::get<1>(t) == 1.1, "" );
  51. }
  52. {
  53. static_assert(test_tie_constexpr(), "");
  54. }
  55. #endif
  56. }