| 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 U1, class U2> |
| 14 | // tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); |
| 15 | |
| 16 | // UNSUPPORTED: c++03 |
| 17 | |
| 18 | #include <tuple> |
| 19 | #include <utility> |
| 20 | #include <cassert> |
| 21 | |
| 22 | #include "test_macros.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::pair<long, int> T0; |
| 31 | typedef std::tuple<long long, double> T1; |
| 32 | T0 t0(2, 3); |
| 33 | T1 t1(std::allocator_arg, A1<int>(5), t0); |
| 34 | assert(std::get<0>(t1) == 2); |
| 35 | assert(std::get<1>(t1) == 3); |
| 36 | } |
| 37 | { |
| 38 | typedef std::pair<int, int> T0; |
| 39 | typedef std::tuple<alloc_first, double> T1; |
| 40 | T0 t0(2, 3); |
| 41 | alloc_first::allocator_constructed = false; |
| 42 | T1 t1(std::allocator_arg, A1<int>(5), t0); |
| 43 | assert(alloc_first::allocator_constructed); |
| 44 | assert(std::get<0>(t1) == 2); |
| 45 | assert(std::get<1>(t1) == 3); |
| 46 | } |
| 47 | { |
| 48 | typedef std::pair<int, int> T0; |
| 49 | typedef std::tuple<alloc_first, alloc_last> T1; |
| 50 | T0 t0(2, 3); |
| 51 | alloc_first::allocator_constructed = false; |
| 52 | alloc_last::allocator_constructed = false; |
| 53 | T1 t1(std::allocator_arg, A1<int>(5), t0); |
| 54 | assert(alloc_first::allocator_constructed); |
| 55 | assert(alloc_last::allocator_constructed); |
| 56 | assert(std::get<0>(t1) == 2); |
| 57 | assert(std::get<1>(t1) == 3); |
| 58 | } |
| 59 | { |
| 60 | // Test that we can use a tag derived from allocator_arg_t |
| 61 | struct DerivedFromAllocatorArgT : std::allocator_arg_t { }; |
| 62 | DerivedFromAllocatorArgT derived; |
| 63 | std::pair<int, int> p(1, 2); |
| 64 | std::tuple<int, int> t(derived, A1<int>(), p); |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |