This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::packaged_task trunk problem


On 3 November 2011 13:13, Lars Gullik Bjønnes wrote:
>
> I tried to put the packaged_task into a
> std::vector<std::function<void()>>, that fails.
> I had to create a wrapper around the packaged_task to make it work.

Yes, std::function can only hold CopyConstructible objects:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3313.html#1287

A copy constructor is required even if it will actually never be
needed. In that defect report I said it would be a terrible idea for
std::function to throw if you tried to copy it when it contained a
non-copyable target object, which I think is true for std::function in
general, but that doesn't stop you providing that behaviour via a
wrapper if you want it.

Something like ...

template<typename Moveable>
struct PretendToBeCopyable
{
  explicit PretendToBeCopyable(Moveable&& m) : m(m) {}
  PretendToBeCopyable(PretendToBeCopyable&&) = default;
  PretendToBeCopyable(const PretendToBeCopyable&)
  { throw std::logic_error("No way, Jose"); }
  // ...
  private:
    Moveable m;
};


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]