Currently, only doubles can produce a template of chars in a user defined literal:
template <char...> double operator "" _x();
// Later
1.3_x; // OK
"1.3"_y; // C++14 does not allow a _y user-
// defined operator to parse that as a template of chars
Is there a clever way to produce a std::integer_sequence
of chars using a user defined literal. In other words, what the code of _y(const char*, std::size_t)
would be so that I end up with a std::integer_sequence<char, '1', '.', '3'>
?
At this point in time, the best we can (portably) do is a macro trick as demonstrated for
vtmpl::string
. Basically, we create a list of accesses such as…which we trim to obtain the desired result.
The first step is easily done via
BOOST_PP_ENUM
, although recursive macros are also fine (definition from here):Usage of the above looks like this (trimming included):
Where
rtrim
is defined inalgorithms.hxx
.