I faced a situation where I want this kind of function:
MoveOnly createMoveOnly();
Stored here:
std::function<boost::any ()> factory = &createMoveOnly;
This should work, AFAIK, because MoveOnly
is convertible to boost::any
Using boost 1.55 which supports move semantics for boost.any, it does not work. It triggers an error about trying to use the deleted copy constructor for MoveOnly
internally in the holder for boost::any
. But the top-level constructor for Boost.Any is correctly chosen (It uses a templated ValueType && that forwards parameters).
Maybe the problem is in std::function
.
Any hints?
I think that boost::any
requires a copy constructor and assignment operator. The documentation seems to indicate this:
As the emphasis of a value lies in its state not its identity, values can be copied and typically assigned one to another, requiring the explicit or implicit definition of a public copy constructor and public assignment operator. Values typically live within other scopes, i.e. within objects or blocks, rather than on the heap. Values are therefore normally passed around and manipulated directly as variables or through references, but not as pointers that emphasize identity and indirection.
http://www.boost.org/doc/libs/1_55_0/doc/html/any/reference.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With