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