1 |
742 |
jeremybenn |
// { dg-do compile }
|
2 |
|
|
// { dg-options "-std=gnu++0x" }
|
3 |
|
|
|
4 |
|
|
// Copyright (C) 2011 Free Software Foundation, Inc.
|
5 |
|
|
//
|
6 |
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
7 |
|
|
// software; you can redistribute it and/or modify it under the
|
8 |
|
|
// terms of the GNU General Public License as published by the
|
9 |
|
|
// Free Software Foundation; either version 3, or (at your option)
|
10 |
|
|
// any later version.
|
11 |
|
|
|
12 |
|
|
// This library is distributed in the hope that it will be useful,
|
13 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
// GNU General Public License for more details.
|
16 |
|
|
|
17 |
|
|
// You should have received a copy of the GNU General Public License along
|
18 |
|
|
// with this library; see the file COPYING3. If not see
|
19 |
|
|
// <http://www.gnu.org/licenses/>.
|
20 |
|
|
|
21 |
|
|
// test that propagate_on_container_xxx is true iff it is true for
|
22 |
|
|
// any of the outer or inner allocators
|
23 |
|
|
|
24 |
|
|
#include <scoped_allocator>
|
25 |
|
|
|
26 |
|
|
using std::scoped_allocator_adaptor;
|
27 |
|
|
|
28 |
|
|
typedef short test_type;
|
29 |
|
|
|
30 |
|
|
template<typename T>
|
31 |
|
|
struct minimal_allocator
|
32 |
|
|
{
|
33 |
|
|
typedef T value_type;
|
34 |
|
|
minimal_allocator();
|
35 |
|
|
template <typename U>
|
36 |
|
|
minimal_allocator(const minimal_allocator<U>&);
|
37 |
|
|
T* allocate(std::size_t);
|
38 |
|
|
void deallocate(T*, std::size_t);
|
39 |
|
|
};
|
40 |
|
|
|
41 |
|
|
template<typename T, bool copy, bool move, bool swap>
|
42 |
|
|
struct test_allocator : minimal_allocator<T>
|
43 |
|
|
{
|
44 |
|
|
struct propagate_on_container_copy_assignment
|
45 |
|
|
{ static const bool value = copy; };
|
46 |
|
|
|
47 |
|
|
struct propagate_on_container_move_assignment
|
48 |
|
|
{ static const bool value = move; };
|
49 |
|
|
|
50 |
|
|
struct propagate_on_container_swap
|
51 |
|
|
{ static const bool value = swap; };
|
52 |
|
|
};
|
53 |
|
|
|
54 |
|
|
template<typename A>
|
55 |
|
|
constexpr bool prop_on_copy()
|
56 |
|
|
{
|
57 |
|
|
typedef typename A::propagate_on_container_copy_assignment type;
|
58 |
|
|
return type::value;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
template<typename A>
|
62 |
|
|
constexpr bool prop_on_move()
|
63 |
|
|
{
|
64 |
|
|
typedef typename A::propagate_on_container_move_assignment type;
|
65 |
|
|
return type::value;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
template<typename A>
|
69 |
|
|
constexpr bool prop_on_swap()
|
70 |
|
|
{
|
71 |
|
|
typedef typename A::propagate_on_container_swap type;
|
72 |
|
|
return type::value;
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
template<typename A, bool C, bool M, bool S>
|
76 |
|
|
constexpr bool test1()
|
77 |
|
|
{
|
78 |
|
|
static_assert( prop_on_copy<A>() == C, "copy" );
|
79 |
|
|
static_assert( prop_on_move<A>() == M, "move" );
|
80 |
|
|
static_assert( prop_on_swap<A>() == S, "swap" );
|
81 |
|
|
return true;
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
template<bool C, bool M, bool S>
|
85 |
|
|
constexpr bool test2()
|
86 |
|
|
{
|
87 |
|
|
typedef minimal_allocator<test_type> base_alloc;
|
88 |
|
|
typedef test_allocator<test_type, C, M, S> test_alloc;
|
89 |
|
|
typedef scoped_allocator_adaptor<base_alloc, test_alloc> scoped1;
|
90 |
|
|
typedef scoped_allocator_adaptor<test_alloc, base_alloc> scoped2;
|
91 |
|
|
typedef scoped_allocator_adaptor<test_alloc, test_alloc> scoped3;
|
92 |
|
|
return test1<scoped1, C, M, S>()
|
93 |
|
|
&& test1<scoped2, C, M, S>()
|
94 |
|
|
&& test1<scoped3, C, M, S>();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
static_assert( test2<false, false, false>(), "never propagate" );
|
98 |
|
|
static_assert( test2<true, false, false>(), "propagate on copy" );
|
99 |
|
|
static_assert( test2<false, true, false>(), "propagate on move" );
|
100 |
|
|
static_assert( test2<false, false, true>(), "propagate on swap" );
|
101 |
|
|
static_assert( test2<true, true, false>(), "propagate on copy & move" );
|
102 |
|
|
static_assert( test2<true, false, true>(), "propagate on copy & swap" );
|
103 |
|
|
static_assert( test2<false, true, true>(), "propagate on move & swap" );
|
104 |
|
|
static_assert( test2<true, true, true>(), "always propagate" );
|
105 |
|
|
|