copy.pass.cpp 1.6 KB

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