/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_TAKE_WHILE_HPP #define RANGES_V3_VIEW_TAKE_WHILE_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-views /// @{ template struct iter_take_while_view : view_adaptor, Rng, is_finite::value ? finite : unknown> { private: friend range_access; RANGES_NO_UNIQUE_ADDRESS semiregular_box_t pred_; template struct sentinel_adaptor : adaptor_base { private: friend struct sentinel_adaptor; using CRng = meta::const_if_c; semiregular_box_ref_or_val_t pred_; public: sentinel_adaptor() = default; sentinel_adaptor(semiregular_box_ref_or_val_t pred) : pred_(std::move(pred)) {} CPP_template(bool Other)( // requires IsConst && (!Other)) sentinel_adaptor(sentinel_adaptor that) : pred_(std::move(that.pred_)) {} bool empty(iterator_t const & it, sentinel_t const & last) const { return it == last || !invoke(pred_, it); } }; sentinel_adaptor end_adaptor() { return {pred_}; } template auto end_adaptor() const -> CPP_ret(sentinel_adaptor)( // requires Const && range> && invocable>>) { return {pred_}; } public: iter_take_while_view() = default; constexpr iter_take_while_view(Rng rng, Pred pred) : iter_take_while_view::view_adaptor{std::move(rng)} , pred_(std::move(pred)) {} }; template struct take_while_view : iter_take_while_view> { take_while_view() = default; constexpr take_while_view(Rng rng, Pred pred) : iter_take_while_view>{std::move(rng), indirect(std::move(pred))} {} }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 CPP_template(typename Rng, typename Fun)(requires copy_constructible) take_while_view(Rng &&, Fun) ->take_while_view, Fun>; #endif namespace views { struct iter_take_while_fn { private: friend view_access; template static constexpr auto bind(iter_take_while_fn iter_take_while, Pred pred) { return make_pipeable(bind_back(iter_take_while, std::move(pred))); } public: template constexpr auto operator()(Rng && rng, Pred pred) const -> CPP_ret(iter_take_while_view, Pred>)( // requires viewable_range && input_range && predicate> && copy_constructible) { return {all(static_cast(rng)), std::move(pred)}; } }; struct take_while_fn { private: friend view_access; template static constexpr auto bind(take_while_fn take_while, Pred pred) { return make_pipeable(bind_back(take_while, std::move(pred))); } template static constexpr auto bind(take_while_fn take_while, Pred pred, Proj proj) { return make_pipeable( bind_back(take_while, std::move(pred), std::move(proj))); } public: template constexpr auto operator()(Rng && rng, Pred pred) const -> CPP_ret(take_while_view, Pred>)( // requires viewable_range && input_range && indirect_unary_predicate>) { return {all(static_cast(rng)), std::move(pred)}; } template constexpr auto operator()(Rng && rng, Pred pred, Proj proj) const -> CPP_ret(take_while_view, composed>)( // requires viewable_range && input_range && indirect_unary_predicate &, iterator_t>) { return {all(static_cast(rng)), compose(std::move(pred), std::move(proj))}; } }; /// \relates iter_take_while_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, iter_take_while) /// \relates take_while_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, take_while) } // namespace views namespace cpp20 { namespace views { using ranges::views::take_while; } CPP_template(typename Rng, typename Pred)( // requires viewable_range && input_range && predicate> && copy_constructible) // using take_while_view = ranges::take_while_view; } // namespace cpp20 /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::iter_take_while_view) RANGES_SATISFY_BOOST_RANGE(::ranges::take_while_view) #endif