2 // { dg-options "-std=gnu++0x" }
4 // Copyright (C) 2011 Free Software Foundation, Inc.
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)
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.
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/>.
21 // test that propagate_on_container_xxx is true iff it is true for
22 // any of the outer or inner allocators
24 #include <scoped_allocator>
26 using std::scoped_allocator_adaptor
;
28 typedef short test_type
;
31 struct minimal_allocator
36 minimal_allocator(const minimal_allocator
<U
>&);
37 T
* allocate(std::size_t);
38 void deallocate(T
*, std::size_t);
41 template<typename T
, bool copy
, bool move
, bool swap
>
42 struct test_allocator
: minimal_allocator
<T
>
44 struct propagate_on_container_copy_assignment
45 { static const bool value
= copy
; };
47 struct propagate_on_container_move_assignment
48 { static const bool value
= move
; };
50 struct propagate_on_container_swap
51 { static const bool value
= swap
; };
55 constexpr bool prop_on_copy()
57 typedef typename
A::propagate_on_container_copy_assignment type
;
62 constexpr bool prop_on_move()
64 typedef typename
A::propagate_on_container_move_assignment type
;
69 constexpr bool prop_on_swap()
71 typedef typename
A::propagate_on_container_swap type
;
75 template<typename A
, bool C
, bool M
, bool S
>
76 constexpr bool test1()
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" );
84 template<bool C
, bool M
, bool S
>
85 constexpr bool test2()
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
>();
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" );