Opened 10 years ago
Closed 10 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: |
Description
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.
Note:
See TracTickets
for help on using tickets.

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