aboutsummaryrefslogtreecommitdiff
path: root/src/util/algorithm.tpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-02 19:51:54 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:57:00 +0200
commiteecf4b1e666211a13afa56f93477c55e8fd01621 (patch)
tree410510d6e058995174d5a5b0f535fb457a0c3542 /src/util/algorithm.tpp
parent87f55120f96d0f4f80b497dc9006d89df2dda125 (diff)
feat: implement game of lifev0.1.0
Diffstat (limited to 'src/util/algorithm.tpp')
-rw-r--r--src/util/algorithm.tpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/util/algorithm.tpp b/src/util/algorithm.tpp
new file mode 100644
index 0000000..00269ed
--- /dev/null
+++ b/src/util/algorithm.tpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include "algorithm.hpp"
+
+#include <algorithm>
+
+template <typename ContainerType, typename Value>
+requires Container<ContainerType>
+constexpr auto container_find(const ContainerType &container, const Value &value) noexcept
+ -> typename ContainerType::const_iterator
+{
+ return std::find(container.begin(), container.end(), value);
+}
+
+template <typename ContainerType, typename Value>
+requires Container<ContainerType>
+constexpr auto container_has(const ContainerType &container, const Value &value) noexcept
+ -> bool
+{
+ return container_find(container, value) != container.end();
+}
+
+template <typename ContainerType, typename Predicate>
+requires Container<ContainerType> && HasPushBack<ContainerType> &&
+ std::predicate<Predicate, typename ContainerType::value_type>
+constexpr auto
+container_filter(const ContainerType &container, Predicate predicate) noexcept
+ -> ContainerType
+{
+ ContainerType filtered_container;
+
+ std::copy_if(
+ std::begin(container),
+ std::end(container),
+ std::back_inserter(filtered_container),
+ predicate);
+
+ return filtered_container;
+}
+
+template <typename ContainerType, typename Predicate>
+requires Container<ContainerType> &&
+ std::predicate<Predicate, typename ContainerType::value_type>
+constexpr auto
+container_filter(const ContainerType &container, Predicate predicate) noexcept
+ -> ContainerType
+{
+ ContainerType filtered_container;
+
+ std::copy_if(
+ std::begin(container),
+ std::end(container),
+ std::inserter(filtered_container, filtered_container.begin()),
+ predicate);
+
+ return filtered_container;
+}