Does an empty value package extension correspond to a type package or an optional type parameter?

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 ... >(); // Error: no overload for termination.
}

template< typename = void > // I want this to match an empty pack of chars.
// template< short = 0 > // even this would do.
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: ; . . . , , , ...

+5
2

, , .

, . , , .

, :

template< typename = void > // Define this one first!
constexpr unsigned long long parse_binary() {
    return 0;
}

template< char head, char ... tail >
constexpr unsigned long long parse_binary() {
    return ( ( head - '0' ) << sizeof ... (tail) )
        + parse_binary< tail ... >(); // Bingo: overload found.
}
0

?

template<char Ch>
constexpr unsigned long long parse_binary(){
  return Ch - '0';
};

// second head to disambiguate
template< char head1, char head2, char ... tail >
constexpr unsigned long long parse_binary() {
    return ( ( head1 - '0' ) << sizeof ... (tail)+1 ) + parse_binary< head2, tail ... >();
}

, parse_binary , :

error: call to function 'parse_binary' that is neither visible in
      the template definition nor found by argument-dependent lookup

// call trace...

note: 'parse_binary' should be declared prior to the call site
      constexpr unsigned long long parse_binary() {
+4

All Articles