4
class MoveOnlyOperation
{
public:
    MoveOnlyOperation()                         = default;
    MoveOnlyOperation(const MoveOnlyOperation&) = delete;
    MoveOnlyOperation(MoveOnlyOperation&&)      = default;

    int operator()()
    {
        return 0;
    }
};

I want to wrap an object instance inside a packaged_task like this:

std::packaged_task<void()> task(MoveOnlyOperation{}); 

I get "error C2280: 'MoveOnlyOperation::MoveOnlyOperation(const MoveOnlyOperation &)': attempting to reference a deleted function"

The documentation for C++ 11 says one can perfect forward the instance inside the packaged_task though. I also don't have issues with clang.

It there something implementation defined about how packaged_task should be implemented or a bug in VS 2015 (and possibly later because I get same issue with http://rextester.com/WBEH22233)

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Ghita
  • 4,465
  • 4
  • 42
  • 69
  • Not all versions of VS support all the C++11 features. See https://msdn.microsoft.com/en-us/library/hh567368.aspx. – R Sahu Feb 26 '18 at 19:33
  • Yes, but this seems to be a library bug – Ghita Feb 26 '18 at 20:28
  • I hope somebody with more knowledgeable than me will be able to help you out. – R Sahu Feb 26 '18 at 21:04
  • This looks like a library bug to me. MSVC is storing the callable in `std::function`, which imposes the copyable requirement. I don't see anything in the standard that says the callable needs to be copy constructible. – Praetorian Feb 26 '18 at 23:36

2 Answers2

4

This is a known bug in MSVC's packaged_task implementation. They're storing the callable within std::function, which requires that the argument be copy-constructible.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
0

As @Praetorian said, it's MSVC's known bug.

It caused trouble to me, to put lambda function with moving captured std::unique_ptr, into std::packaged_func. And I'm doing Linux / Windows cross platform, note it works perfectly well in Linux system.

Use its original source: boost::fibers::packaged_task fixed the problem for me.

Val
  • 21,938
  • 10
  • 68
  • 86