Skip to content
Snippets Groups Projects
Commit a2035f05 authored by Max Bonomi's avatar Max Bonomi
Browse files

Add a method to Tools to remove duplicates from a STL vector

parent 41dedd14
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,9 @@ public: ...@@ -60,6 +60,9 @@ public:
static void interpretRanges(std::vector<std::string>&); static void interpretRanges(std::vector<std::string>&);
/// Switching function /// Switching function
static double switchingFunc(const double, const int, const int, const double, const double, double *); static double switchingFunc(const double, const int, const int, const double, const double, double *);
/// Remove duplicates from a vector of types <T>
template <typename T>
static void removeDuplicates(std::vector<T>& vec);
}; };
template <class T> template <class T>
...@@ -85,6 +88,13 @@ bool Tools::parseVector(std::vector<std::string>&line,const std::string&key,std: ...@@ -85,6 +88,13 @@ bool Tools::parseVector(std::vector<std::string>&line,const std::string&key,std:
return true; return true;
} }
template<typename T>
void Tools::removeDuplicates(std::vector<T>& vec)
{
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
inline inline
bool Tools::parseFlag(std::vector<std::string>&line,const std::string&key,bool&val){ bool Tools::parseFlag(std::vector<std::string>&line,const std::string&key,bool&val){
std::string s; std::string s;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment