I have a std::set of unique pointers in a class like std::set<std::unique_ptr<T>> my_set{};
, and I want to write a method that produces a sorted vector of the values pointed to by these unique pointers.
Currently I've got:
auto convert() -> std::vector<T> {
auto vec = std::vector<T>();
for (auto const& element : my_set) {
vec.push_back(element.get());
}
return vec;
}
However, I'm not sure this will produce the required sorting that I want? Would anyone know how I can sort the pointers in the set such that the values pointed to are in increasing order (meaning I can just push each one back onto the set)?
EDIT: to do the question can I use std::transform(my_set.begin(), my_set.end(), vec.begin(), [](std::unique_ptr<T> ptr) -> T { return ptr.get(); });
?