Is it in poor taste to use std::memcpy in a highly-OO C++ application? That is, in the same way that the use of realloc / free / malloc / calloc is frowned upon?
Printable View
Is it in poor taste to use std::memcpy in a highly-OO C++ application? That is, in the same way that the use of realloc / free / malloc / calloc is frowned upon?
That's a loaded question. memcpy can only be used on POD types. If you know the data that you want to copy is of POD type then you can use memcpy, if not then don't as it will constitute undefined behaviour.
As an aside, under some circumstances, a compiler may convert a "copy by iteration" into a memcpy if it can figure out that the data held in both source and destination is both contiguous and POD.
There's not much reason to prefer memcpy over std::copy in C++, and the latter handles a larger number of cases correctly.
Agreed, and, the compiler can make it just as fast for POD types.