MyraMath
sortunique.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_UTILITY_SORTUNIQUE_H
7 #define MYRAMATH_UTILITY_SORTUNIQUE_H
8 
14 #include <vector>
15 #include <algorithm>
16 
17 namespace myra {
18 
20 template<class T> void sortunique(std::vector<T>& v)
21  {
22  std::sort(v.begin(), v.end());
23  typedef typename std::vector<T>::iterator Iterator;
24  Iterator i = std::unique(v.begin(), v.end());
25  size_t d = std::distance(v.begin(),i);
26  v.resize(d);
27  }
28 
29 } // namespace myra
30 
31 #endif
void sortunique(std::vector< T > &v)
Reduces a std::vector to its unique entries, and sorts it.
Definition: sortunique.h:20
Definition: syntax.dox:1