| | |
| | |
| |
|
| | #pragma once |
| |
|
| | #include <algorithm> |
| | #include <functional> |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | namespace Common { |
| |
|
| | template <class ForwardIt, class T, class Compare = std::less<>> |
| | [[nodiscard]] ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, |
| | Compare comp = {}) { |
| | |
| | |
| | |
| |
|
| | first = std::lower_bound(first, last, value, comp); |
| | return first != last && !comp(value, *first) ? first : last; |
| | } |
| |
|
| | template <typename T, typename Func, typename... Args> |
| | T FoldRight(T initial_value, Func&& func, Args&&... args) { |
| | T value{initial_value}; |
| | const auto high_func = [&value, &func]<typename U>(U x) { value = func(value, x); }; |
| | (std::invoke(high_func, std::forward<Args>(args)), ...); |
| | return value; |
| | } |
| |
|
| | } |
| |
|