From eecf4b1e666211a13afa56f93477c55e8fd01621 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Jun 2022 19:51:54 +0200 Subject: feat: implement game of life --- src/util/algorithm.tpp | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/util/algorithm.tpp (limited to 'src/util/algorithm.tpp') 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 + +template +requires Container +constexpr auto container_find(const ContainerType &container, const Value &value) noexcept + -> typename ContainerType::const_iterator +{ + return std::find(container.begin(), container.end(), value); +} + +template +requires Container +constexpr auto container_has(const ContainerType &container, const Value &value) noexcept + -> bool +{ + return container_find(container, value) != container.end(); +} + +template +requires Container && HasPushBack && + std::predicate +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 +requires Container && + std::predicate +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; +} -- cgit v1.2.3-18-g5258