记录一下 __gnu_cxx::hash_map传一个新allocator的写法

本文详细介绍了如何使用__gnu_cxx::hash_map创建角色实例,包括定义全局的角色指针分配器__gnu_cxx::__pool_alloc及实例化过程。通过具体参数设置展示了hash_map的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

老得查代码写,这里记录一下:

hash_map(size_type __n, const hasher& __hf, 
    const key_equal& __eql, const allocator_type& __a = allocator_type())
 

// 全局的角色指针Allocator
__gnu_cxx::__pool_alloc<Role*> g_rolePtrAlloc; 


typedef __gnu_cxx::hash_map<
     uint32_t, 
     Role*, 
     __gnu_cxx::hash<uint32_t>, 
     std::equal_to<uint32_t>, 
     __gnu_cxx::__pool_alloc<Role*> > Roles;
Roles roles(5000, __gnu_cxx::hash<uint32_t>(), 
    std::equal_to<uint32_t>(), g_rolePtrAlloc);


转载于:https://www.cnblogs.com/herm/archive/2012/02/23/2773917.html

分析编译错误:/home/shz/Project/appHDQt6/parammanager.cpp:96: error: no match for ‘operator==’ (operand types are ‘const ParamMetaData’ and ‘const T’ {aka ‘const ParamMetaData’}) In file included from ../../Qt6/6.7.3/gcc_64/include/QtCore/QMap:1, from ../appHDQt6/parammanager.h:5, from ../appHDQt6/parammanager.cpp:1: ../../Qt6/6.7.3/gcc_64/include/QtCore/qmap.h: In instantiation of ‘QMapData<AMap>::valueIsEqualTo(const T&) [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::T = ParamMetaData]::<lambda(const auto:29&)> [with auto:29 = std::pair<const QString, ParamMetaData>]’: /usr/include/c++/9/bits/predefined_ops.h:283:11: required from ‘bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = std::_Rb_tree_const_iterator<std::pair<const QString, ParamMetaData> >; _Predicate = QMapData<AMap>::valueIsEqualTo(const T&) [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::T = ParamMetaData]::<lambda(const auto:29&)>]’ /usr/include/c++/9/bits/stl_algo.h:104:42: required from ‘_InputIterator std::__find_if(_InputIterator, _InputIterator, _Predicate, std::input_iterator_tag) [with _InputIterator = std::_Rb_tree_const_iterator<std::pair<const QString, ParamMetaData> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<QMapData<AMap>::valueIsEqualTo(const T&) [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::T = ParamMetaData]::<lambda(const auto:29&)> >]’ /usr/include/c++/9/bits/stl_algo.h:161:23: required from ‘_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = std::_Rb_tree_const_iterator<std::pair<const QString, ParamMetaData> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<QMapData<AMap>::valueIsEqualTo(const T&) [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::T = ParamMetaData]::<lambda(const auto:29&)> >]’ /usr/include/c++/9/bits/stl_algo.h:3969:28: required from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = std::_Rb_tree_const_iterator<std::pair<const QString, ParamMetaData> >; _Predicate = QMapData<AMap>::valueIsEqualTo(const T&) [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::T = ParamMetaData]::<lambda(const auto:29&)>]’ ../../Qt6/6.7.3/gcc_64/include/QtCore/qmap.h:83:30: required from ‘QMapData<AMap>::Key QMapData<AMap>::key(const T&, const Key&) const [with AMap = std::map<QString, ParamMetaData, std::less<QString>, std::allocator<std::pair<const QString, ParamMetaData> > >; QMapData<AMap>::Key = QString; QMapData<AMap>::T = ParamMetaData]’ ../../Qt6/6.7.3/gcc_64/include/QtCore/qmap.h:353:40: required from ‘Key QMap<Key, T>::key(const T&, const Key&) const [with Key = QString; T = ParamMetaData]’ ../appHDQt6/parammanager.cpp:96:43: required from here ../../Qt6/6.7.3/gcc_64/include/QtCore/qmap.h:78:58: error: no match for ‘operator==’ (operand types are ‘const ParamMetaData’ and ‘const T’ {aka ‘const ParamMetaData’}) 78 | return [&value](const auto &v) { return v.second == value; }; | ~~~~~~~~~^~~~~~~~
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值