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