Opened 5 years ago

Closed 5 years ago

#7215 closed Bugs (fixed)

string::insert returns a wrong iterator

Reported by: anonymous Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.50.0 Severity: Problem
Keywords: Cc:


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;


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.

Attachments (0)

Change History (1)

comment:1 Changed 5 years ago by Ion Gaztañaga

Resolution: fixed
Status: newclosed

Thanks for the report. Fixed in trunk t revision: 80174

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ion Gaztañaga.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.