]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unsynchronized_pool_resource/cons.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unsynchronized_pool_resource / cons.cc
1 // Copyright (C) 2018-2023 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++17 } }
19
20 #include <memory_resource>
21 #include <testsuite_hooks.h>
22 #include <testsuite_allocator.h>
23
24 void
25 test01()
26 {
27 __gnu_test::memory_resource test_mr1, test_mr2;
28 __gnu_test::default_resource_mgr mgr(&test_mr1);
29
30 const std::pmr::pool_options opts{1, 2};
31 using std::pmr::unsynchronized_pool_resource;
32
33 unsynchronized_pool_resource p1 = {opts, &test_mr2};
34 VERIFY( p1.upstream_resource() == &test_mr2 );
35 unsynchronized_pool_resource p2;
36 VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() );
37 unsynchronized_pool_resource p3{&test_mr2};
38 VERIFY( p3.upstream_resource() == &test_mr2 );
39 unsynchronized_pool_resource p4{opts};
40 VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() );
41
42 static_assert(!std::is_copy_constructible_v<unsynchronized_pool_resource>);
43 static_assert(!std::is_copy_assignable_v<unsynchronized_pool_resource>);
44 static_assert(std::is_destructible_v<unsynchronized_pool_resource>);
45 }
46
47 void
48 test02()
49 {
50 __gnu_test::memory_resource test_mr1, test_mr2;
51 __gnu_test::default_resource_mgr mgr(&test_mr1);
52
53 const std::pmr::pool_options opts{1, 2};
54
55 struct derived : std::pmr::unsynchronized_pool_resource
56 {
57 using unsynchronized_pool_resource::unsynchronized_pool_resource;
58 };
59
60 derived p1 = {opts, &test_mr2};
61 VERIFY( p1.upstream_resource() == &test_mr2 );
62 derived p2;
63 VERIFY( p2.upstream_resource() == std::pmr::get_default_resource() );
64 derived p3{&test_mr2};
65 VERIFY( p3.upstream_resource() == &test_mr2 );
66 derived p4{opts};
67 VERIFY( p4.upstream_resource() == std::pmr::get_default_resource() );
68
69 static_assert(!std::is_copy_constructible_v<derived>);
70 static_assert(!std::is_copy_assignable_v<derived>);
71 static_assert(std::is_destructible_v<derived>);
72 }
73
74 int
75 main()
76 {
77 test01();
78 test02();
79 }