actual C++ interview question

One quick note on the following:
the copy ctor should not be used, because it will be less efficient than `std::memmove`

In general: I don't think it necessarily follows. An actual (non-inlined) function call to a library function `std::memmove` wouldn't be exactly free, either (on a side-note: `std::memcpy` makes the no-overlapping assumption and should be at least as fast). I presume the person preferring it would assume that it gets inlined by the compiler. But then, so is the body of the copy ctor. And one could argue that if you really want efficiency, you may want to consider using SIMD intrinsics. But, then again, your implementations `std::memmove/memcpy` may be vectorized, too.

Overall, then, it all boils down to the actual optimizations performed by your compiler; I'd prefer to look at the generated assembly code and profile.
 
Back
Top