container: allow sort_and_unique to have a comparator

This commit is contained in:
Justin Viiret
2017-02-16 11:03:05 +11:00
committed by Matthew Barr
parent cea8f452f2
commit dc50ab291b
2 changed files with 12 additions and 17 deletions

View File

@@ -90,9 +90,9 @@ auto make_vector_from(const std::pair<It, It> &range)
}
/** \brief Sort a sequence container and remove duplicates. */
template <typename C>
void sort_and_unique(C &container) {
std::sort(std::begin(container), std::end(container));
template <typename C, typename Compare = std::less<typename C::value_type>>
void sort_and_unique(C &container, Compare comp = Compare()) {
std::sort(std::begin(container), std::end(container), comp);
container.erase(std::unique(std::begin(container), std::end(container)),
std::end(container));
}