What are disadvantages of using macro as interface of all move semantics?
I have recently read about syntax of move-related function inside a class (http://stackoverflow.com/a/4782927/ ), and in my opinion, it is quite tedious and repetitive :-
C(C&&) = default; // Move constructor
C& operator=(C&&) & = default; // Move assignment operator
It is dirtier if I want to customize both move-assignment and move-constructor with the same implementation. (same problem as Copy constructor and = operator overload in C++: is a common function possible?)
Therefore, I decide to create a macro (swap-like function) to make everything concise in a single place.
#define MACRO_MOVE(C) \
C& operator=(C&& that) & { \
moveHack(this,&that); return *this; \
} \
C(C&& that){ \
moveHack(this,&that); \
} \
static void moveHack(C* dst,C* src)
Here is the usage :-
class X{
int data=42;
MACRO_MOVE(X){
dst->data=src->data;
src->data=0;
}
};
However, I haven't seen anyone do like this before.
Are there any issues I should concern?
Are there any specific disadvantages of this approach?