473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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, stringcontainer_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
Jun 27 '08 #1
0 1373

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pentium77 | last post by:
Basically I have a situation where I need to update changes occuring in one Text field of a table into another text field located in another table. In addition both the tables are located in...
4
by: Richard Cornford | last post by:
For the last couple of months I have been trying to get the next round of updates to the FAQ underway and been being thwarted by a heavy workload (the project I am working on has to be finished an...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.