0

I am trying to compile a project on my mac, which is originally written on linux. It went smoothly on archlinux but has a lot of errors on mac. Especially, I'm very confused with this error message:

In file included from /Users/STW/Documents/neuroblaze/nb/tagged_index/tagged_index.t.hpp:4:
/Users/STW/Documents/neuroblaze/nb/tagged_index/tagged_index.hpp:425:26: error: 
      implicit instantiation of undefined template 'std::hash<unsigned long>'
  ::std::hash<IndexType> hasher;
                         ^

And here is the relevant code:(tagged_index.hpp)

namespace std {
/**
 * tagged_index can be hashed. Just forwards the hash to the contained type.
 *
 * @ingroup TaggedIndex
 */
template <typename UniquenessTag, typename IndexType,
          typename ConstructorFunction>
struct hash<tsb::tagged_index<UniquenessTag, IndexType, ConstructorFunction>> {
  using value_type =
      tsb::tagged_index<UniquenessTag, IndexType, ConstructorFunction>;
  ::std::hash<IndexType> hasher;
  size_t operator()(const value_type& l) const { return hasher(l); }
};

/**
 * tagged_offset can be hashed. Just forwards the hash to the contained type.
 *
 * @ingroup TaggedOffset
 */
template <typename UniquenessTag, typename IndexType,
          typename ConstructorFunction>
struct hash<tsb::tagged_offset<UniquenessTag, IndexType, ConstructorFunction>> {
  using value_type =
      tsb::tagged_offset<UniquenessTag, IndexType, ConstructorFunction>;
  ::std::hash<IndexType> hasher;
  size_t operator()(const value_type& l) const { return hasher(l); }
};

} // end namespace std

I have included functional in this hpp file.

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
Nothing More
  • 873
  • 12
  • 29

1 Answers1

1

Are you also including "memory"? I just found what may be a bug in Clang's standard library code.

It has the following definition of hash:

template <class _Tp> struct hash; 

This is not the same as the one in __functional_base:

template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;

This may violate the ODR, depending on how _LIBCPP_TYPE_VIS_ONLY is defined. All the specializations for hash<> of integer types use that symbol, so possibly the redefinition is invalidating them.

I found that including functional after memory gets better results than including memory after functional.