(Boost Library) - 使用boost :: fast_pool_allocator的boost :: container :: flat_set

时间:2014-02-14 13:26:04

标签: c++ boost pool

我正在尝试使用*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>          ]

1 个答案:

答案 0 :(得分:2)

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

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

通过这个小修补程序,您的代码可以编译,

  • gcc 4.8,boost 1.55,
  • VS 2013,提升1.54,
  • VS 2013年11月CTP,提升1.54。

但它不能编译,

  • VS 2013,提升1.55

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

所以你必须坚持使用旧版本的增强版。