I've tried the following code in GCC 4.8:
#include <iostream>
using namespace std;
template <typename T, T... vs>
struct integral_list {
typedef T elem_type;
};
template <typename T, T... vs>
struct gen_array {
static const T data[sizeof...(vs)];
};
template <typename T, T... vs>
const T gen_array<T, vs...>::data[sizeof...(vs)] = { vs... };
template <char... cs>
constexpr auto operator "" _lit() -> integral_list<char, cs...> {
return declval<integral_list<char, cs...>>();
}
int main() {
int (& data)[4] = gen_array<char, decltype("abcd"_lit)>::data;
for (int i = 0; i < 4; ++i)
cout << data[i] << endl;
}
and got
tester.cpp:21:48: error: unable to find string literal operator 'operator"" _lit' with 'const char [5]', 'unsigned int' arguments
while C++11 Standard says
13.5.8.5: The declaration of a literal operator template shall have an empty parameter-declaration-clause and its template-parameter-list shall have a single template-parameter that is a non-type template parameter pack (14.5.3) with element type char.
So either I didn't figure out the line of standard or GCC goes weird. Could you help me solving this dilemma? If not, is there any other way to implement a conversion of string literal to variadic template's argument list?