forked from OctaForge/libostd
make the pipe op a member to make it to work automagically on user ranges
This commit is contained in:
parent
6ba3b93018
commit
21da5ec3d1
|
@ -691,6 +691,25 @@ struct InputRange {
|
|||
return *static_cast<B *>(this);
|
||||
}
|
||||
|
||||
/* pipe op, must be a member to work for user ranges automagically */
|
||||
|
||||
template<typename F>
|
||||
auto operator|(F &&func) & {
|
||||
return func(*static_cast<B *>(this));
|
||||
}
|
||||
template<typename F>
|
||||
auto operator|(F &&func) const & {
|
||||
return func(*static_cast<B const *>(this));
|
||||
}
|
||||
template<typename F>
|
||||
auto operator|(F &&func) && {
|
||||
return func(std::move(*static_cast<B *>(this)));
|
||||
}
|
||||
template<typename F>
|
||||
auto operator|(F &&func) const && {
|
||||
return func(std::move(*static_cast<B const *>(this)));
|
||||
}
|
||||
|
||||
/* universal bool operator */
|
||||
|
||||
explicit operator bool() const {
|
||||
|
@ -698,13 +717,6 @@ struct InputRange {
|
|||
}
|
||||
};
|
||||
|
||||
template<typename R, typename F>
|
||||
inline auto operator|(R &&range, F &&func) ->
|
||||
std::enable_if_t<IsInputRange<R>, decltype(func(std::forward<R>(range)))>
|
||||
{
|
||||
return func(std::forward<R>(range));
|
||||
}
|
||||
|
||||
inline auto reverse() {
|
||||
return [](auto &&obj) { return obj.reverse(); };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue