c++ - 将 absl::flat_hash_set 与 folly::small_vector 一起使用
问题描述
我正在尝试创建一个absl::flat_hash_set
of folly::small_vector
。添加对 absl::Hash 的自定义类型的支持的文档说:
类型的
AbslHashValue
重载只能在与所述类型相同的文件和命名空间中声明。给定类型的正确AbslHashValue
实现将通过 ADL 发现。
不幸的是,我不能这样做,因为我不控制库的源代码或安装。
所以我试过这个:
// 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.data(), sequence.size());
}
return h;
}
// MyClass.h
class MyClass {
//...
private:
absl::flat_hash_set<tSequences> _sequences;
};
但是我得到了大量的模板错误,这些错误似乎表明我的类型不能被散列:
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>, 4, folly::small_vector_policy::NoHeap> >) (const key_type&)’
551 | auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k));
我能做些什么来让folly::small_vector
Abseil 可以散列吗?
解决方案
推荐阅读
- php - 每次满足if语句时,如何为多维数组中的每个人添加一个int值到'i'
- jquery - 用户滚动时使用 jQuery 更改 rgba 背景颜色
- msbuild - 如何让 msbuild 识别另一个字母表中的字符?
- regex - 如何使用正则表达式排序?
- vb.net - 如何使搜索栏等于 vb.net 中的 Windows 文件资源管理器?
- django - 如何为单个视图制作 404 页面?
- arrays - 矩阵/二维numpy数组中的着色条目?
- python - 如何绘制单点初始化?
- .net - MVC1000 警告死锁的根本原因是什么(使用 IHtmlHelper.Partial 可能导致应用程序死锁......)
- vba - 自动导出访问表数据以填充模板 Excel 工作表