]>
Commit | Line | Data |
---|---|---|
9378b06e | 1 | // PR c++/59867 |
e4276ba5 | 2 | // { dg-do compile { target c++14 } } |
9378b06e | 3 | |
9378b06e ESR |
4 | using namespace std; |
5 | ||
6 | // constant | |
7 | template<typename T, T x> | |
8 | struct meta_value | |
9 | { | |
10 | typedef meta_value type; | |
11 | typedef T value_type; | |
12 | static const T value = x; | |
13 | }; | |
14 | ||
15 | // array | |
16 | template<typename T, T... data> | |
17 | struct meta_array | |
18 | { | |
19 | typedef meta_array type; | |
20 | typedef T item_type; | |
21 | }; | |
22 | ||
23 | // static array -> runtime array conversion utility | |
24 | template<typename T> | |
25 | struct array_gen; | |
26 | ||
27 | template<typename T, T... xs> | |
28 | struct array_gen<meta_array<T, xs...>> | |
29 | { | |
30 | static const T value[sizeof...(xs)]; | |
31 | }; | |
32 | ||
33 | template<typename T, T... xs> | |
34 | const T | |
35 | array_gen<meta_array<T, xs...>>::value[sizeof...(xs)] = {xs...}; | |
36 | ||
37 | // static string | |
38 | template<typename T, T... xs> | |
39 | constexpr meta_array<T, xs...> | |
40 | operator""_s() | |
41 | { | |
42 | static_assert(sizeof...(xs) == 3, "What's wrong with you?"); | |
43 | return meta_array<T, xs...>(); | |
44 | } | |
45 | ||
46 | int | |
47 | main() | |
48 | { | |
49 | auto a = "123"_s; | |
50 | const char (& xs)[3] = array_gen<decltype("123"_s)>::value; | |
51 | } |