I have the following small and easy code:
int main(int argc, char *argv[]) {
std::vector<std::string> in;
std::set<std::string> out;
in.push_back("Hi");
in.push_back("Dear");
in.push_back("Buddy");
for (const auto& item : in) {
*** std::transform(item.begin(),item.end(),item.begin(), ::tolower);
*** out.insert(item);
}
return 0;
}
I'd like to copy all items of in
into out
.
However, with an in-place lowercase conversion, preferrably without an extra temporary variable.
So this is the required content of out
at the end:
hi
dear
buddy
Please note, const auto& item
is fixed, meaning I can't remove the const
requirement (this is part of a bigger library, here is over-simplified for demo).
How should I do this? (If I remove the "const" modifier, it works, but if modifications are not allowed on item
, how can I still insert the item into the set, while also transforming it to lowercase?)