]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc
1 // Copyright (C) 2017-2024 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do compile { target c++11 } }
24 template<typename T
, typename U
>
25 using Rebind
= typename
std::allocator_traits
<T
>::template rebind_alloc
<U
>;
27 template<typename T
, typename
= T
>
30 template<typename U
> struct rebind
{ using other
= HasRebind
<U
>; };
33 // Would get HasRebind<long, int> here if the first template argument is
34 // replaced instead of using the nested rebind.
35 static_assert(is_same
<Rebind
<HasRebind
<int>, long>, HasRebind
<long>>::value
,
36 "nested alias template is used");
43 static_assert(is_same
<Rebind
<NoRebind0
<int>, long>,
44 NoRebind0
<long>>::value
,
45 "first template argument is replaced");
47 template<typename T
, typename
>
52 static_assert(is_same
<Rebind
<NoRebind1
<int, void>, long>,
53 NoRebind1
<long, void>>::value
,
54 "first template argument is replaced");
56 template<typename T
, typename
, typename
>
61 static_assert(is_same
<Rebind
<NoRebind2
<int, void, void>, long>,
62 NoRebind2
<long, void, void>>::value
,
63 "first template argument is replaced");
65 template<typename T
, typename
...>
70 static_assert(is_same
<Rebind
<NoRebindN
<int>, long>,
71 NoRebindN
<long>>::value
,
72 "first template argument is replaced");
73 static_assert(is_same
<Rebind
<NoRebindN
<int, void>, long>,
74 NoRebindN
<long, void>>::value
,
75 "first template argument is replaced");
77 template<typename T
, int = 0>
81 // PR libstdc++/72792 specialization of allocator_traits is still well-formed:
82 std::allocator_traits
<CannotRebind
<int>>::value_type v
;