copy.pass.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // tuple(const tuple& u) = default;
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <string>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. struct Empty {};
  18. int main()
  19. {
  20. {
  21. typedef std::tuple<> T;
  22. T t0;
  23. T t = t0;
  24. ((void)t); // Prevent unused warning
  25. }
  26. {
  27. typedef std::tuple<int> T;
  28. T t0(2);
  29. T t = t0;
  30. assert(std::get<0>(t) == 2);
  31. }
  32. {
  33. typedef std::tuple<int, char> T;
  34. T t0(2, 'a');
  35. T t = t0;
  36. assert(std::get<0>(t) == 2);
  37. assert(std::get<1>(t) == 'a');
  38. }
  39. {
  40. typedef std::tuple<int, char, std::string> T;
  41. const T t0(2, 'a', "some text");
  42. T t = t0;
  43. assert(std::get<0>(t) == 2);
  44. assert(std::get<1>(t) == 'a');
  45. assert(std::get<2>(t) == "some text");
  46. }
  47. #if TEST_STD_VER > 11
  48. {
  49. typedef std::tuple<int> T;
  50. constexpr T t0(2);
  51. constexpr T t = t0;
  52. static_assert(std::get<0>(t) == 2, "");
  53. }
  54. {
  55. typedef std::tuple<Empty> T;
  56. constexpr T t0;
  57. constexpr T t = t0;
  58. constexpr Empty e = std::get<0>(t);
  59. ((void)e); // Prevent unused warning
  60. }
  61. #endif
  62. }