]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/scoped_allocator/construct_pair_c++2a.cc
1 // Copyright (C) 2019-2024 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-do run { target c++20 } }
20 // P0591R4 makes uses-allocator construction apply recursively for nested pairs
22 #include <scoped_allocator>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
29 using allocator_type
= __gnu_test::uneq_allocator
<int>;
31 X(int personality
) : a(personality
) { }
32 X(std::allocator_arg_t
, allocator_type a
) : a(a
) { }
33 X(std::allocator_arg_t
, allocator_type a
, const X
&) : a(a
) { }
41 using value_type
= std::pair
<std::pair
<X
, int>, std::pair
<int, X
>>;
43 = std::scoped_allocator_adaptor
<__gnu_test::uneq_allocator
<value_type
>>;
45 const scoped_alloc
a(10);
46 std::vector
<value_type
, scoped_alloc
> v(a
);
47 VERIFY( v
.get_allocator().get_personality() == a
.get_personality() );
49 value_type
val( { X(1), 2 }, { 3, X(4) } );
51 X
& x1
= v
.back().first
.first
;
52 VERIFY( x1
.a
.get_personality() != val
.first
.first
.a
.get_personality() );
53 VERIFY( x1
.a
.get_personality() == a
.get_personality() );
55 X
& x2
= v
.back().second
.second
;
56 VERIFY( x2
.a
.get_personality() != val
.second
.second
.a
.get_personality() );
57 VERIFY( x2
.a
.get_personality() == a
.get_personality() );
59 // Check other members of the pairs are correctly initialized too:
60 VERIFY( v
.back().first
.second
== val
.first
.second
);
61 VERIFY( v
.back().second
.first
== val
.second
.first
);
67 using value_type
= std::pair
<std::pair
<X
, int>, std::pair
<int, X
>>;
69 = std::scoped_allocator_adaptor
<__gnu_test::uneq_allocator
<value_type
>,
72 const scoped_alloc
a(10, 20);
73 std::vector
<value_type
, scoped_alloc
> v(a
);
74 VERIFY( v
.get_allocator().get_personality() == a
.get_personality() );
76 value_type
val( { X(1), 2 }, { 3, X(4) } );
78 X
& x1
= v
.back().first
.first
;
79 VERIFY( x1
.a
.get_personality() != val
.first
.first
.a
.get_personality() );
80 VERIFY( x1
.a
.get_personality() != a
.get_personality() );
81 VERIFY( x1
.a
.get_personality() == a
.inner_allocator().get_personality() );
83 X
& x2
= v
.back().second
.second
;
84 VERIFY( x2
.a
.get_personality() != val
.second
.second
.a
.get_personality() );
85 VERIFY( x2
.a
.get_personality() != a
.get_personality() );
86 VERIFY( x2
.a
.get_personality() == a
.inner_allocator().get_personality() );
88 // Check other members of the pairs are correctly initialized too:
89 VERIFY( v
.back().first
.second
== val
.first
.second
);
90 VERIFY( v
.back().second
.first
== val
.second
.first
);