Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: explicit specialization of non-template class 'hash' #5

Closed
njlr opened this issue May 10, 2017 · 8 comments
Closed

error: explicit specialization of non-template class 'hash' #5

njlr opened this issue May 10, 2017 · 8 comments

Comments

@njlr
Copy link
Contributor

njlr commented May 10, 2017

I get this error when building the tests on macOS:

In file included from test/optional-lite.t.cpp:7:
In file included from test/optional-lite.t.h:12:
include/nonstd/optional.hpp:1070:7: error: explicit specialization of non-template class 'hash'
class hash< nonstd::optional >
^ ~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

My Clang version:

$ clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

My compiler flags:

-std=c++11
@martinmoene
Copy link
Owner

Note to self: investigate CGAL/Nested specialization syntax?.

@martinmoene
Copy link
Owner

martinmoene commented May 11, 2017

Above CGAL link refers to Why can't I specialize std::tuple_element which states the location of the original declaration of hash is not std and the declaration should not be repeated differently:

namespace std {

//    template < class T>
//    struct hash;

template< class T >
class hash< nonstd::optional<T> >
{
public:
    std::size_t operator()( nonstd::optional<T> const & v ) const optional_noexcept
    {
        return bool( v ) ? hash<T>()( *v ) : 0;
    }
};
}

However this situation is not (directly) the case here.

@martinmoene
Copy link
Owner

martinmoene commented May 11, 2017

gsl lite's issue 63 provides more information and circumvents the Clang Xcode problem by using gsl::to_integer<std::size_t>( v ) instead of hash<T>()( v ).

@martinmoene
Copy link
Owner

I gather #include <functional> is missing.

@martinmoene
Copy link
Owner

martinmoene commented May 11, 2017

@njlr Question is: do we now get gsl lite's issue 63 ?

@njlr
Copy link
Contributor Author

njlr commented May 15, 2017

The tests work now.

01-to_int works if I change line 19 to const:

    const char * text = argc > 1 ? argv[1] : "42";

@njlr
Copy link
Contributor Author

njlr commented May 15, 2017

See: #6

@martinmoene
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants