The minimal change is just to group the trivially-initialized members together, so you can memcpy
them easily:
struct myStruct{
struct {
int a,b,c,d;
double e,f,g,h;
std::complex<double> value1,value2;
} pod;
std::unique_ptr<Calculator> calc;
myStruct(){}
myStruct(const myStruct &)=delete;
myStruct(myStruct && other);
};
myStruct::myStruct(myStruct && other){
std::memcpy(&pod,&other.pod,sizeof(pod));
other.calc.release();
calc->rebind(this);
}
Note std::complex
is a literal type, which should be safe to put into the pod member. If you add any other member objects of class type, you'll have to verify yourself that they're safe to memcpy.
A better implementation would, as Jonathan Wakely pointed out, sidestep the concerns about pod and non-pod (or literal, and trivially-initialized) members. Instead, group members by whether you want them copied or moved:
struct myStruct{
struct {
int a,b,c,d;
double e,f,g,h;
std::complex<double> value1,value2;
} val;
std::unique_ptr<Calculator> calc;
myStruct(){}
myStruct(const myStruct &)=delete;
myStruct(myStruct && other);
};
myStruct::myStruct(myStruct && other)
: val(other.val) // copy the value types
, calc(std::move(other.calc)) // and move the reference types
{
calc->rebind(this);
}