15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <tuple>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template <class... Types> class tuple;
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // template <class Alloc, class... UTypes>
1416719cd0SHui Xie // constexpr                                        // since c++20
155a83710eSEric Fiselier //   tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
165a83710eSEric Fiselier 
1731cbe0f2SLouis Dionne // UNSUPPORTED: c++03
180a52cd79SEric Fiselier 
195a83710eSEric Fiselier #include <tuple>
209795699aSEric Fiselier #include <memory>
215a83710eSEric Fiselier #include <cassert>
225a83710eSEric Fiselier 
237fc6a556SMarshall Clow #include "test_macros.h"
245a83710eSEric Fiselier #include "allocators.h"
2516719cd0SHui Xie #include "test_allocator.h"
265a83710eSEric Fiselier #include "../alloc_first.h"
275a83710eSEric Fiselier #include "../alloc_last.h"
285a83710eSEric Fiselier 
299795699aSEric Fiselier struct Explicit {
309795699aSEric Fiselier   int value;
ExplicitExplicit319795699aSEric Fiselier   explicit Explicit(int x) : value(x) {}
329795699aSEric Fiselier };
339795699aSEric Fiselier 
349795699aSEric Fiselier struct Implicit {
359795699aSEric Fiselier   int value;
ImplicitImplicit369795699aSEric Fiselier   Implicit(int x) : value(x) {}
379795699aSEric Fiselier };
389795699aSEric Fiselier 
39*24186f72Scpplearner #if TEST_STD_VER > 17
alloc_copy_constructor_is_constexpr()4016719cd0SHui Xie constexpr bool alloc_copy_constructor_is_constexpr() {
4116719cd0SHui Xie   const std::tuple<int> t1 = 1;
4216719cd0SHui Xie   std::tuple<int> t2 = {std::allocator_arg, test_allocator<int>{}, t1};
4316719cd0SHui Xie   assert(std::get<0>(t2) == 1);
4416719cd0SHui Xie   return true;
4516719cd0SHui Xie }
4616719cd0SHui Xie #endif
4716719cd0SHui Xie 
main(int,char **)482df59c50SJF Bastien int main(int, char**)
495a83710eSEric Fiselier {
505a83710eSEric Fiselier     {
51a0d87857SStephan T. Lavavej         typedef std::tuple<long> T0;
52a0d87857SStephan T. Lavavej         typedef std::tuple<long long> T1;
53a0d87857SStephan T. Lavavej         T0 t0(2);
545a83710eSEric Fiselier         T1 t1(std::allocator_arg, A1<int>(), t0);
555a83710eSEric Fiselier         assert(std::get<0>(t1) == 2);
565a83710eSEric Fiselier     }
575a83710eSEric Fiselier     {
585a83710eSEric Fiselier         typedef std::tuple<int> T0;
595a83710eSEric Fiselier         typedef std::tuple<alloc_first> T1;
605a83710eSEric Fiselier         T0 t0(2);
615a83710eSEric Fiselier         alloc_first::allocator_constructed = false;
625a83710eSEric Fiselier         T1 t1(std::allocator_arg, A1<int>(5), t0);
635a83710eSEric Fiselier         assert(alloc_first::allocator_constructed);
645a83710eSEric Fiselier         assert(std::get<0>(t1) == 2);
655a83710eSEric Fiselier     }
665a83710eSEric Fiselier     {
675a83710eSEric Fiselier         typedef std::tuple<int, int> T0;
685a83710eSEric Fiselier         typedef std::tuple<alloc_first, alloc_last> T1;
695a83710eSEric Fiselier         T0 t0(2, 3);
705a83710eSEric Fiselier         alloc_first::allocator_constructed = false;
715a83710eSEric Fiselier         alloc_last::allocator_constructed = false;
725a83710eSEric Fiselier         T1 t1(std::allocator_arg, A1<int>(5), t0);
735a83710eSEric Fiselier         assert(alloc_first::allocator_constructed);
745a83710eSEric Fiselier         assert(alloc_last::allocator_constructed);
755a83710eSEric Fiselier         assert(std::get<0>(t1) == 2);
765a83710eSEric Fiselier         assert(std::get<1>(t1) == 3);
775a83710eSEric Fiselier     }
785a83710eSEric Fiselier     {
79a0d87857SStephan T. Lavavej         typedef std::tuple<long, int, int> T0;
80a0d87857SStephan T. Lavavej         typedef std::tuple<long long, alloc_first, alloc_last> T1;
81a0d87857SStephan T. Lavavej         T0 t0(1, 2, 3);
825a83710eSEric Fiselier         alloc_first::allocator_constructed = false;
835a83710eSEric Fiselier         alloc_last::allocator_constructed = false;
845a83710eSEric Fiselier         T1 t1(std::allocator_arg, A1<int>(5), t0);
855a83710eSEric Fiselier         assert(alloc_first::allocator_constructed);
865a83710eSEric Fiselier         assert(alloc_last::allocator_constructed);
875a83710eSEric Fiselier         assert(std::get<0>(t1) == 1);
885a83710eSEric Fiselier         assert(std::get<1>(t1) == 2);
895a83710eSEric Fiselier         assert(std::get<2>(t1) == 3);
905a83710eSEric Fiselier     }
919795699aSEric Fiselier     {
929795699aSEric Fiselier         const std::tuple<int> t1(42);
935b1e5b43SMichael Park         std::tuple<Explicit> t2{std::allocator_arg, std::allocator<int>{},  t1};
949795699aSEric Fiselier         assert(std::get<0>(t2).value == 42);
959795699aSEric Fiselier     }
969795699aSEric Fiselier     {
979795699aSEric Fiselier         const std::tuple<int> t1(42);
985b1e5b43SMichael Park         std::tuple<Implicit> t2 = {std::allocator_arg, std::allocator<int>{}, t1};
999795699aSEric Fiselier         assert(std::get<0>(t2).value == 42);
1009795699aSEric Fiselier     }
101a3ab5120SLouis Dionne     {
102a3ab5120SLouis Dionne         // Test that we can use a tag derived from allocator_arg_t
103a3ab5120SLouis Dionne         struct DerivedFromAllocatorArgT : std::allocator_arg_t { };
104a3ab5120SLouis Dionne         DerivedFromAllocatorArgT derived;
105a3ab5120SLouis Dionne         std::tuple<long> from(3l);
106a3ab5120SLouis Dionne         std::tuple<long long> t0(derived, A1<int>(), from);
107a3ab5120SLouis Dionne     }
1082df59c50SJF Bastien 
109*24186f72Scpplearner #if TEST_STD_VER > 17
11016719cd0SHui Xie     static_assert(alloc_copy_constructor_is_constexpr());
11116719cd0SHui Xie #endif
1122df59c50SJF Bastien     return 0;
1135a83710eSEric Fiselier }
114