blob: c862d3b64d56f631c537a22783961ffb505b7813 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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, tuple<UTypes...>&&);
16
Eric Fiselierf0630522015-02-19 02:10:42 +000017// UNSUPPORTED: c++98, c++03
18
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019#include <tuple>
20#include <string>
21#include <memory>
22#include <cassert>
23
Marshall Clowebedffd2013-12-02 18:08:31 +000024#include "allocators.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025#include "../alloc_first.h"
26#include "../alloc_last.h"
27
28struct B
29{
30 int id_;
31
32 explicit B(int i) : id_(i) {}
33
34 virtual ~B() {}
35};
36
37struct D
38 : B
39{
40 explicit D(int i) : B(i) {}
41};
42
43int main()
44{
45 {
46 typedef std::tuple<int> T0;
47 typedef std::tuple<alloc_first> T1;
48 T0 t0(2);
49 alloc_first::allocator_constructed = false;
50 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
51 assert(alloc_first::allocator_constructed);
52 assert(std::get<0>(t1) == 2);
53 }
54 {
55 typedef std::tuple<std::unique_ptr<D>> T0;
56 typedef std::tuple<std::unique_ptr<B>> T1;
57 T0 t0(std::unique_ptr<D>(new D(3)));
58 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
59 assert(std::get<0>(t1)->id_ == 3);
60 }
61 {
62 typedef std::tuple<int, std::unique_ptr<D>> T0;
63 typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
64 T0 t0(2, std::unique_ptr<D>(new D(3)));
65 alloc_first::allocator_constructed = false;
66 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
67 assert(alloc_first::allocator_constructed);
68 assert(std::get<0>(t1) == 2);
69 assert(std::get<1>(t1)->id_ == 3);
70 }
71 {
72 typedef std::tuple<int, int, std::unique_ptr<D>> T0;
73 typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1;
74 T0 t0(1, 2, std::unique_ptr<D>(new D(3)));
75 alloc_first::allocator_constructed = false;
76 alloc_last::allocator_constructed = false;
77 T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
78 assert(alloc_first::allocator_constructed);
79 assert(alloc_last::allocator_constructed);
80 assert(std::get<0>(t1) == 1);
81 assert(std::get<1>(t1) == 2);
82 assert(std::get<2>(t1)->id_ == 3);
83 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084}