[Boost-bugs] [Boost C++ Libraries] #7215: string::insert returns a wrong iterator

Subject: [Boost-bugs] [Boost C++ Libraries] #7215: string::insert returns a wrong iterator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-08-09 11:27:53


#7215: string::insert returns a wrong iterator
------------------------------+---------------------------------------------
 Reporter: anonymous | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: container
  Version: Boost 1.50.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 {{{iterator insert(const_iterator p, CharT c)}}} returns an iterator witch
 refers to a character behind the inserted character.
 (Boost 1.50.0, MSVC 9.0)

 {{{
 #include <iostream>
 #include <string>
 #include <boost/container/string.hpp>

 int main()
 {
     std::string ss("1");
     boost::container::string bs("1");

     std::cout << *ss.insert(ss.begin(), '0') << std::endl;
     std::cout << *bs.insert(bs.begin(), '0') << std::endl;

     return 0;
 }


 Output:
 0
 1
 }}}

 In boost/container/string.hpp:

 {{{
 iterator insert(const_iterator p, CharT c)
 {
    size_type new_offset = p - this->priv_addr() + 1;
    this->insert(p, cvalue_iterator(c, 1), cvalue_iterator());
    return this->priv_addr() + new_offset;
 }
 }}}

 I think that "+ 1" is unnecessary.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7215>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC