I have a C function to swap an arbitrary number of bytes:
void my_swap(void* a, void* b, long n);
Not possible because std::swap must know exactly the type of the passed variables.
There may be several reasons as to why your
my_swap is slower than
void*variables point to an "unaliased" memory (in particular, that the operation you're going to do with the pointed memory will not reach the area of one that may overlap with the other). Compilers are not allowed to generate fast code for that cases because in case of overlaps it will result in wrong data operation.
This is why it is impossible to write an implementation of
my_swap that would be that fast as
std::swap because this
void* as argument is the reason.