I spent quite a bit of time implementing movement semantics for my class, but now I am dealing with functions that use it.
Ok, so I have this object with a lot of data on the heap: CLargeOb , for which I implemented move semantics (constructor and operator =). It fits perfectly as follows:
void OtherOb::Func(CLargeOb&& largeOb1, CLargeOb&& largeOb2) { SomeOtherFunc(largeOb1);
However, it is not always possible to allow moving / splitting objects, so I added these two functions:
void OtherOb::Func(const CLargeOb& largeOb1, CLargeOb&& largeOb2) { SomeOtherFunc(largeOb1); SomeOtherFunc(largeOb2); m_largeOb1 = largeOb1; m_largeOb2 = (CLargeOb&&)largeOb2; } void OtherOb::Func(CLargeOb&& largeOb1, const CLargeOb& largeOb2) { SomeOtherFunc(largeOb1); SomeOtherFunc(largeOb2); m_largeOb1 = (CLargeOb&&)largeOb1; m_largeOb2 = largeOb2; }
Although it works, you can already guess that this will become a major pain in ss when I have a function that takes 3 or more of these objects as parameters ... Is there no sensible way to solve this problem with patterns or maybe "perfect call forwarding"?
demorge
source share