Suppose I have a vector v{1,2,3,4,5}
If I want to insert it to another vector (say v1), I can do something like this;
std::transform(v.begin(), v.end(), v1.begin(), [](const auto& val) { return val+1; });
But If I want to insert all values to a set/unordered_set, just specifying the begin()
iterator won’t work
I have to use std::inserter()
as following
std::transform(v.begin(), v.end(), std::inserter(my_set, my_set.begin()), [](const auto& val) { return val+1;});
Could you any one help me, what I’m missing? Shouldn’t std::transform
also insert val in set as we have its begin()
iteratior? [I have also initialized the set with enough size]