1323. basic_string::replace should use const_iterator

Section: 27.4.3.7.6 [string.replace] Status: C++11 Submitter: Daniel Krügler Opened: 2010-02-19 Last modified: 2016-11-12

Priority: Not Prioritized

View all other issues in [string.replace].

View all issues with C++11 status.

Discussion:

In contrast to all library usages of purely positional iterator values several overloads of std::basic_string::replace still use iterator instead of const_iterator arguments. The paper N3021 quite nicely visualizes the purely positional responsibilities of the function arguments.

This should be fixed to make the library consistent, the proposed changes are quite mechanic.

[ Post-Rapperswil: ]

Moved to Tentatively Ready after 5 positive votes on c++std-lib.

[ Adopted at 2010-11 Batavia ]

Proposed resolution:

  1. In 27.4.3 [basic.string], class template basic_string synopsis change as indicated:

    // 21.4.6 modifiers:
    ...
    basic_string& replace(const_iterator i1, const_iterator i2,
                          const basic_string& str);
    basic_string& replace(const_iterator i1, const_iterator i2,
                          const charT* s, size_type n);
    basic_string& replace(const_iterator i1, const_iterator i2,
                          const charT* s);
    basic_string& replace(const_iterator i1, const_iterator i2,
                          size_type n, charT c);
    template<class InputIterator>
      basic_string& replace(const_iterator i1, const_iterator i2,
                            InputIterator j1, InputIterator j2);
    basic_string& replace(const_iterator, const_iterator,
                          initializer_list<charT>);
    
  2. In 27.4.3.7.6 [string.replace] before p.18, change the following signatures as indicated:

    basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
    
  3. In 27.4.3.7.6 [string.replace] before p.21, change the following signatures as indicated:

    basic_string&
      replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
    
  4. In 27.4.3.7.6 [string.replace] before p.24, change the following signatures as indicated:

    basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
    
  5. In 27.4.3.7.6 [string.replace] before p.27, change the following signatures as indicated:

    basic_string& replace(const_iterator i1, const_iterator i2, size_type n,
                          charT c);
    
  6. In 27.4.3.7.6 [string.replace] before p.30, change the following signatures as indicated:

    template<class InputIterator>
      basic_string& replace(const_iterator i1, const_iterator i2,
                            InputIterator j1, InputIterator j2);
    
  7. In 27.4.3.7.6 [string.replace] before p.33, change the following signatures as indicated:

    basic_string& replace(const_iterator i1, const_iterator i2,
                          initializer_list<charT> il);