question on map<K, V>::insert(iterator, const value& v)
consider the following program:
#include <cstdlib>
#include <iostream>
#include <map>
#include <utility>
#include <string>
using namespace std;
int main()
{
typedef map<int, string> container_type;
container_type m;
m[0] = "zero";
m[1] = "one";
m[2] = "two";
container_type::iterator it = m.find(0);
++it;
++it;
container_type::iterator res = m.insert(m.end(), make_pair(0,
"Test"));
if (res == m.begin())
cout << "res equals m.begin()" << endl;
else
cout << "res != m.begin()" << endl;
cout << res->second << endl;
return EXIT_SUCCESS;
}
The output of the above program is
res equals m.begin()
zero
My question: From the output, it looks like, the insert() operation
starts searching from the begin() position even though the hint is to
start at m.end() which is passed as the first argument to m.insert().
I am unable to understand this.
What actually does 'passing the iterator as hint' to the insert()
function mean ?
Does it mean, it will start searching ONLY from this hint iterator or
it will search from begin() irrespective of whatever 'hint iterator'
argument is passed(ie, in essence, it is ignored). ? How does this
version of insert() work ?
Kindly explain.
Thanks
V.Subramanian