]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
a5544970 1// Copyright (C) 2017-2019 Free Software Foundation, Inc.
a3a1620b
JW
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
22using std::is_same;
23
24template<typename T, typename U>
25 using Rebind = typename std::allocator_traits<T>::template rebind_alloc<U>;
26
27template<typename T>
28 struct HasRebind {
29 using value_type = T;
30 template<typename U> struct rebind { using other = std::allocator<U>; };
31 };
32
33static_assert(is_same<Rebind<HasRebind<int>, long>,
34 std::allocator<long>>::value,
35 "nested alias template is used");
36
37template<typename T>
38 struct NoRebind0 {
39 using value_type = T;
40 };
41
42static_assert(is_same<Rebind<NoRebind0<int>, long>,
43 NoRebind0<long>>::value,
44 "first template argument is replaced");
45
46template<typename T, typename>
47 struct NoRebind1 {
48 using value_type = T;
49 };
50
51static_assert(is_same<Rebind<NoRebind1<int, void>, long>,
52 NoRebind1<long, void>>::value,
53 "first template argument is replaced");
54
55template<typename T, typename, typename>
56 struct NoRebind2 {
57 using value_type = T;
58 };
59
60static_assert(is_same<Rebind<NoRebind2<int, void, void>, long>,
61 NoRebind2<long, void, void>>::value,
62 "first template argument is replaced");
63
64template<typename T, typename...>
65 struct NoRebindN {
66 using value_type = T;
67 };
68
69static_assert(is_same<Rebind<NoRebindN<int>, long>,
70 NoRebindN<long>>::value,
71 "first template argument is replaced");
72static_assert(is_same<Rebind<NoRebindN<int, void>, long>,
73 NoRebindN<long, void>>::value,
74 "first template argument is replaced");
75
76template<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:
81std::allocator_traits<CannotRebind<int>>::value_type v;