I am using the below code for conversion:
std::set<ObjectType> s(v.begin(), v.end());
However, I need to keep the order of the vector elements. How can I do this?
You can't if the vector is not ordered. A std::set keeps it contents in either an ascending or descending order.
If the vector is ordered then you just need to set the comparison function of the std::set to whatever was used to order the vector.
You may want to see: How to remove duplicates from unsorted std::vector while keeping the original ordering using algorithms?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With