Is there a way to enable the move construct and prevent the creation and assignment of a copy. I can think of several classes with file pointers and buffer pointers (resource handles, etc.) that will benefit from copying and copy destination.
I am using VC2010 and GCC 4.5.2. I know that I would have to declare empty private assignments and copy constructors in the headers of the VC2010 class, and as far as I know, GCC will allow any signature to be deleted after the method does the same.
If anyone has a good example of such a skeletal class, and I would be very grateful for its advantages. thanks in advance John
Here is an example of a class for which I would like to allow moves, but I would also like to prevent direct sorting. Is it just a matter of creating a copy constructor and operator = private?
class LoadLumScanner_v8002 : public ILoadLumScanner { public: // default constructor LoadLumScanner_v8002(); // copy constructor LoadLumScanner_v8002(const LoadLumScanner_v8002& rhs); // move constructor LoadLumScanner_v8002(LoadLumScanner_v8002&& rhs); // non-throwing copy-and-swap idiom unified assignment inline LoadLumScanner_v8002& operator=(LoadLumScanner_v8002 rhs) { rhs.swap(*this); return *this; } // non-throwing-swap idiom inline void swap(LoadLumScanner_v8002& rhs) throw() { // enable ADL (not necessary in our case, but good practice) using std::swap; // swap base members // ... // swap members swap(mValidatedOk, rhs.mValidatedOk); swap(mFile, rhs.mFile); swap(mPartNo, rhs.mPartNo); swap(mMediaSequenceNo, rhs.mMediaSequenceNo); swap(mMaxMediaSequenceNo, rhs.mMaxMediaSequenceNo); swap(mLoadListOffset, rhs.mLoadListOffset); swap(mFirstLoadOffset, rhs.mFirstLoadOffset); swap(mLoadCount, rhs.mLoadCount); swap(mLoadIndex, rhs.mLoadIndex); swap(mLoadMediaSequenceNo, rhs.mLoadMediaSequenceNo); swap(mLoadPartNo, rhs.mLoadPartNo); swap(mLoadFilePath, rhs.mLoadFilePath); } // destructor virtual ~LoadLumScanner_v8002(); }
source share