Debian Codegraph @

libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc

raw
1 // Copyright (C) 2014-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 compile { target c++11 } }
19
20 #include <queue>
21
22 using test_type = std::priority_queue<int>;
23 using container = test_type::container_type;
24 using comp = std::less<container::value_type>;
25
26 template<typename A>
27 using uses_allocator = std::uses_allocator<test_type, A>;
28
29 template<typename... Args>
30 using is_constructible = std::is_constructible<test_type, Args...>;
31
32 // test with invalid allocator
33 using alloc_type = container::allocator_type;
34
35 static_assert( uses_allocator<alloc_type>::value, "valid allocator" );
36
37 static_assert( is_constructible<const alloc_type&>::value,
38 "priority_queue(const Alloc&)" );
39 static_assert( is_constructible<const comp&, const alloc_type&>::value,
40 "priority_queue(const Cmp&, const Alloc&)" );
41 static_assert( is_constructible<const comp&, const container&,
42 const alloc_type&>::value,
43 "priority_queue(const Cmp&, const Container&, const Alloc&)" );
44 static_assert( is_constructible<const comp&, container&&,
45 const alloc_type&>::value,
46 "priority_queue(const Cmp&, const Container&, const Alloc&)" );
47 static_assert( is_constructible<const test_type&, const alloc_type&>::value,
48 "priority_queue(const priority_queue&, const Alloc&)" );
49 static_assert( is_constructible<test_type&&, const alloc_type&>::value,
50 "priority_queue(const priority_queue&, const Alloc&)" );
51
52 // test with invalid allocator
53 struct X { };
54
55 static_assert( !uses_allocator<X>::value, "invalid allocator" );
56
57 static_assert( !is_constructible<const X&>::value,
58 "priority_queue(const NonAlloc&)" );
59 static_assert( !is_constructible<const comp&, const X&>::value,
60 "priority_queue(const Cmp&, const NonAlloc&)" );
61 static_assert( !is_constructible<const comp&, const container&,
62 const X&>::value,
63 "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" );
64 static_assert( !is_constructible<const comp&, container&&, const X&>::value,
65 "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" );
66 static_assert( !is_constructible<const test_type&, const X&>::value,
67 "priority_queue(const priority_queue&, const NonAlloc&)" );
68 static_assert( !is_constructible<test_type&&, const X&>::value,
69 "priority_queue(const priority_queue&, const NonAlloc&)" );