]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / rebind_alloc.cc
1 // Copyright (C) 2017-2020 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 <memory>
21
22 using std::is_same;
23
24 template<typename T, typename U>
25 using Rebind = typename std::allocator_traits<T>::template rebind_alloc<U>;
26
27 template<typename T>
28 struct HasRebind {
29 using value_type = T;
30 template<typename U> struct rebind { using other = std::allocator<U>; };
31 };
32
33 static_assert(is_same<Rebind<HasRebind<int>, long>,
34 std::allocator<long>>::value,
35 "nested alias template is used");
36
37 template<typename T>
38 struct NoRebind0 {
39 using value_type = T;
40 };
41
42 static_assert(is_same<Rebind<NoRebind0<int>, long>,
43 NoRebind0<long>>::value,
44 "first template argument is replaced");
45
46 template<typename T, typename>
47 struct NoRebind1 {
48 using value_type = T;
49 };
50
51 static_assert(is_same<Rebind<NoRebind1<int, void>, long>,
52 NoRebind1<long, void>>::value,
53 "first template argument is replaced");
54
55 template<typename T, typename, typename>
56 struct NoRebind2 {
57 using value_type = T;
58 };
59
60 static_assert(is_same<Rebind<NoRebind2<int, void, void>, long>,
61 NoRebind2<long, void, void>>::value,
62 "first template argument is replaced");
63
64 template<typename T, typename...>
65 struct NoRebindN {
66 using value_type = T;
67 };
68
69 static_assert(is_same<Rebind<NoRebindN<int>, long>,
70 NoRebindN<long>>::value,
71 "first template argument is replaced");
72 static_assert(is_same<Rebind<NoRebindN<int, void>, long>,
73 NoRebindN<long, void>>::value,
74 "first template argument is replaced");
75
76 template<typename T, int = 0>
77 struct CannotRebind {
78 using value_type = T;
79 };
80 // PR libstdc++/72792 specialization of allocator_traits is still well-formed:
81 std::allocator_traits<CannotRebind<int>>::value_type v;