aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp1y/pr59867.C
blob: 91d025964c0865fe903e193b19c397b36937772a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// PR c++/59867
// { dg-do compile { target c++1y } }

#include <iostream>
using namespace std;

// constant
template<typename T, T x>
  struct meta_value
  {
    typedef meta_value type;
    typedef T value_type;
    static const T value = x;
  };

// array
template<typename T, T... data>
  struct meta_array
  {
    typedef meta_array type;
    typedef T item_type;
  };

// static array -> runtime array conversion utility
template<typename T>
  struct array_gen;

template<typename T, T... xs>
  struct array_gen<meta_array<T, xs...>>
  {
    static const T value[sizeof...(xs)];
  };

template<typename T, T... xs>
  const T
  array_gen<meta_array<T, xs...>>::value[sizeof...(xs)] = {xs...};

// static string
template<typename T, T... xs>
  constexpr meta_array<T, xs...>
  operator""_s()
  {
    static_assert(sizeof...(xs) == 3, "What's wrong with you?");
    return meta_array<T, xs...>();
  }

int
main()
{
  auto a = "123"_s;
  const char (& xs)[3] = array_gen<decltype("123"_s)>::value;
}