1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
14 // template <class... Types> class tuple;
16 // template <class Alloc>
17 // tuple(allocator_arg_t, const Alloc& a);
19 // NOTE: this constructor does not currently support tags derived from
20 // allocator_arg_t because libc++ has to deduce the parameter as a template
21 // argument. See PR27684 (https://bugs.llvm.org/show_bug.cgi?id=27684)
26 #include "DefaultOnly.h"
27 #include "allocators.h"
28 #include "../alloc_first.h"
29 #include "../alloc_last.h"
31 template <class T = void>
32 struct NonDefaultConstructible {
33 constexpr NonDefaultConstructible() {
34 static_assert(!std::is_same<T, T>::value, "Default Ctor instantiated");
37 explicit constexpr NonDefaultConstructible(int) {}
41 struct DerivedFromAllocArgT : std::allocator_arg_t {};
46 std::tuple<> t(std::allocator_arg, A1<int>());
49 std::tuple<int> t(std::allocator_arg, A1<int>());
50 assert(std::get<0>(t) == 0);
53 std::tuple<DefaultOnly> t(std::allocator_arg, A1<int>());
54 assert(std::get<0>(t) == DefaultOnly());
57 assert(!alloc_first::allocator_constructed);
58 std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5));
59 assert(alloc_first::allocator_constructed);
60 assert(std::get<0>(t) == alloc_first());
63 assert(!alloc_last::allocator_constructed);
64 std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5));
65 assert(alloc_last::allocator_constructed);
66 assert(std::get<0>(t) == alloc_last());
69 alloc_first::allocator_constructed = false;
70 std::tuple<DefaultOnly, alloc_first> t(std::allocator_arg, A1<int>(5));
71 assert(std::get<0>(t) == DefaultOnly());
72 assert(alloc_first::allocator_constructed);
73 assert(std::get<1>(t) == alloc_first());
76 alloc_first::allocator_constructed = false;
77 alloc_last::allocator_constructed = false;
78 std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg,
80 assert(std::get<0>(t) == DefaultOnly());
81 assert(alloc_first::allocator_constructed);
82 assert(std::get<1>(t) == alloc_first());
83 assert(alloc_last::allocator_constructed);
84 assert(std::get<2>(t) == alloc_last());
87 alloc_first::allocator_constructed = false;
88 alloc_last::allocator_constructed = false;
89 std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg,
91 assert(std::get<0>(t) == DefaultOnly());
92 assert(!alloc_first::allocator_constructed);
93 assert(std::get<1>(t) == alloc_first());
94 assert(!alloc_last::allocator_constructed);
95 assert(std::get<2>(t) == alloc_last());
98 // Test that the uses-allocator default constructor does not evaluate
99 // its SFINAE when it otherwise shouldn't be selected. Do this by
100 // using 'NonDefaultConstructible' which will cause a compile error
101 // if std::is_default_constructible is evaluated on it.
102 using T = NonDefaultConstructible<>;
104 std::tuple<T, T> t(v, v);
105 std::tuple<T, T> t2(42, 42);