Hi Bruno,

You can work around this problem by using malloc/free to manage the memory, and then creating and destroying the object yourself.

void *mem = myPool.malloc();
Object *obj = new (mem) Object(args);

Then to destroy:

obj->~Object();
myPool.free(obj);

-Gabe


On Mon, May 5, 2014 at 11:10 PM, Bruno Sanches <bcsanches@gmail.com> wrote:

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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users