Modify

Ticket #7215 (closed Bugs: fixed)

Opened 21 months ago

Last modified 20 months ago

string::insert returns a wrong iterator

Reported by: anonymous Owned by: igaztanaga
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.

Attachments

Change History

comment:1 Changed 20 months ago by igaztanaga

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.