Я пытаюсь использовать *boost::container::flat_set*
с использованием *boost::fast_pool_allocator*
, Тем не менее, я получаю ошибку компиляции. Ваши комментарии и предложения очень ценятся.
Чтобы подчеркнуть проблему, я показываю пример, как показано ниже.
#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;
};
С этим небольшим исправлением ваш код компилируется с
Но это не компилируется с
из-за этой ошибки: Ошибка компиляции has_member_function_callable_with.hpp в msvc-12.0 — «.select_on_container_copy_construction» должна иметь класс / struct / union.
Таким образом, вам придется придерживаться более старой версии Boost.
Других решений пока нет …