B
brzrkr0
A portion of my program needs to initialize a std::set<int> to have
all the keys in a std::map<int, double>. The code I've pasted below
works, but I'm wondering if there's a more elegant way to do it (an
STL algorithm, maybe?). I'm a bit of an STL noob, so any advice
people can give would be greatly appreciated.
typedef std::map<int, double> intDoubleMap;
typedef std::set<int> intSet;
intSet v;
// map is an intDoubleMap* and has been initialized with some values
for (intDoubleMap::const_iterator it = map->begin();
it != map->end();
it++) {
int i = it->first;
v.insert(i);
}
Thanks,
Casey
all the keys in a std::map<int, double>. The code I've pasted below
works, but I'm wondering if there's a more elegant way to do it (an
STL algorithm, maybe?). I'm a bit of an STL noob, so any advice
people can give would be greatly appreciated.
typedef std::map<int, double> intDoubleMap;
typedef std::set<int> intSet;
intSet v;
// map is an intDoubleMap* and has been initialized with some values
for (intDoubleMap::const_iterator it = map->begin();
it != map->end();
it++) {
int i = it->first;
v.insert(i);
}
Thanks,
Casey