问题描述
我正在尝试创建connectTimeout
中的absl::flat_hash_set
。添加对absl :: Hash的自定义类型的支持的文档说:
类型的
folly::small_vector
重载只能在同一位置声明 文件和命名空间表示为类型。正确的AbslHashValue
实现 可以通过ADL发现给定类型的数据。
不幸的是,我无法做到这一点,因为我无法控制该库的源代码或安装。
所以我尝试了这个:
AbslHashValue
// Typedefs.h
constexpr size_t MAX_SEQUENCE_LENGTH = 128;
using tSequence = folly::small_vector<
int8_t,MAX_BET_SEQUENCE_LENGTH,folly::small_vector_policy::NoHeap>;
using tSequences = folly::small_vector<
tSequence,4,folly::small_vector_policy::NoHeap>;
template<typename H>
H AbslHashValue(H h,const tSequence& sequence) {
return H::combine_contiguous(std::move(h),sequence.data(),sequence.size());
}
template<typename H>
H AbslHashValue(H h,const tSequences& sequences) {
for(const auto& sequence : sequences) {
h = H::combine_contiguous(std::move(h),sequence.size());
}
return h;
}
但是我收到大量模板错误,这些错误似乎表明无法对我的类型进行散列:
// MyClass.h
class MyClass {
//...
private:
absl::flat_hash_set<tSequences> _sequences;
};
我可以做些什么使Abseil成为error: no match for call to ‘(const absl::hash_internal::Hash<folly::small_vector<folly::small_vector<signed char,128,folly::small_vector_policy::NoHeap>,folly::small_vector_policy::NoHeap> >) (const key_type&)’
551 | auto KeyTypeCanBeHashed(const Hash& h,const key_type& k) -> decltype(h(k));
的哈希值吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)