I have a code:
std::vector<int> vector = {1, 3, 5, 7, 9};
using my_type = std::pair<int, int>;
std::map<int, boost::optional<my_type>> map;
for (const auto &i : vector) {
map[i] = boost::none;
}
const my_type val = {1, 5};
std::transform(vector.cbegin(),
vector.cend(),
std::inserter(map, map.end()),
[&val](const int &i) {
return std::make_pair(i, boost::optional<my_type>(val));
});
Everything works fine, but std::transformdoes not change the map, replacing the values with an existing key, so I have the following:
{
{1, boost::none},
{3, boost::none},
{5, boost::none},
{7, boost::none},
{9, boost::none},
}
Is it possible to make it work as the next simple range?
for (const auto &i : vector) {
map[i] = boost::optional<my_type>(val));
}
PS I know how it works std::inserterand std::map::insert, just curious, how can I change the transformation to change the values.