generalize nf7::util::Uniq
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "nf7.hh"
|
||||
|
||||
#include "common/util_algorithm.hh"
|
||||
|
||||
|
||||
namespace nf7::gui {
|
||||
|
||||
|
20
common/util_algorithm.hh
Normal file
20
common/util_algorithm.hh
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace nf7::util {
|
||||
|
||||
template <typename T>
|
||||
inline void Uniq(std::vector<T>& v) noexcept {
|
||||
for (auto itr = v.begin(); itr < v.end();) {
|
||||
if (v.end() != std::find(itr+1, v.end(), *itr)) {
|
||||
itr = v.erase(itr);
|
||||
} else {
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace nf7::util
|
@@ -35,15 +35,6 @@ inline void JoinAndAppend(std::string& dst, std::span<const std::string> src, ch
|
||||
dst += c;
|
||||
}
|
||||
}
|
||||
inline void Uniq(std::vector<std::string>& v) noexcept {
|
||||
for (auto itr = v.begin(); itr < v.end();) {
|
||||
if (v.end() != std::find(itr+1, v.end(), *itr)) {
|
||||
itr = v.erase(itr);
|
||||
} else {
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline std::optional<std::string_view> SplitAndValidate(
|
||||
std::string_view v,
|
||||
|
Reference in New Issue
Block a user