generalize nf7::util::Uniq

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

View File

@ -113,6 +113,7 @@ target_sources(nf7
common/squashed_history.hh
common/thread.hh
common/timed_queue.hh
common/util_algorithm.hh
common/util_string.hh
common/value.hh
common/yas_audio.hh

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,

View File

@ -32,6 +32,7 @@
#include "common/node.hh"
#include "common/node_root_lambda.hh"
#include "common/ptr_selector.hh"
#include "common/util_algorithm.hh"
#include "common/util_string.hh"

View File

@ -36,6 +36,7 @@
#include "common/node_link_store.hh"
#include "common/ptr_selector.hh"
#include "common/squashed_history.hh"
#include "common/util_algorithm.hh"
#include "common/yas_imgui.hh"
#include "common/yas_imnodes.hh"
#include "common/yas_nf7.hh"