
Hi all, boost::noncopyable interferes with the implicit generation of move construction and move assignment, so I was wondering if anybody had any thoughts on something like this: class noncopyable { protected: noncopyable() = default; noncopyable(noncopyable&&) = default; noncopyable& operator=(noncopyable&&) = default; noncopyable(noncopyable const&) = delete; noncopyable& operator=(noncopyable const&) = delete; }; Which would replace the existing technique when C++11 support is on. I guess it could be argued that non copyable should imply non moveable. However, you won't hear me defending that position; plenty of thought went into move semantics with the defaults chosen to have sa[f|n]e behaviour. The derived class will still be subject to that criteria, I'm just trying to prevent noncopyable from artificially inhibiting move semantics. Would anybody want nonmovable? nonmoveable? Any thoughts / comments / omissions gratefully received. Ben

On Friday, July 06, 2012 03:26 PM, Ben Pope wrote:
boost::noncopyable interferes with the implicit generation of move
Hmm, I see this was discussed before: http://lists.boost.org/boost-users/2011/07/69621.php Which I failed to find first time I searched. There is still the case where I want to prevent copying (but allow moving), and boost::noncopyable was what I used before move semantics. I guess we could have: class moveonly { protected: moveonly() = default; moveonly(moveonly&&) = default; moveonly& operator=(moveonly&&) = default; // implicit // moveonly(moveonly const&) = delete; // moveonly& operator=(moveonly const&) = delete; }; So that there is an expressive and concise form of "I want this to have default move semantics without being copyable". Ben

Hmm, I see this was discussed before: http://lists.boost.org/boost-users/2011/07/69621.php
Which I failed to find first time I searched.
There is still the case where I want to prevent copying (but allow moving), and boost::noncopyable was what I used before move semantics.
I guess we could have:
class moveonly { protected: moveonly() = default; moveonly(moveonly&&) = default; moveonly& operator=(moveonly&&) = default; // implicit // moveonly(moveonly const&) = delete; // moveonly& operator=(moveonly const&) = delete; };
So that there is an expressive and concise form of "I want this to have default move semantics without being copyable".
I believe the conclusion of that thread was to simply declare a defaulted move constructor in your derived class. Its presence will inhibit the generation of a copy constructor (on conformant compilers) and so your class will be moveable but not copyable. Regards, Nate
participants (2)
-
Ben Pope
-
Nathan Ridge