/cp
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / pr59867.C
blob2c4f1d046bf30099e74efa85b7b01d9643975f62
1 // PR c++/59867
2 // { dg-do compile { target c++14 } }
4 using namespace std;
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   };
15 // array
16 template<typename T, T... data>
17   struct meta_array
18   {
19     typedef meta_array type;
20     typedef T item_type;
21   };
23 // static array -> runtime array conversion utility
24 template<typename T>
25   struct array_gen;
27 template<typename T, T... xs>
28   struct array_gen<meta_array<T, xs...>>
29   {
30     static const T value[sizeof...(xs)];
31   };
33 template<typename T, T... xs>
34   const T
35   array_gen<meta_array<T, xs...>>::value[sizeof...(xs)] = {xs...};
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   }
46 int
47 main()
49   auto a = "123"_s;
50   const char (& xs)[3] = array_gen<decltype("123"_s)>::value;