Autoresponse: I found a complete solution based on comments and other answers to my question, and to other questions, such as https://stackoverflow.com/a/312947/ .
The solution is to use the template form of user-defined literals and add the number manually, multiplying the amount based on the numbers already analyzed by 10.
I wrote a detailed version of this answering machine here: http://scrupulousabstractions.tumblr.com/post/38460349771/c-11-type-safe-use-of-integer-user-defined-literals
template<char... Chars> int operator"" _steps(){ return {litparser<0,Chars...>::value}; }
Litparser is a small metaprogram that takes a list of characters as arguments extended from input characters stored in the Chars parameter package.
typedef unsigned long long ULL; // Delcare the litparser template<ULL Sum, char... Chars> struct litparser; // Specialize on the case where there at least one character left: template<ULL Sum, char Head, char... Rest> struct litparser<Sum, Head, Rest...> { // parse a digit. recurse with new sum and ramaining digits static const ULL value = litparser< (Head <'0' || Head >'9') ? throw std::exception() : Sum*10 + Head-'0' , Rest...>::value; }; // When 'Rest' finally is empty, we reach this terminating case template<ULL Sum> struct litparser<Sum> { static const ULL value = Sum; };
Johan lundberg
source share