diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-01 16:01:04 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-01 16:01:04 +0200 |
commit | 7307815e99a79dac42f2a9c06b0fe6171ea11ba0 (patch) | |
tree | ad41ee819dc87fc2653caf720fa7d1df30c0caeb /src/util/algorithm_impl.hpp | |
parent | 2bff8c999edde11270ecaf6fbd2d24f54d0e360b (diff) |
refactor: use ranges
Diffstat (limited to 'src/util/algorithm_impl.hpp')
-rw-r--r-- | src/util/algorithm_impl.hpp | 67 |
1 files changed, 0 insertions, 67 deletions
diff --git a/src/util/algorithm_impl.hpp b/src/util/algorithm_impl.hpp deleted file mode 100644 index d7c5e3b..0000000 --- a/src/util/algorithm_impl.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#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 Predicate> -requires Container<ContainerType> && - std::predicate<Predicate, typename ContainerType::value_type> -constexpr auto -container_find(const ContainerType &container, Predicate predicate) noexcept -> - typename ContainerType::const_iterator -{ - return std::find_if(container.begin(), container.end(), predicate); -} - -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; -} |