]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/scoped_allocator/construct_pair_c++2a.cc
1 // Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
21 // P0591R4 makes uses-allocator construction apply recursively for nested pairs
23 #include <scoped_allocator>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
30 using allocator_type
= __gnu_test::uneq_allocator
<int>;
32 X(int personality
) : a(personality
) { }
33 X(std::allocator_arg_t
, allocator_type a
) : a(a
) { }
34 X(std::allocator_arg_t
, allocator_type a
, const X
&) : a(a
) { }
42 using value_type
= std::pair
<std::pair
<X
, int>, std::pair
<int, X
>>;
44 = std::scoped_allocator_adaptor
<__gnu_test::uneq_allocator
<value_type
>>;
46 const scoped_alloc
a(10);
47 std::vector
<value_type
, scoped_alloc
> v(a
);
48 VERIFY( v
.get_allocator().get_personality() == a
.get_personality() );
50 value_type
val( { X(1), 2 }, { 3, X(4) } );
52 X
& x1
= v
.back().first
.first
;
53 VERIFY( x1
.a
.get_personality() != val
.first
.first
.a
.get_personality() );
54 VERIFY( x1
.a
.get_personality() == a
.get_personality() );
56 X
& x2
= v
.back().second
.second
;
57 VERIFY( x2
.a
.get_personality() != val
.second
.second
.a
.get_personality() );
58 VERIFY( x2
.a
.get_personality() == a
.get_personality() );
60 // Check other members of the pairs are correctly initialized too:
61 VERIFY( v
.back().first
.second
== val
.first
.second
);
62 VERIFY( v
.back().second
.first
== val
.second
.first
);
68 using value_type
= std::pair
<std::pair
<X
, int>, std::pair
<int, X
>>;
70 = std::scoped_allocator_adaptor
<__gnu_test::uneq_allocator
<value_type
>,
73 const scoped_alloc
a(10, 20);
74 std::vector
<value_type
, scoped_alloc
> v(a
);
75 VERIFY( v
.get_allocator().get_personality() == a
.get_personality() );
77 value_type
val( { X(1), 2 }, { 3, X(4) } );
79 X
& x1
= v
.back().first
.first
;
80 VERIFY( x1
.a
.get_personality() != val
.first
.first
.a
.get_personality() );
81 VERIFY( x1
.a
.get_personality() != a
.get_personality() );
82 VERIFY( x1
.a
.get_personality() == a
.inner_allocator().get_personality() );
84 X
& x2
= v
.back().second
.second
;
85 VERIFY( x2
.a
.get_personality() != val
.second
.second
.a
.get_personality() );
86 VERIFY( x2
.a
.get_personality() != a
.get_personality() );
87 VERIFY( x2
.a
.get_personality() == a
.inner_allocator().get_personality() );
89 // Check other members of the pairs are correctly initialized too:
90 VERIFY( v
.back().first
.second
== val
.first
.second
);
91 VERIFY( v
.back().second
.first
== val
.second
.first
);