diff --git a/source/mijin/util/iterators.hpp b/source/mijin/util/iterators.hpp index 090bde8..5fca076 100644 --- a/source/mijin/util/iterators.hpp +++ b/source/mijin/util/iterators.hpp @@ -4,6 +4,8 @@ #define MIJIN_UTIL_ITERATORS_HPP_INCLUDED 1 #include +#include +#include #include #include @@ -26,8 +28,25 @@ struct RangeRef return std::end(range); } }; + template -concept RangeAdapterType = std::is_base_of_v; +struct is_range_adapter_type : std::false_type {}; + +template requires std::is_base_of_v +struct is_range_adapter_type : std::true_type {}; + +// allow passing in spans and string_views by value +template +struct is_range_adapter_type> : std::true_type {}; + +template +struct is_range_adapter_type> : std::true_type {}; + +template +concept RangeAdapterType = is_range_adapter_type::value; + +static_assert(!is_range_adapter_type>::value); +static_assert(is_range_adapter_type::value); template struct RangeRef @@ -346,6 +365,41 @@ auto chain(TFirstRange&& firstRange, TSecondRange&& secondRange, TMoreRanges&&.. { return chain(std::forward(firstRange), chain(std::forward(secondRange), std::forward(moreRanges)...)); } + +template +TAs collect(TIterable&& iterable) +{ + return TAs(iterable.begin(), iterable.end()); +} + +namespace pipe +{ +template +struct Replace +{ + T what; + T with; + + Replace(T what_, T with_) : what(std::move(what_)), with(std::move(with_)) {} +}; +template +Replace(T, T) -> Replace; + +template +auto operator|(TIterable&& iterable, Replace()))>::value_type> repl) +{ + return replace(std::forward(iterable), std::move(repl.what), std::move(repl.with)); +} + +template +struct Collect {}; + +template +auto operator|(TIterable&& iterable, Collect) +{ + return collect(std::forward(iterable)); +} +} } // namespace mijin #endif // MIJIN_UTIL_ITERATORS_HPP_INCLUDED \ No newline at end of file