]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / stack / requirements / uses_allocator.cc
1 // Copyright (C) 2014-2022 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 <stack>
21
22 using test_type = std::stack<int>;
23 using container = test_type::container_type;
24
25 template<typename A>
26 using uses_allocator = std::uses_allocator<test_type, A>;
27
28 template<typename... Args>
29 using is_constructible = std::is_constructible<test_type, Args...>;
30
31 // test with valid allocator
32 using alloc_type = container::allocator_type;
33
34 static_assert( uses_allocator<alloc_type>::value, "valid allocator" );
35
36 static_assert( is_constructible<const alloc_type&>::value,
37 "stack(const Alloc&)" );
38 static_assert( is_constructible<const container&, const alloc_type&>::value,
39 "stack(const container_type&, const Alloc&)" );
40 static_assert( is_constructible<container&&, const alloc_type&>::value,
41 "stack(const container_type&, const Alloc&)" );
42 static_assert( is_constructible<const test_type&, const alloc_type&>::value,
43 "stack(const stack&, const Alloc&)" );
44 static_assert( is_constructible<test_type&&, const alloc_type&>::value,
45 "stack(const stack&, const Alloc&)" );
46
47 // test with invalid allocator
48 struct X { };
49
50 static_assert( !uses_allocator<X>::value, "invalid allocator" );
51
52 static_assert( !is_constructible<const X&>::value,
53 "stack(const NonAlloc&)" );
54 static_assert( !is_constructible<const container&, const X&>::value,
55 "stack(const container_type&, const NonAlloc&)" );
56 static_assert( !is_constructible<container&&, const X&>::value,
57 "stack(const container_type&, const NonAlloc&)" );
58 static_assert( !is_constructible<const test_type&, const X&>::value,
59 "stack(const stack&, const NonAlloc&)" );
60 static_assert( !is_constructible<test_type&&, const X&>::value,
61 "stack(const stack&, const NonAlloc&)" );