Boost logo

Boost Users :

Subject: [Boost-users] Boost pool and move constructor
From: Bruno Sanches (bcsanches_at_[hidden])
Date: 2014-05-05 23:10:31


I am trying to create a object using boost object_pool, but trying to use
the move constructor of the desired object, but on Visual 2013, I am always
getting:

error C2664: 'MyObject::MyObject(const MyObject &)' : cannot convert
argument 1 from 'MyObject (__cdecl &)(void)' to 'MyObject &&'

The error happens because boost pool construct method always assume a const
parameter.

Sample code:

#include <boost/pool/object_pool.hpp>
class MyObject{
    public:
        MyObject():
            m_iData(0)
        {

        }

        MyObject(MyObject &&other):
            m_iData(std::move(other.m_iData))
        {
            other.m_iData = 0;
        }

        MyObject(const MyObject &rhs) = delete;

        MyObject &operator=(const MyObject &rhs) = delete;

    private:
        int m_iData;};
int main(int, char**){
    boost::object_pool<MyObject> pool;

    MyObject obj;

    MyObject *pObj = pool.construct(std::move(obj));}

Is there any way to invoke the move constructor using boost::object_pool?

Thanks
Bruno Sanches
========================
http://www.pontov.com.br



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net