]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/uses_allocator/construction.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / uses_allocator / construction.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
b8214660 2
83ffe9cd 3// Copyright (C) 2011-2023 Free Software Foundation, Inc.
b8214660
JW
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20// 20.6.7.2 uses-allocator construction
21
22#include <memory>
23#include <tuple>
24#include <testsuite_hooks.h>
25
26struct MyAlloc { };
27
28// type that can't be constructed with an allocator
29struct CannotUse
30{
31 CannotUse(int) : ok(true) { }
32
33 bool ok;
34};
35
36// type that can be constructed with an allocator
37// but which has uses_allocator == false
38struct DoesNotUse
39{
40 typedef MyAlloc allocator_type;
41
42 DoesNotUse(int) : ok(true) { }
43 DoesNotUse(std::allocator_arg_t, MyAlloc, int) : ok(false) { }
44 DoesNotUse(int, MyAlloc) : ok(false) { }
45
46 bool ok;
47};
48
49namespace std
50{
51 template<typename A>
52 struct uses_allocator<DoesNotUse, A> : false_type { };
53}
54
55// type that can be constructed with an allocator as second argument
56struct UsesWithTag
57{
58 typedef MyAlloc allocator_type;
59
60 UsesWithTag(int) : ok(false) { }
61 UsesWithTag(std::allocator_arg_t, MyAlloc, int) : ok(true) { }
62 UsesWithTag(int, MyAlloc) : ok(false) { }
63
64 bool ok;
65};
66
67// type that can be constructed with an allocator as last argument
68struct UsesWithoutTag
69{
70 typedef MyAlloc allocator_type;
71
72 UsesWithoutTag(int) : ok(false) { }
73 UsesWithoutTag(int, MyAlloc) : ok(true) { }
74
75 bool ok;
76};
77
78
79template<typename TestType, typename... T>
80 bool test2(T... args)
81 {
82 using std::allocator_arg;
83 using std::tuple;
84 using std::get;
85
86 tuple<TestType, T...> t(allocator_arg, MyAlloc(), 1, args...);
87
88 return get<0>(t).ok;
89 }
90
91template<typename... T>
92 void test(T... args)
93 {
b8214660
JW
94 VERIFY( test2<CannotUse>(args...) );
95 VERIFY( test2<DoesNotUse>(args...) );
96 VERIFY( test2<UsesWithTag>(args...) );
97 VERIFY( test2<UsesWithoutTag>(args...) );
98 }
99
100int main()
101{
102 test();
103 test(1);
104 test(1, 2);
105 return 0;
106}