gpt4 book ai didi

c++ - (Boost 库) - boost::container::flat_set with boost::fast_pool_allocator

转载 作者:行者123 更新时间:2023-11-30 04:08:33 32 4
gpt4 key购买 nike

我正在尝试通过 *boost::fast_pool_allocator* 使用 *boost::container::flat_set*。但是,我收到编译错误。非常感谢您的意见和建议。为了突出这个问题,我展示了如下示例。

#include <../include_boost_1_52_0/boost/pool/pool_alloc.hpp>
#include <../include_boost_1_52_0/boost/pool/singleton_pool.hpp>
#include <../include_boost_1_52_0/boost/container/flat_set.hpp>

typedef struct ReceivedQ RecQ;
struct ReceivedQ
{
int m_SequenceNo;
char m_Buffer[500];
ReceivedQ(int seq, char* data, int dataLength)
{
m_SequenceNo=seq;
::memcpy(m_Buffer,(char*)data,dataLength);
}
bool operator< (const RecQ& rhs) const { return m_SequenceNo < rhs.m_SequenceNo; }
};
typedef boost::fast_pool_allocator<RecQ> allocator_RecQ_t;


struct Conn
{
boost::container::flat_set<RecQ, allocator_RecQ_t> m_ReceivedQ;
};

int _tmain(int argc, char* argv[])
{
Conn cn;
RecQ received(1,"test",4);
boost::container::flat_set<RecQ, allocator_RecQ_t>::iterator iter;
cn.m_ReceivedQ.insert(received);
//iter=cn.m_ReceivedQ.find(received);


return 0;
}

如上编译时,我发现以下错误。

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(63): error C2039: '()' : is not a member of 'boost::fast_pool_allocator<T>'
1> with
1> [
1> T=RecQ
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(61) : while compiling class template member function 'bool boost::container::container_detail::flat_tree_value_compare<Compare,Value,KeyOfValue>::operator ()(const Value &,const Value &) const'
1> with
1> [
1> Compare=allocator_RecQ_t,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(789) : see reference to function template instantiation 'bool boost::container::container_detail::flat_tree_value_compare<Compare,Value,KeyOfValue>::operator ()(const Value &,const Value &) const' being compiled
1> with
1> [
1> Compare=allocator_RecQ_t,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(98) : see reference to class template instantiation 'boost::container::container_detail::flat_tree_value_compare<Compare,Value,KeyOfValue>' being compiled
1> with
1> [
1> Compare=allocator_RecQ_t,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(155) : see reference to class template instantiation 'boost::container::container_detail::flat_tree<Key,Value,KeyOfValue,Compare,A>::Data' being compiled
1> with
1> [
1> Key=RecQ,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>,
1> Compare=allocator_RecQ_t,
1> A=std::allocator<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\../include_boost_1_52_0/boost/container/flat_set.hpp(75) : see reference to class template instantiation 'boost::container::container_detail::flat_tree<Key,Value,KeyOfValue,Compare,A>' being compiled
1> with
1> [
1> Key=RecQ,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>,
1> Compare=allocator_RecQ_t,
1> A=std::allocator<RecQ>
1> ]
1> BoostFlatSet.cpp(27) : see reference to class template instantiation 'boost::container::flat_set<Key,Compare>' being compiled
1> with
1> [
1> Key=RecQ,
1> Compare=allocator_RecQ_t
1> ]

同样,如果我注释插入行并取消注释 find() 行,则会出现以下编译错误。

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(698): error C2064: term does not evaluate to a function taking 2 arguments
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include_boost_1_52_0\boost/container/detail/flat_tree.hpp(694) : while compiling class template member function 'boost::container::container_detail::vector_iterator<Pointer> boost::container::container_detail::flat_tree<Key,Value,KeyOfValue,Compare,A>::find(const ReceivedQ &)'
1> with
1> [
1> Pointer=ReceivedQ *,
1> Key=RecQ,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>,
1> Compare=allocator_RecQ_t,
1> A=std::allocator<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\../include_boost_1_52_0/boost/container/flat_set.hpp(619) : see reference to function template instantiation 'boost::container::container_detail::vector_iterator<Pointer> boost::container::container_detail::flat_tree<Key,Value,KeyOfValue,Compare,A>::find(const ReceivedQ &)' being compiled
1> with
1> [
1> Pointer=ReceivedQ *,
1> Key=RecQ,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>,
1> Compare=allocator_RecQ_t,
1> A=std::allocator<RecQ>
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\../include_boost_1_52_0/boost/container/flat_set.hpp(75) : see reference to class template instantiation 'boost::container::container_detail::flat_tree<Key,Value,KeyOfValue,Compare,A>' being compiled
1> with
1> [
1> Key=RecQ,
1> Value=RecQ,
1> KeyOfValue=boost::container::container_detail::identity<RecQ>,
1> Compare=allocator_RecQ_t,
1> A=std::allocator<RecQ>
1> ]
1> BoostFlatSet.cpp(27) : see reference to class template instantiation 'boost::container::flat_set<Key,Compare>' being compiled
1> with
1> [
1> Key=RecQ,
1> Compare=allocator_RecQ_t
1> ]

最佳答案

排序谓词必须是模板参数的一部分:

struct Conn
{
boost::container::flat_set<
RecQ,
std::less<RecQ>,
allocator_RecQ_t> m_ReceivedQ;
};

通过这个小修复,您的代码可以编译,

  • gcc 4.8, boost 1.55,
  • 对比 2013, boost 1.54,
  • 对比 2013 年 11 月 CTP, boost 1.54。

但它不编译,

  • 对比 2013, boost 1.55

因为这个错误:has_member_function_callable_with.hpp compile error on msvc-12.0 - '.select_on_container_copy_construction' must have class/struct/union .

因此您必须同时坚持使用旧版本的 boost。

关于c++ - (Boost 库) - boost::container::flat_set with boost::fast_pool_allocator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21780632/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com