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, tuple&&); 15 16 // UNSUPPORTED: c++03 17 18 #include <tuple> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "MoveOnly.h" 23 #include "allocators.h" 24 #include "../alloc_first.h" 25 #include "../alloc_last.h" 26 27 int main(int, char**) 28 { 29 { 30 typedef std::tuple<> T; 31 T t0; 32 T t(std::allocator_arg, A1<int>(), std::move(t0)); 33 } 34 { 35 typedef std::tuple<MoveOnly> T; 36 T t0(MoveOnly(0)); 37 T t(std::allocator_arg, A1<int>(), std::move(t0)); 38 assert(std::get<0>(t) == 0); 39 } 40 { 41 typedef std::tuple<alloc_first> T; 42 T t0(1); 43 alloc_first::allocator_constructed = false; 44 T t(std::allocator_arg, A1<int>(5), std::move(t0)); 45 assert(alloc_first::allocator_constructed); 46 assert(std::get<0>(t) == 1); 47 } 48 { 49 typedef std::tuple<alloc_last> T; 50 T t0(1); 51 alloc_last::allocator_constructed = false; 52 T t(std::allocator_arg, A1<int>(5), std::move(t0)); 53 assert(alloc_last::allocator_constructed); 54 assert(std::get<0>(t) == 1); 55 } 56 { 57 typedef std::tuple<MoveOnly, alloc_first> T; 58 T t0(0 ,1); 59 alloc_first::allocator_constructed = false; 60 T t(std::allocator_arg, A1<int>(5), std::move(t0)); 61 assert(alloc_first::allocator_constructed); 62 assert(std::get<0>(t) == 0); 63 assert(std::get<1>(t) == 1); 64 } 65 { 66 typedef std::tuple<MoveOnly, alloc_first, alloc_last> T; 67 T t0(1, 2, 3); 68 alloc_first::allocator_constructed = false; 69 alloc_last::allocator_constructed = false; 70 T t(std::allocator_arg, A1<int>(5), std::move(t0)); 71 assert(alloc_first::allocator_constructed); 72 assert(alloc_last::allocator_constructed); 73 assert(std::get<0>(t) == 1); 74 assert(std::get<1>(t) == 2); 75 assert(std::get<2>(t) == 3); 76 } 77 { 78 // Test that we can use a tag derived from allocator_arg_t 79 struct DerivedFromAllocatorArgT : std::allocator_arg_t { }; 80 DerivedFromAllocatorArgT derived; 81 std::tuple<int> from(3); 82 std::tuple<int> t0(derived, A1<int>(), std::move(from)); 83 } 84 85 return 0; 86 } 87