This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD Concepts status.

1087. Incorrect OutputIterator concept requirements for replace algorithms

Section: 27.7.5 [alg.replace] Status: NAD Concepts Submitter: Howard Hinnant Opened: 2009-03-22 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [alg.replace].

View all issues with NAD Concepts status.

Discussion:

Addresses UK 301 [CD1]

replace and replace_if have the requirement: OutputIterator<Iter, Iter::reference> Which implies they need to copy some values in the range the algorithm is iterating over. This is not however the case, the only thing that happens is const T&s might be copied over existing elements (hence the OutputIterator<Iter, const T&>.

Remove OutputIterator<Iter, Iter::reference> from replace and replace_if.

[ Summit: ]

We agree. To be handled by Howard.

Proposed resolution:

Change in [algorithms.syn] and 27.7.5 [alg.replace]:

template<ForwardIterator Iter, class T> 
  requires OutputIterator<Iter, Iter::reference> 
        && OutputIterator<Iter, const T&> 
        && HasEqualTo<Iter::value_type, T> 
  void replace(Iter first, Iter last, 
               const T& old_value, const T& new_value); 

template<ForwardIterator Iter, Predicate<auto, Iter::value_type> Pred, class T> 
  requires OutputIterator<Iter, Iter::reference> 
        && OutputIterator<Iter, const T&> 
        && CopyConstructible<Pred> 
  void replace_if(Iter first, Iter last,
                  Pred pred, const T& new_value);