1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <tuple> 11 12 // template <class... Types> class tuple; 13 14 // template <class Alloc> 15 // tuple(allocator_arg_t, const Alloc& a, const Types&...); 16 17 // UNSUPPORTED: c++98, c++03 18 19 #include <tuple> 20 #include <memory> 21 #include <cassert> 22 23 #include "allocators.h" 24 #include "../alloc_first.h" 25 #include "../alloc_last.h" 26 27 struct ImplicitCopy { 28 explicit ImplicitCopy(int) {} 29 ImplicitCopy(ImplicitCopy const&) {} 30 }; 31 32 // Test that tuple(std::allocator_arg, Alloc, Types const&...) allows implicit 33 // copy conversions in return value expressions. 34 std::tuple<ImplicitCopy> testImplicitCopy1() { 35 ImplicitCopy i(42); 36 return {std::allocator_arg, std::allocator<void>{}, i}; 37 } 38 39 std::tuple<ImplicitCopy> testImplicitCopy2() { 40 const ImplicitCopy i(42); 41 return {std::allocator_arg, std::allocator<void>{}, i}; 42 } 43 44 int main() 45 { 46 { 47 // check that the literal '0' can implicitly initialize a stored pointer. 48 std::tuple<int*> t = {std::allocator_arg, std::allocator<void>{}, 0}; 49 } 50 { 51 std::tuple<int> t(std::allocator_arg, A1<int>(), 3); 52 assert(std::get<0>(t) == 3); 53 } 54 { 55 assert(!alloc_first::allocator_constructed); 56 std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5), alloc_first(3)); 57 assert(alloc_first::allocator_constructed); 58 assert(std::get<0>(t) == alloc_first(3)); 59 } 60 { 61 assert(!alloc_last::allocator_constructed); 62 std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5), alloc_last(3)); 63 assert(alloc_last::allocator_constructed); 64 assert(std::get<0>(t) == alloc_last(3)); 65 } 66 { 67 alloc_first::allocator_constructed = false; 68 std::tuple<int, alloc_first> t(std::allocator_arg, A1<int>(5), 69 10, alloc_first(15)); 70 assert(std::get<0>(t) == 10); 71 assert(alloc_first::allocator_constructed); 72 assert(std::get<1>(t) == alloc_first(15)); 73 } 74 { 75 alloc_first::allocator_constructed = false; 76 alloc_last::allocator_constructed = false; 77 std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, 78 A1<int>(5), 1, alloc_first(2), 79 alloc_last(3)); 80 assert(std::get<0>(t) == 1); 81 assert(alloc_first::allocator_constructed); 82 assert(std::get<1>(t) == alloc_first(2)); 83 assert(alloc_last::allocator_constructed); 84 assert(std::get<2>(t) == alloc_last(3)); 85 } 86 { 87 alloc_first::allocator_constructed = false; 88 alloc_last::allocator_constructed = false; 89 std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, 90 A2<int>(5), 1, alloc_first(2), 91 alloc_last(3)); 92 assert(std::get<0>(t) == 1); 93 assert(!alloc_first::allocator_constructed); 94 assert(std::get<1>(t) == alloc_first(2)); 95 assert(!alloc_last::allocator_constructed); 96 assert(std::get<2>(t) == alloc_last(3)); 97 } 98 } 99