Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <tuple> |
| 11 | |
| 12 | // template <class... Types> class tuple; |
| 13 | |
| 14 | // template <class Alloc, class... UTypes> |
| 15 | // tuple(allocator_arg_t, const Alloc& a, UTypes&&...); |
| 16 | |
Eric Fiselier | f063052 | 2015-02-19 02:10:42 +0000 | [diff] [blame] | 17 | // UNSUPPORTED: c++98, c++03 |
| 18 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | #include <tuple> |
| 20 | #include <cassert> |
| 21 | |
Marshall Clow | df00d5e | 2015-01-28 21:22:53 +0000 | [diff] [blame] | 22 | #include "MoveOnly.h" |
Marshall Clow | ebedffd | 2013-12-02 18:08:31 +0000 | [diff] [blame] | 23 | #include "allocators.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | #include "../alloc_first.h" |
| 25 | #include "../alloc_last.h" |
| 26 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 27 | struct NoDefault { NoDefault() = delete; }; |
Marshall Clow | bbc7c74 | 2014-10-15 10:33:02 +0000 | [diff] [blame] | 28 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 29 | // Make sure the _Up... constructor SFINAEs out when the types that |
| 30 | // are not explicitly initialized are not all default constructible. |
| 31 | // Otherwise, std::is_constructible would return true but instantiating |
| 32 | // the constructor would fail. |
| 33 | void test_default_constructible_extension_sfinae() |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 34 | { |
| 35 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 36 | typedef std::tuple<MoveOnly, NoDefault> Tuple; |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 37 | |
| 38 | static_assert(!std::is_constructible< |
| 39 | Tuple, |
| 40 | std::allocator_arg_t, A1<int>, MoveOnly |
| 41 | >::value, ""); |
| 42 | |
| 43 | static_assert(std::is_constructible< |
| 44 | Tuple, |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 45 | std::allocator_arg_t, A1<int>, MoveOnly, NoDefault |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 46 | >::value, ""); |
| 47 | } |
| 48 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 49 | typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple; |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 50 | |
| 51 | static_assert(!std::is_constructible< |
Eric Fiselier | 75fdf0e | 2015-02-05 20:28:37 +0000 | [diff] [blame] | 52 | Tuple, |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 53 | std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly |
| 54 | >::value, ""); |
| 55 | |
| 56 | static_assert(std::is_constructible< |
Eric Fiselier | 75fdf0e | 2015-02-05 20:28:37 +0000 | [diff] [blame] | 57 | Tuple, |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, NoDefault |
| 59 | >::value, ""); |
| 60 | } |
| 61 | { |
| 62 | // Same idea as above but with a nested tuple |
| 63 | typedef std::tuple<MoveOnly, NoDefault> Tuple; |
| 64 | typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; |
| 65 | |
| 66 | static_assert(!std::is_constructible< |
| 67 | NestedTuple, |
| 68 | std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly |
| 69 | >::value, ""); |
| 70 | |
| 71 | static_assert(std::is_constructible< |
| 72 | NestedTuple, |
| 73 | std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly |
| 74 | >::value, ""); |
| 75 | } |
| 76 | { |
| 77 | typedef std::tuple<MoveOnly, int> Tuple; |
| 78 | typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple; |
| 79 | |
| 80 | static_assert(std::is_constructible< |
| 81 | NestedTuple, |
| 82 | std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly |
| 83 | >::value, ""); |
| 84 | |
| 85 | static_assert(std::is_constructible< |
| 86 | NestedTuple, |
| 87 | std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly |
Eric Fiselier | f2215ae | 2014-11-18 23:01:57 +0000 | [diff] [blame] | 88 | >::value, ""); |
| 89 | } |
| 90 | } |
| 91 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | int main() |
| 93 | { |
| 94 | { |
| 95 | std::tuple<MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0)); |
| 96 | assert(std::get<0>(t) == 0); |
| 97 | } |
| 98 | { |
| 99 | std::tuple<MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), |
| 100 | MoveOnly(0), MoveOnly(1)); |
| 101 | assert(std::get<0>(t) == 0); |
| 102 | assert(std::get<1>(t) == 1); |
| 103 | } |
| 104 | { |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 105 | std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | MoveOnly(0), |
| 107 | 1, 2); |
| 108 | assert(std::get<0>(t) == 0); |
| 109 | assert(std::get<1>(t) == 1); |
| 110 | assert(std::get<2>(t) == 2); |
| 111 | } |
| 112 | { |
| 113 | alloc_first::allocator_constructed = false; |
| 114 | alloc_last::allocator_constructed = false; |
| 115 | std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg, |
| 116 | A1<int>(5), 1, 2, 3); |
| 117 | assert(std::get<0>(t) == 1); |
| 118 | assert(alloc_first::allocator_constructed); |
| 119 | assert(std::get<1>(t) == alloc_first(2)); |
| 120 | assert(alloc_last::allocator_constructed); |
| 121 | assert(std::get<2>(t) == alloc_last(3)); |
| 122 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 123 | // extensions |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | { |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 125 | std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), |
| 126 | 0, 1); |
| 127 | assert(std::get<0>(t) == 0); |
| 128 | assert(std::get<1>(t) == 1); |
| 129 | assert(std::get<2>(t) == MoveOnly()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 131 | { |
| 132 | std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(), |
| 133 | 0); |
| 134 | assert(std::get<0>(t) == 0); |
| 135 | assert(std::get<1>(t) == MoveOnly()); |
| 136 | assert(std::get<2>(t) == MoveOnly()); |
| 137 | } |
| 138 | // Check that SFINAE is properly applied with the default reduced arity |
| 139 | // constructor extensions. |
| 140 | test_default_constructible_extension_sfinae(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 141 | } |