How about this?
std::transform(myMap.begin(), myMap.end(), std::inserter(mySet, mySet.begin()),
[](const std::pair<int, double*>& key_value) {
return key_value.second;
});
This only copies pointers. If you need a deep copy, you will need to do:
std::transform(myMap.begin(), myMap.end(), std::inserter(mySet, mySet.begin()),
[](const std::pair<int, double*>& key_value) {
return new double(*key_value.second);
});
BTW, the code uses lambda functions (available only with C ++ 11). If you cannot use C ++ 11, you can use a function object .
source
share