Debian Codegraph @

libstdc++-v3/testsuite/experimental/polymorphic_allocator/construct_pair.cc

raw
1 // Copyright (C) 2018-2025 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8
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.
13
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/>.
17
18 // { dg-do run { target c++14 } }
19
20 #include <experimental/memory_resource>
21 #include <utility>
22 #include <tuple>
23
24 struct A { };
25
26 void
27 test01()
28 {
29 struct X {
30 X(A&&) { }
31 };
32
33 using pair = std::pair<X, int>;
34 std::experimental::pmr::polymorphic_allocator<pair> a;
35 auto ptr = a.allocate(1);
36 a.construct(ptr, std::piecewise_construct,
37 std::tuple<A>{}, std::make_tuple(1));
38 a.deallocate(ptr, 1);
39 }
40
41 void
42 test02()
43 {
44 struct X {
45 using allocator_type = std::experimental::pmr::polymorphic_allocator<int>;
46 X(A&&, const allocator_type&) { }
47 };
48
49 using pair = std::pair<X, int>;
50 std::experimental::pmr::polymorphic_allocator<pair> a;
51 auto ptr = a.allocate(1);
52 a.construct(ptr, std::piecewise_construct,
53 std::tuple<A>{}, std::make_tuple(1));
54 a.deallocate(ptr, 1);
55 }
56
57 void
58 test03()
59 {
60 struct X {
61 using allocator_type = std::experimental::pmr::polymorphic_allocator<int>;
62 X(std::allocator_arg_t, const allocator_type&, A&&) { }
63 };
64
65 using pair = std::pair<X, int>;
66 std::experimental::pmr::polymorphic_allocator<pair> a;
67 auto ptr = a.allocate(1);
68 a.construct(ptr, std::piecewise_construct,
69 std::tuple<A>{}, std::make_tuple(1));
70 a.deallocate(ptr, 1);
71 }
72
73 int main()
74 {
75 test01();
76 test02();
77 test03();
78 }