[ 
https://issues.apache.org/jira/browse/STDCXX-78?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597251#action_12597251
 ] 

Martin Sebor commented on STDCXX-78:
------------------------------------

This might be harder than it seemed. The implementation of the algorithm looks 
like this:

{code}
template <class InputIterator, class OutputIterator>
OutputIterator copy (InputIterator first, InputIterator last, OutputIterator 
res)
{
    _RWSTD_ASSERT_RANGE (first, last);

    for (; !(first == last); ++first,++res)
        *res = *first;
    return res;
}
{code}

The naive solution is to change it like so:

{code}
template <class InputIterator, class OutputIterator>
OutputIterator copy (InputIterator first, InputIterator last, OutputIterator 
res)
{
    _RWSTD_ASSERT_RANGE (first, last);
    _RWSTD_ASSERT_NOT_IN_RANGE (res, first, last);

    for (; !(first == last); ++first,++res)
        *res = *first;
    return res;
}
{code}

But it doesn't work because a) there's no {{\_RWSTD_ASSERT_NOT_IN_RANGE()}} and 
b) if there was (as a parallel to {{\_RWSTD_ASSERT_RANGE}}), it would require 
some changes to the {{\_\_rw_in_range()}} function template to make it work 
with cv-qualified pointers (i.e., in the common case when {{InputIterator=const 
T*}} and {{OutputIterator=T*}}).

All this might be worth doing if it can be used in other algorithms besides 
{{std::copy()}}. Otherwise it seems like a lot of effort and overhead for just 
one algorithm.

> std::copy() doesn't detect overlapping ranges
> ---------------------------------------------
>
>                 Key: STDCXX-78
>                 URL: https://issues.apache.org/jira/browse/STDCXX-78
>             Project: C++ Standard Library
>          Issue Type: Improvement
>          Components: 25. Algorithms
>    Affects Versions: 4.1.2
>         Environment: all
>            Reporter: Martin Sebor
>            Priority: Minor
>
> Quoting from the response to the following post:
> http://mail-archives.apache.org/mod_mbox/incubator-stdcxx-dev/200511.mbox/[EMAIL
>  PROTECTED]
> -------- Original Message --------
> Subject: Re: questions about the lib.alg.copy test
> Date: Wed, 30 Nov 2005 17:33:10 -0700
> From: Martin Sebor <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> References: <[EMAIL PROTECTED]>
> Anton Pevtsov wrote:
> [...]
> > 
> > 2. The copy algorithm can work in case when the destination range
> > overlaps the source range (of course, first position of the source range
> > should not be contained in the destination range). Current version
> > doesn't contain special test for this case, but I prefer to have such
> > test. What do you think about it?
> The requirement in 25.2.1, p3 is that "result shall not be in the
> range [first, last)." The algorithm doesn't detect violations of
> this requirement but it probably should in debug mode. This would
> be a useful enhancement in general. Let me file an enhancement for
> it.
> Martin

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to