From 07b198f71e925eaa90b62fc27b97b382c122cfb3 Mon Sep 17 00:00:00 2001 From: falsycat Date: Thu, 22 Sep 2022 16:54:19 +0900 Subject: [PATCH] generalize nf7::util::Uniq --- CMakeLists.txt | 1 + common/gui_popup.cc | 2 ++ common/util_algorithm.hh | 20 ++++++++++++++++++++ common/util_string.hh | 9 --------- file/luajit_node.cc | 1 + file/node_network.cc | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 common/util_algorithm.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index c45c68f..a5e9d9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/common/gui_popup.cc b/common/gui_popup.cc index c25d3cb..7f8f262 100644 --- a/common/gui_popup.cc +++ b/common/gui_popup.cc @@ -4,6 +4,8 @@ #include "nf7.hh" +#include "common/util_algorithm.hh" + namespace nf7::gui { diff --git a/common/util_algorithm.hh b/common/util_algorithm.hh new file mode 100644 index 0000000..ffd4f9f --- /dev/null +++ b/common/util_algorithm.hh @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + + +namespace nf7::util { + +template +inline void Uniq(std::vector& 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 diff --git a/common/util_string.hh b/common/util_string.hh index 95b9a4e..b45d9ac 100644 --- a/common/util_string.hh +++ b/common/util_string.hh @@ -35,15 +35,6 @@ inline void JoinAndAppend(std::string& dst, std::span src, ch dst += c; } } -inline void Uniq(std::vector& 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 SplitAndValidate( std::string_view v, diff --git a/file/luajit_node.cc b/file/luajit_node.cc index 596aeb5..a519ba2 100644 --- a/file/luajit_node.cc +++ b/file/luajit_node.cc @@ -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" diff --git a/file/node_network.cc b/file/node_network.cc index 237b88d..b9ceb4a 100644 --- a/file/node_network.cc +++ b/file/node_network.cc @@ -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"