diff options
Diffstat (limited to 'src/util/vector.h')
-rw-r--r-- | src/util/vector.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/util/vector.h b/src/util/vector.h index 40ff73c293..1513562f1b 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -5,7 +5,9 @@ #ifndef BITCOIN_UTIL_VECTOR_H #define BITCOIN_UTIL_VECTOR_H +#include <functional> #include <initializer_list> +#include <optional> #include <type_traits> #include <utility> #include <vector> @@ -67,4 +69,15 @@ inline void ClearShrink(V& v) noexcept V{}.swap(v); } +template<typename V, typename L> +inline std::optional<V> FindFirst(const std::vector<V>& vec, const L fnc) +{ + for (const auto& el : vec) { + if (fnc(el)) { + return el; + } + } + return std::nullopt; +} + #endif // BITCOIN_UTIL_VECTOR_H |