1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
// { dg-options "-std=gnu++11" }
// Copyright (C) 2011-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// 20.4.2.1 [tuple.cnstr] Allocator-extended constructors
#include <memory>
#include <tuple>
#include <testsuite_hooks.h>
struct MyAlloc { };
// type that can't be constructed with an allocator
struct CannotUse
{
CannotUse(int = 0, int = 0) : ok(true) { }
bool ok;
};
// type that can be constructed with an allocator
// but which has uses_allocator == false
struct DoesNotUse
{
typedef MyAlloc allocator_type;
DoesNotUse(int = 0) : ok(true) { }
DoesNotUse(std::allocator_arg_t, MyAlloc, int = 0) : ok(false) { }
DoesNotUse(MyAlloc) : ok(false) { }
DoesNotUse(int, MyAlloc) : ok(false) { }
DoesNotUse(const DoesNotUse&) : ok(true) { }
DoesNotUse(std::allocator_arg_t, MyAlloc, const DoesNotUse&) : ok(false) { }
DoesNotUse(const DoesNotUse&, MyAlloc) : ok(false) { }
DoesNotUse(DoesNotUse&&) : ok(true) { }
DoesNotUse(std::allocator_arg_t, MyAlloc, DoesNotUse&&) : ok(false) { }
DoesNotUse(DoesNotUse&&, MyAlloc) : ok(false) { }
bool ok;
};
namespace std
{
template<typename A>
struct uses_allocator<DoesNotUse, A> : false_type { };
}
// type that can be constructed with an allocator as second argument
struct UsesWithTag
{
typedef MyAlloc allocator_type;
UsesWithTag(int = 0) : ok(false) { }
UsesWithTag(std::allocator_arg_t, MyAlloc, int = 0) : ok(true) { }
UsesWithTag(MyAlloc) : ok(false) { }
UsesWithTag(int, MyAlloc) : ok(false) { }
UsesWithTag(const UsesWithTag&) : ok(false) { }
UsesWithTag(std::allocator_arg_t, MyAlloc, const UsesWithTag&) : ok(true) { }
UsesWithTag(const UsesWithTag&, MyAlloc) : ok(false) { }
UsesWithTag(UsesWithTag&&) : ok(false) { }
UsesWithTag(std::allocator_arg_t, MyAlloc, UsesWithTag&&) : ok(true) { }
UsesWithTag(UsesWithTag&&, MyAlloc) : ok(false) { }
bool ok;
};
// type that can be constructed with an allocator as last argument
struct UsesWithoutTag
{
typedef MyAlloc allocator_type;
UsesWithoutTag(int = 0) : ok(false) { }
UsesWithoutTag(MyAlloc) : ok(true) { }
UsesWithoutTag(int, MyAlloc) : ok(true) { }
UsesWithoutTag(const UsesWithoutTag&) : ok(false) { }
UsesWithoutTag(const UsesWithoutTag&, MyAlloc) : ok(true) { }
UsesWithoutTag(UsesWithoutTag&&) : ok(false) { }
UsesWithoutTag(UsesWithoutTag&&, MyAlloc) : ok(true) { }
bool ok;
};
void test01()
{
bool test __attribute__((unused)) = true;
using std::allocator_arg;
using std::tuple;
using std::make_tuple;
using std::get;
typedef CannotUse T1;
typedef DoesNotUse T2;
typedef UsesWithTag T3;
typedef UsesWithoutTag T4;
typedef tuple<T1, T2, T3, T4> test_type;
MyAlloc a;
// default construction
test_type t1(allocator_arg, a);
VERIFY( get<0>(t1).ok );
VERIFY( get<1>(t1).ok );
VERIFY( get<2>(t1).ok );
VERIFY( get<3>(t1).ok );
// copy construction
test_type t2(allocator_arg, a, t1);
VERIFY( get<0>(t2).ok );
VERIFY( get<1>(t2).ok );
VERIFY( get<2>(t2).ok );
VERIFY( get<3>(t2).ok );
// move construction
test_type t3(allocator_arg, a, std::move(t1));
VERIFY( get<0>(t3).ok );
VERIFY( get<1>(t3).ok );
VERIFY( get<2>(t3).ok );
VERIFY( get<3>(t3).ok );
// construction from int
test_type t4(allocator_arg, a, 1, 2, 3, 4);
VERIFY( get<0>(t4).ok );
VERIFY( get<1>(t4).ok );
VERIFY( get<2>(t4).ok );
VERIFY( get<3>(t4).ok );
auto ints = make_tuple(1, 2, 3, 4);
// construction from lvalue tuple of ints
test_type t5(allocator_arg, a, ints);
VERIFY( get<0>(t5).ok );
VERIFY( get<1>(t5).ok );
VERIFY( get<2>(t5).ok );
VERIFY( get<3>(t2).ok );
// construction from rvalue tuple of ints
test_type t6(allocator_arg, a, std::move(ints));
VERIFY( get<0>(t6).ok );
VERIFY( get<1>(t6).ok );
VERIFY( get<2>(t6).ok );
VERIFY( get<3>(t6).ok );
}
int main()
{
test01();
return 0;
}
|