Boost logo

Boost :

Subject: Re: [boost] [type_traits] optimized std::copy example wrong?
From: Christopher Jefferson (chris_at_[hidden])
Date: 2010-04-24 16:48:49


On 24 Apr 2010, at 16:55, strasser_at_[hidden] wrote:

> Zitat von Thorsten Ottosen <nesotto_at_[hidden]>:
>
>> 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.

Chris


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