while exploring the subject of constexpr/operator"' features of C++11 I stumbled upon this article: http://www.codeproject.com/Articles/447922/Application-of-Cplusplus11-User-Defined-Literals-t
It quotes an example of how would a code providing string-to-binary-number udl look like:
constexpr unsigned long long ToBinary(unsigned long long x, const char* s)
{
return (!*s ? x : ToBinary(x + x + (*s =='1'? 1 : 0), s+1));
}
constexpr unsigned long long int operator "" _b(const char* s)
{ return ToBinary(0,s);}
it all works as advertised, but I do not quite like that the global namespace is contaminated with the auxilliary ToBinary function. Instead of trying to mangle the function's name I was attempting to conceive a solution which would have a recursive lambda function embedded within the operator"" body.
Solutions for recursive lambdas in C++ are known and they employ std::function usage. To make that possible within the constexpr operator"" one would need to have the declaration and invocation of the recursive lambda embedded within a single return statement. My attempts to achieve that failed, so I am resorting to SO for help. Is having recursive lambda invoked within constexpr operator"" possible at all? If so, what hints are there?
Thanks,