H
Howard Hinnant
I'm writing a short note on lwg issue 233 which concerns the meaning of
the iterator hint when inserting into a multimap or multiset. I would
like to include in my note a survey of current practice. To that end, I
would appreciate it if people could report back what the following
program outputs, and what compiler/library was used to generate the
results.
#include <map>
#include <iostream>
template <class Map>
void
display(const Map& m)
{
for (typename Map::const_iterator i = m.begin(), e = m.end(); i !=
e; ++i)
std::cout << '(' << i->first << ", " << i->second << ") ";
std::cout << '\n';
}
int main()
{
typedef std::multimap<int, std::string> Map;
typedef std:air<int, std::string> value_type;
Map m;
m.insert(value_type(0, "zero"));
m.insert(value_type(1, "one"));
m.insert(value_type(2, "two"));
display(m);
m.insert(m.find(1), value_type(1, "One"));
display(m);
}
To get things started, Metrowerks CodeWarrior (all versions for many
years) outputs:
(0, zero) (1, one) (2, two)
(0, zero) (1, One) (1, one) (2, two)
Thank you for any assistance.
-Howard
the iterator hint when inserting into a multimap or multiset. I would
like to include in my note a survey of current practice. To that end, I
would appreciate it if people could report back what the following
program outputs, and what compiler/library was used to generate the
results.
#include <map>
#include <iostream>
template <class Map>
void
display(const Map& m)
{
for (typename Map::const_iterator i = m.begin(), e = m.end(); i !=
e; ++i)
std::cout << '(' << i->first << ", " << i->second << ") ";
std::cout << '\n';
}
int main()
{
typedef std::multimap<int, std::string> Map;
typedef std:air<int, std::string> value_type;
Map m;
m.insert(value_type(0, "zero"));
m.insert(value_type(1, "one"));
m.insert(value_type(2, "two"));
display(m);
m.insert(m.find(1), value_type(1, "One"));
display(m);
}
To get things started, Metrowerks CodeWarrior (all versions for many
years) outputs:
(0, zero) (1, one) (2, two)
(0, zero) (1, One) (1, one) (2, two)
Thank you for any assistance.
-Howard