alloc_convert_copy.pass.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Alloc, class... UTypes>
  11. // tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
  12. // UNSUPPORTED: c++98, c++03
  13. #include <tuple>
  14. #include <memory>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "allocators.h"
  18. #include "../alloc_first.h"
  19. #include "../alloc_last.h"
  20. struct Explicit {
  21. int value;
  22. explicit Explicit(int x) : value(x) {}
  23. };
  24. struct Implicit {
  25. int value;
  26. Implicit(int x) : value(x) {}
  27. };
  28. int main(int, char**)
  29. {
  30. {
  31. typedef std::tuple<long> T0;
  32. typedef std::tuple<long long> T1;
  33. T0 t0(2);
  34. T1 t1(std::allocator_arg, A1<int>(), t0);
  35. assert(std::get<0>(t1) == 2);
  36. }
  37. {
  38. typedef std::tuple<int> T0;
  39. typedef std::tuple<alloc_first> T1;
  40. T0 t0(2);
  41. alloc_first::allocator_constructed = false;
  42. T1 t1(std::allocator_arg, A1<int>(5), t0);
  43. assert(alloc_first::allocator_constructed);
  44. assert(std::get<0>(t1) == 2);
  45. }
  46. {
  47. typedef std::tuple<int, int> T0;
  48. typedef std::tuple<alloc_first, alloc_last> T1;
  49. T0 t0(2, 3);
  50. alloc_first::allocator_constructed = false;
  51. alloc_last::allocator_constructed = false;
  52. T1 t1(std::allocator_arg, A1<int>(5), t0);
  53. assert(alloc_first::allocator_constructed);
  54. assert(alloc_last::allocator_constructed);
  55. assert(std::get<0>(t1) == 2);
  56. assert(std::get<1>(t1) == 3);
  57. }
  58. {
  59. typedef std::tuple<long, int, int> T0;
  60. typedef std::tuple<long long, alloc_first, alloc_last> T1;
  61. T0 t0(1, 2, 3);
  62. alloc_first::allocator_constructed = false;
  63. alloc_last::allocator_constructed = false;
  64. T1 t1(std::allocator_arg, A1<int>(5), t0);
  65. assert(alloc_first::allocator_constructed);
  66. assert(alloc_last::allocator_constructed);
  67. assert(std::get<0>(t1) == 1);
  68. assert(std::get<1>(t1) == 2);
  69. assert(std::get<2>(t1) == 3);
  70. }
  71. {
  72. const std::tuple<int> t1(42);
  73. std::tuple<Explicit> t2{std::allocator_arg, std::allocator<void>{}, t1};
  74. assert(std::get<0>(t2).value == 42);
  75. }
  76. {
  77. const std::tuple<int> t1(42);
  78. std::tuple<Implicit> t2 = {std::allocator_arg, std::allocator<void>{}, t1};
  79. assert(std::get<0>(t2).value == 42);
  80. }
  81. return 0;
  82. }