xref: /llvm-project/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc_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>
14 //   tuple(allocator_arg_t, const Alloc& a, const tuple&);
15 
16 // UNSUPPORTED: c++98, c++03
17 
18 #include <tuple>
19 #include <cassert>
20 
21 #include "allocators.h"
22 #include "../alloc_first.h"
23 #include "../alloc_last.h"
24 
25 int main()
26 {
27     {
28         typedef std::tuple<> T;
29         T t0;
30         T t(std::allocator_arg, A1<int>(), t0);
31     }
32     {
33         typedef std::tuple<int> T;
34         T t0(2);
35         T t(std::allocator_arg, A1<int>(), t0);
36         assert(std::get<0>(t) == 2);
37     }
38     {
39         typedef std::tuple<alloc_first> T;
40         T t0(2);
41         alloc_first::allocator_constructed = false;
42         T t(std::allocator_arg, A1<int>(5), t0);
43         assert(alloc_first::allocator_constructed);
44         assert(std::get<0>(t) == 2);
45     }
46     {
47         typedef std::tuple<alloc_last> T;
48         T t0(2);
49         alloc_last::allocator_constructed = false;
50         T t(std::allocator_arg, A1<int>(5), t0);
51         assert(alloc_last::allocator_constructed);
52         assert(std::get<0>(t) == 2);
53     }
54 // testing extensions
55 #ifdef _LIBCPP_VERSION
56     {
57         typedef std::tuple<alloc_first, alloc_last> T;
58         T t0(2, 3);
59         alloc_first::allocator_constructed = false;
60         alloc_last::allocator_constructed = false;
61         T t(std::allocator_arg, A1<int>(5), t0);
62         assert(alloc_first::allocator_constructed);
63         assert(alloc_last::allocator_constructed);
64         assert(std::get<0>(t) == 2);
65         assert(std::get<1>(t) == 3);
66     }
67     {
68         typedef std::tuple<int, alloc_first, alloc_last> T;
69         T t0(1, 2, 3);
70         alloc_first::allocator_constructed = false;
71         alloc_last::allocator_constructed = false;
72         T t(std::allocator_arg, A1<int>(5), t0);
73         assert(alloc_first::allocator_constructed);
74         assert(alloc_last::allocator_constructed);
75         assert(std::get<0>(t) == 1);
76         assert(std::get<1>(t) == 2);
77         assert(std::get<2>(t) == 3);
78     }
79 #endif
80 }
81