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, tuple<UTypes...>&&); 15 16 // UNSUPPORTED: c++98, c++03 17 18 #include <tuple> 19 #include <string> 20 #include <memory> 21 #include <cassert> 22 23 #include "allocators.h" 24 #include "../alloc_first.h" 25 #include "../alloc_last.h" 26 27 struct B 28 { 29 int id_; 30 31 explicit B(int i) : id_(i) {} 32 33 virtual ~B() {} 34 }; 35 36 struct D 37 : B 38 { 39 explicit D(int i) : B(i) {} 40 }; 41 42 struct Explicit { 43 int value; 44 explicit Explicit(int x) : value(x) {} 45 }; 46 47 struct Implicit { 48 int value; 49 Implicit(int x) : value(x) {} 50 }; 51 52 int main(int, char**) 53 { 54 { 55 typedef std::tuple<int> T0; 56 typedef std::tuple<alloc_first> T1; 57 T0 t0(2); 58 alloc_first::allocator_constructed = false; 59 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); 60 assert(alloc_first::allocator_constructed); 61 assert(std::get<0>(t1) == 2); 62 } 63 { 64 typedef std::tuple<std::unique_ptr<D>> T0; 65 typedef std::tuple<std::unique_ptr<B>> T1; 66 T0 t0(std::unique_ptr<D>(new D(3))); 67 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); 68 assert(std::get<0>(t1)->id_ == 3); 69 } 70 { 71 typedef std::tuple<int, std::unique_ptr<D>> T0; 72 typedef std::tuple<alloc_first, std::unique_ptr<B>> T1; 73 T0 t0(2, std::unique_ptr<D>(new D(3))); 74 alloc_first::allocator_constructed = false; 75 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); 76 assert(alloc_first::allocator_constructed); 77 assert(std::get<0>(t1) == 2); 78 assert(std::get<1>(t1)->id_ == 3); 79 } 80 { 81 typedef std::tuple<int, int, std::unique_ptr<D>> T0; 82 typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1; 83 T0 t0(1, 2, std::unique_ptr<D>(new D(3))); 84 alloc_first::allocator_constructed = false; 85 alloc_last::allocator_constructed = false; 86 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0)); 87 assert(alloc_first::allocator_constructed); 88 assert(alloc_last::allocator_constructed); 89 assert(std::get<0>(t1) == 1); 90 assert(std::get<1>(t1) == 2); 91 assert(std::get<2>(t1)->id_ == 3); 92 } 93 { 94 std::tuple<int> t1(42); 95 std::tuple<Explicit> t2{std::allocator_arg, std::allocator<void>{}, std::move(t1)}; 96 assert(std::get<0>(t2).value == 42); 97 } 98 { 99 std::tuple<int> t1(42); 100 std::tuple<Implicit> t2 = {std::allocator_arg, std::allocator<void>{}, std::move(t1)}; 101 assert(std::get<0>(t2).value == 42); 102 } 103 104 return 0; 105 } 106