generalize nf7::util::Uniq

This commit is contained in:
2022-09-22 16:54:19 +09:00
parent b004723464
commit 07b198f71e
6 changed files with 25 additions and 9 deletions

View File

@@ -4,6 +4,8 @@
#include "nf7.hh"
#include "common/util_algorithm.hh"
namespace nf7::gui {

20
common/util_algorithm.hh Normal file
View 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

View File

@@ -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,