c – Boost快速池分配器是否存在函数指针问题?

c – Boost快速池分配器是否存在函数指针问题?,第1张

概述这是一个Boost错误还是我做错了什么? #include <map>#include <boost/pool/pool_alloc.hpp>int main(){ typedef const std::string key; typedef double* (*value)(const int&); std::map<key, value, std::less<k 这是一个Boost错误还是我做错了什么?

#include <map>#include <boost/pool/pool_alloc.hpp>int main(){    typedef const std::string key;    typedef double* (*value)(const int&);    std::map<key,value,std::less<key>> map_with_standard_allocator; // works    std::map<key,std::less<key>,boost::fast_pool_allocator<std::pair<const key,value> > > map_with_boost_allocator; // fails}

最后一行无法在MS Visual Studio 2008下使用Boost 1.40和1.48进行编译.然而,它在g 4.5.3(Cygwin)下编译得很好.

错误是:

1>Compiling...1>main.cpp1>C:\Unilib1\trunk\External\boost/pool/pool_alloc.hpp(205) : error C2535: 'const std::basic_string<_Elem,_Traits,_Ax> *boost::fast_pool_allocator<T,UserAllocator,Mutex,NextSize>::address(const std::basic_string<_Elem,_Ax> &)' : member function already defined or declared1>        with1>        [1>            _Elem=char,1>            _Traits=std::char_traits<char>,1>            _Ax=std::allocator<char>,1>            T=const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,1>            UserAllocator=boost::default_user_allocator_new_delete,1>            Mutex=boost::details::pool::default_mutex,1>            NextSize=321>        ]1>        C:\Unilib1\trunk\External\boost/pool/pool_alloc.hpp(202) : see declaration of 'boost::fast_pool_allocator<T,NextSize>::address'1>        with1>        [1>            T=const std::basic_string<char,1>            NextSize=321>        ]1>        c:\Program files\Microsoft Visual Studio 9.0\VC\include\xtree(137) : see reference to class template instantiation 'boost::fast_pool_allocator<T,NextSize>' being compiled1>        with1>        [1>            T=const std::basic_string<char,1>            NextSize=321>        ]1>        c:\Program files\Microsoft Visual Studio 9.0\VC\include\map(78) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled1>        with1>        [1>            _Traits=std::_Tmap_traits<key,boost::fast_pool_allocator<std::pair<key,value >>,false>1>        ]1>        .\main.cpp(9) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled1>        with1>        [1>            _Kty=key,1>            _Ty=value,1>            _Pr=std::less<key>,1>            _Alloc=boost::fast_pool_allocator<std::pair<key,value >>1>        ]
解决方法 这不是VS2008中的一个错误(因为我在此答案的早期编辑中错误地声称). C 03标准要求关联容器的密钥类型(如std :: map)必须是“可分配的”(根据23.1.2“关联容器”中的表69).并且const std :: string不可分配.请注意,C 11标准似乎放宽了这一要求,但新标准不适用于VC 2008以来.

我不清楚是否需要编译器来诊断尝试使用std :: map和不可分配密钥的代码,所以我认为没有人可以声称GCC或VC 2010不正确地接受此代码(我认为它属于未定义代码区域,可以按照您的预期工作,即使不能保证它能正常工作).但很明显,VC 2008拒绝编译它是可以的.

总而言之,我认为VC 2008的库参数化地图键上的分配器地址()函数而不是map的元素仍然是可疑的(如果你感兴趣的话,请参阅这个答案的第一个编辑,但是我不知道)认为自从std :: pair<>之后就有任何真正的错误用于保持map元素的用法总是被设置为使得key部分与整个元素位于同一地址.

总结

以上是内存溢出为你收集整理的c – Boost快速池分配器是否存在函数指针问题?全部内容,希望文章能够帮你解决c – Boost快速池分配器是否存在函数指针问题?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1226012.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存