// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #pragma once /*! \file rx-skip_while.hpp \brief Discards the first items fulfilling the predicate from this observable emit them from the new observable that is returned. \tparam Predicate the type of the predicate \param t the predicate \return An observable that discards the first items until condition emitted by the source Observable is not fulfilling the predicate, or all of the items from the source observable if the predicate never returns false \sample \snippet skip_while.cpp skip_while sample \snippet output.txt skip_while sample */ #if !defined(RXCPP_OPERATORS_RX_SKIP_WHILE_HPP) #define RXCPP_OPERATORS_RX_SKIP_WHILE_HPP #include "../rx-includes.hpp" namespace rxcpp { namespace operators { namespace detail { template struct skip_while_invalid_arguments {}; template struct skip_while_invalid : public rxo::operator_base> { using type = observable, skip_while_invalid>; }; template using skip_while_invalid_t = typename skip_while_invalid::type; template struct skip_while { typedef rxu::decay_t source_value_type; typedef rxu::decay_t test_type; test_type test; skip_while(test_type t) : test(std::move(t)) { } template struct skip_while_observer { typedef skip_while_observer this_type; typedef source_value_type value_type; typedef rxu::decay_t dest_type; typedef observer observer_type; dest_type dest; test_type test; bool pass; skip_while_observer(dest_type d, test_type t) : dest(std::move(d)) , test(std::move(t)), pass(false) { } void on_next(source_value_type v) { if(pass || !test(v)) { pass = true; dest.on_next(v); } } void on_error(rxu::error_ptr e) const { dest.on_error(e); } void on_completed() const { dest.on_completed(); } static subscriber make(dest_type d, test_type t) { return make_subscriber(d, this_type(d, std::move(t))); } }; template auto operator()(Subscriber dest) const -> decltype(skip_while_observer::make(std::move(dest), test)) { return skip_while_observer::make(std::move(dest), test); } }; } /*! @copydoc rx-skip_while.hpp */ template auto skip_while(AN&&... an) -> operator_factory { return operator_factory(std::make_tuple(std::forward(an)...)); } } template<> struct member_overload { template, class TakeWhile = rxo::detail::skip_while>> static auto member(Observable&& o, Predicate&& p) -> decltype(o.template lift(TakeWhile(std::forward(p)))) { return o.template lift(TakeWhile(std::forward(p))); } template static operators::detail::skip_while_invalid_t member(const AN&...) { std::terminate(); return {}; static_assert(sizeof...(AN) == 10000, "skip_while takes (Predicate)"); } }; } #endif