Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading