]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc
Allocator-extended constructors for container adaptors.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / stack / requirements / uses_allocator.cc
1 // Copyright (C) 2014-2015 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-options "-std=gnu++11" }
19 // { dg-do compile }
20
21 #include <stack>
22
23 using test_type = std::stack<int>;
24 using container = test_type::container_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 valid 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 "stack(const Alloc&)" );
39 static_assert( is_constructible<const container&, const alloc_type&>::value,
40 "stack(const container_type&, const Alloc&)" );
41 static_assert( is_constructible<container&&, const alloc_type&>::value,
42 "stack(const container_type&, const Alloc&)" );
43 static_assert( is_constructible<const test_type&, const alloc_type&>::value,
44 "stack(const stack&, const Alloc&)" );
45 static_assert( is_constructible<test_type&&, const alloc_type&>::value,
46 "stack(const stack&, const Alloc&)" );
47
48 // test with invalid allocator
49 struct X { };
50
51 static_assert( !uses_allocator<X>::value, "invalid allocator" );
52
53 static_assert( !is_constructible<const X&>::value,
54 "stack(const NonAlloc&)" );
55 static_assert( !is_constructible<const container&, const X&>::value,
56 "stack(const container_type&, const NonAlloc&)" );
57 static_assert( !is_constructible<container&&, const X&>::value,
58 "stack(const container_type&, const NonAlloc&)" );
59 static_assert( !is_constructible<const test_type&, const X&>::value,
60 "stack(const stack&, const NonAlloc&)" );
61 static_assert( !is_constructible<test_type&&, const X&>::value,
62 "stack(const stack&, const NonAlloc&)" );