I was just trying to crack a binary literal operator ""_b, but stuck trying to stop recursion. How to define a function that can be called using an empty list of template template parameters that does not conflict with parameter package overloading? Then inspiration: juxtapose the empty package extension with something stupid.
But GCC complains that non-existent types of the empty argument list are not consistent with the explicitly unnecessary types of the argument list. Should it work this way?
template< char head, char ... tail >
constexpr unsigned long long parse_binary() {
return ( ( head - '0' ) << sizeof ... (tail) )
+ parse_binary< tail ... >();
}
template< typename = void >
constexpr unsigned long long parse_binary() {
return 0;
}
template< char ... digits >
constexpr unsigned long long operator ""_b() {
return parse_binary< digits ... >();
}
#include <iostream>
int main() {
std::cout << 010101_b << '\n';
}
Note. The question does not implement operator ""_b. This problem can be solved by expanding the package in the parameter list and passing std::integral_constanttypes around.
2: ; . . . , , , ...