make the pipe op a member to make it to work automagically on user ranges

master
Daniel Kolesa 2017-02-13 21:12:32 +01:00
parent 6ba3b93018
commit 21da5ec3d1
1 changed files with 19 additions and 7 deletions

View File

@ -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(); };
}