1 // { dg-do compile { target c++11 } }
3 // Copyright (C) 2011-2017 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // test that propagate_on_container_xxx is true iff it is true for
21 // any of the outer or inner allocators
23 #include <scoped_allocator>
25 using std::scoped_allocator_adaptor
;
27 typedef short test_type
;
30 struct minimal_allocator
35 minimal_allocator(const minimal_allocator
<U
>&);
36 T
* allocate(std::size_t);
37 void deallocate(T
*, std::size_t);
40 template<typename T
, bool copy
, bool move
, bool swap
>
41 struct test_allocator
: minimal_allocator
<T
>
45 { using other
= test_allocator
<U
, copy
, move
, swap
>; };
47 struct propagate_on_container_copy_assignment
48 : std::integral_constant
<bool, copy
> { };
50 struct propagate_on_container_move_assignment
51 : std::integral_constant
<bool, move
> { };
53 struct propagate_on_container_swap
54 : std::integral_constant
<bool, swap
> { };
58 constexpr bool prop_on_copy()
60 typedef typename
A::propagate_on_container_copy_assignment type
;
65 constexpr bool prop_on_move()
67 typedef typename
A::propagate_on_container_move_assignment type
;
72 constexpr bool prop_on_swap()
74 typedef typename
A::propagate_on_container_swap type
;
78 template<typename A
, bool C
, bool M
, bool S
>
79 constexpr bool test1()
81 static_assert( prop_on_copy
<A
>() == C
, "copy" );
82 static_assert( prop_on_move
<A
>() == M
, "move" );
83 static_assert( prop_on_swap
<A
>() == S
, "swap" );
87 template<bool C
, bool M
, bool S
>
88 constexpr bool test2()
90 typedef minimal_allocator
<test_type
> base_alloc
;
91 typedef test_allocator
<test_type
, C
, M
, S
> test_alloc
;
92 typedef scoped_allocator_adaptor
<base_alloc
, test_alloc
> scoped1
;
93 typedef scoped_allocator_adaptor
<test_alloc
, base_alloc
> scoped2
;
94 typedef scoped_allocator_adaptor
<test_alloc
, test_alloc
> scoped3
;
95 return test1
<scoped1
, C
, M
, S
>()
96 && test1
<scoped2
, C
, M
, S
>()
97 && test1
<scoped3
, C
, M
, S
>();
100 static_assert( test2
<false, false, false>(), "never propagate" );
101 static_assert( test2
<true, false, false>(), "propagate on copy" );
102 static_assert( test2
<false, true, false>(), "propagate on move" );
103 static_assert( test2
<false, false, true>(), "propagate on swap" );
104 static_assert( test2
<true, true, false>(), "propagate on copy & move" );
105 static_assert( test2
<true, false, true>(), "propagate on copy & swap" );
106 static_assert( test2
<false, true, true>(), "propagate on move & swap" );
107 static_assert( test2
<true, true, true>(), "always propagate" );