make_tuple.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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<VTypes...> make_tuple(Types&&... t);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <functional>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. int main(int, char**)
  18. {
  19. {
  20. int i = 0;
  21. float j = 0;
  22. std::tuple<int, int&, float&> t = std::make_tuple(1, std::ref(i),
  23. std::ref(j));
  24. assert(std::get<0>(t) == 1);
  25. assert(std::get<1>(t) == 0);
  26. assert(std::get<2>(t) == 0);
  27. i = 2;
  28. j = 3.5;
  29. assert(std::get<0>(t) == 1);
  30. assert(std::get<1>(t) == 2);
  31. assert(std::get<2>(t) == 3.5);
  32. std::get<1>(t) = 0;
  33. std::get<2>(t) = 0;
  34. assert(i == 0);
  35. assert(j == 0);
  36. }
  37. #if TEST_STD_VER > 11
  38. {
  39. constexpr auto t1 = std::make_tuple(0, 1, 3.14);
  40. constexpr int i1 = std::get<1>(t1);
  41. constexpr double d1 = std::get<2>(t1);
  42. static_assert (i1 == 1, "" );
  43. static_assert (d1 == 3.14, "" );
  44. }
  45. #endif
  46. return 0;
  47. }