greywolf82
greywolf82

Reputation: 22193

Standard hash with variadic template

I have the following code:

namespace foo {
template<typename ...Types>
class Pi {
};
}

namespace std {
        template<> //line offending gcc 8.3.1
        template<typename ...Types>
        struct hash<foo::Pi<Types...>> {
            std::size_t operator()( const foo::Pi<Types...>& s ) const noexcept {
              return 0;
            }
        };
}


int main() {
   return 0;
}

Using gcc 8.3.1 I receive the error too much parameters template-parametr-list, while using gcc 4.8.3 it works. If I remove the commented line above it works, is it correct however?

Upvotes: 1

Views: 122

Answers (1)

user17732522
user17732522

Reputation: 76859

The newer GCC version is correct.

template<> is not valid syntax here. It is only used for explicit specialization of a template.

What you are doing here is partial specialization of std::hash, since you are not specializing for just one specific type, but all types that could be instantiated from foo::Pi. Without template<> you have the correct syntax for partial specialization.

Upvotes: 2

Related Questions