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