Talk:cpp/algorithm/copy
From cppreference.com
Does std::copy/std::copy_if take into account if the output range is empty or smaller than the input range? The two sample implementations certainly do not. Azrael (talk) 22:49, 18 November 2015 (PST)
- No. It's the caller's responsibility. The output doesn't even have to be a range - e.g., an output-only iterator like std::ostream_iterator. T. Canens (talk) 23:40, 18 November 2015 (PST)
The note mentions that for TriviallyCopyable value types, std::copy
uses bulk copy functions like std::memmove. My problem here is that std::copy
does not check for overlapping ranges whereas std::memmove does. Shouldn't this have been std::memcpy instead? — Preceding unsigned comment added by Hgsilverman (talk • contribs)
- No. memcpy requires no overlap whatsoever. The non-ExecutionPolicy std::copy permits overlap in one direction (but not the other). T. Canens (talk) 23:18, 9 December 2017 (PST)
- Thanks, for the answer, after reviewing the std::memcpy found out that the behavior of std::memcpy on overlapping objects is undefined, so std::memcpy is not appropriate for this use. Hgsilverman (talk) 23:49, 9 December 2017 (PST)