Boost logo

Boost :

Subject: Re: [boost] [type_traits] optimized std::copy example wrong?
From: John Maddock (boost.regex_at_[hidden])
Date: 2010-04-25 04:30:49


>>> Hi John & co,
>>>
>>> IIRC, std::copy() cannot use memcpy(), since the memory is allowed to
>>> overlap. Therefore it can only use memmove().
>>
>> std::copy() doesn't allow overlapping ranges. -> std::copy_backward()
>
> std::copy() does allow overlapping ranges. It requires the start of the
> range being copied to is not in the range from, but the end can be.
>
> std::copy(it, it + 5, it - 1); is legal. The equivalent memcpy(it, it - 1,
> 5); is not
>
> For exactly this reason, libstdc++ uses memmove rather than memcpy.
> memmove can also be used for copy_backward.

Updated examples and docs in Trunk,

Thanks for catching this, John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk