【发布时间】:2013-09-27 02:41:27
【问题描述】:
我正在尝试在我的 mac 上编译一个项目,该项目最初是在 linux 上编写的。它在archlinux上运行顺利,但在mac上有很多错误。特别是,我对这个错误消息感到非常困惑:
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;
^
这里是相关代码:(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
我在这个 hpp 文件中包含了函数。
【问题讨论】:
-
你不能向
namespace std添加东西。 -
其实这不是我的代码。它在archlinux上运行得非常好。很奇怪。
-
@n.m.除了模板的特化,例如these。
-
你的 clang 版本是什么?
-
@C.R. clang 3.3 我启用了 c++11 支持