Frage

I am trying to use *boost::container::flat_set* using the *boost::fast_pool_allocator*. However, I am getting the compilation error. Your comments and suggestions are very much appreciated. To highlight the issue, I am showing the example as below.

#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;
}

While compiling as above, I find the following error.

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>          ]

Similarly, if I comment the insert line and un-comment the find() line then I get the following compilation error.

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>          ]
War es hilfreich?

Lösung

The ordering predicate must be part of the templated arguments:

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

With this small fix, your code compiles with,

  • gcc 4.8, boost 1.55,
  • VS 2013, boost 1.54,
  • VS 2013 Nov CTP, boost 1.54.

But it doesn't compile with,

  • VS 2013, boost 1.55

because of this bug: has_member_function_callable_with.hpp compile error on msvc-12.0 - '.select_on_container_copy_construction' must have class/struct/union.

So you will have to stick to an older version of boost in the meanwhile.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top