]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/pointer_traits/rebind.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / pointer_traits / rebind.cc
1 // Copyright (C) 2017-2019 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::pointer_traits<T>::template rebind<U>;
26
27 template<typename T>
28 struct HasRebind {
29 template<typename U> using rebind = U*;
30 };
31
32 static_assert(is_same<Rebind<HasRebind<int>, long>,
33 long*>::value,
34 "nested alias template is used");
35
36 template<typename T> struct NoRebind0 { };
37
38 static_assert(is_same<Rebind<NoRebind0<int>, long>,
39 NoRebind0<long>>::value,
40 "first template argument is replaced");
41
42 template<typename T, typename> struct NoRebind1 { };
43
44 static_assert(is_same<Rebind<NoRebind1<int, void>, long>,
45 NoRebind1<long, void>>::value,
46 "first template argument is replaced");
47
48 template<typename T, typename, typename> struct NoRebind2 { };
49
50 static_assert(is_same<Rebind<NoRebind2<int, void, void>, long>,
51 NoRebind2<long, void, void>>::value,
52 "first template argument is replaced");
53
54 template<typename T, typename...> struct NoRebindN { };
55
56 static_assert(is_same<Rebind<NoRebindN<int>, long>,
57 NoRebindN<long>>::value,
58 "first template argument is replaced");
59 static_assert(is_same<Rebind<NoRebindN<int, void>, long>,
60 NoRebindN<long, void>>::value,
61 "first template argument is replaced");
62
63 template<typename T, int = 0>
64 struct CannotRebind {
65 using element_type = T;
66 };
67 // PR libstdc++/72793 specialization of pointer_traits is still well-formed:
68 std::pointer_traits<CannotRebind<int>>::element_type e;