]>
Commit | Line | Data |
---|---|---|
8ca1fae5 | 1 | // { dg-options "-std=gnu++11" } |
2 | // { dg-do compile } | |
3 | ||
f1717362 | 4 | // Copyright (C) 2015-2016 Free Software Foundation, Inc. |
8ca1fae5 | 5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | // | |
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <type_traits> | |
22 | ||
23 | template<typename T, typename I0, typename... I> | |
24 | struct smallest_rank | |
25 | : std::conditional< sizeof(T) == sizeof(I0), | |
26 | I0, | |
27 | typename smallest_rank<T, I...>::type > | |
28 | { }; | |
29 | ||
30 | template<typename T, typename I0> | |
31 | struct smallest_rank<T, I0> | |
32 | { using type = I0; }; | |
33 | ||
34 | template<typename T> | |
35 | using smallest_rank_t | |
36 | = typename smallest_rank<typename std::remove_cv<T>::type, | |
37 | unsigned char, unsigned short, unsigned int, | |
38 | unsigned long, unsigned long long>::type; | |
39 | ||
40 | using std::make_unsigned; | |
41 | using std::is_same; | |
42 | ||
43 | enum E1 : char { }; | |
44 | using I1 = smallest_rank_t<E1>; | |
45 | static_assert(is_same<make_unsigned<E1>::type, I1>::value, ""); | |
46 | static_assert(is_same<make_unsigned<E1 const>::type, I1 const>::value, ""); | |
47 | ||
48 | enum E2 : short { }; | |
49 | using I2 = smallest_rank_t<E2>; | |
50 | static_assert(is_same<make_unsigned<E2>::type, I2>::value, ""); | |
51 | static_assert(is_same<make_unsigned<E2 const>::type, I2 const>::value, ""); | |
52 | ||
53 | enum E3 : int { }; | |
54 | using I3 = smallest_rank_t<E3>; | |
55 | static_assert(is_same<make_unsigned<E3>::type, I3>::value, ""); | |
56 | static_assert(is_same<make_unsigned<E3 const>::type, I3 const>::value, ""); | |
57 | ||
58 | enum E4 : long { }; | |
59 | using I4 = smallest_rank_t<E4>; | |
60 | static_assert(is_same<make_unsigned<E4>::type, I4>::value, ""); | |
61 | static_assert(is_same<make_unsigned<E4 const>::type, I4 const>::value, ""); | |
62 | ||
63 | // PI libstdc++/60333 | |
64 | enum E5 : long long { }; | |
65 | using I5 = smallest_rank_t<E5>; | |
66 | static_assert(is_same<make_unsigned<E5>::type, I5>::value, ""); | |
67 | static_assert(is_same<make_unsigned<E5 const>::type, I5 const>::value, ""); |