3

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 C2280: 'MyObject::MyObject(const MyObject &)' : attempting to reference a deleted function

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

bcsanches
  • 2,362
  • 21
  • 32

2 Answers2

4

No it isn't supported in the present version of boost. In order to support what you require the boost pool will have to provide the following signature for construction:

template <typename T0> element_type * construct(T0 && a0) { ... }

and since this will be a templated function where both lvalues and rvalues can bind to the argument, the implementation will have to correctly dispatch the construction for both types of values.

You can find the available construction signatures in boost/pool/detail/pool_construct.ipp.

mockinterface
  • 14,452
  • 5
  • 28
  • 49
1

The error message indicates that you are trying to convert a function to an rvalue-reference.

The line MyObject obj(); declares a function called obj, it is not valid to do std::move on a function.

I guess you meant MyObject obj;

M.M
  • 138,810
  • 21
  • 208
  • 365