/// \file // Range v3 library // // Copyright Eric Niebler 2014-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_VIEW_HPP #define RANGES_V3_VIEW_VIEW_HPP #include #include #include #include #include #include #include #include #include namespace ranges { /// \cond namespace detail { struct null_pipe { template constexpr void operator()(Rng &&) const {} }; struct dereference_fn { // clang-format off template constexpr auto CPP_auto_fun(operator())(I &&i) (const) ( return *(I &&) i ) // clang-format on }; } // namespace detail /// \endcond // clang-format off CPP_def ( template(typename Rng) concept simple_view_, view_ && range && same_as, iterator_t> && same_as, sentinel_t> ); // clang-format on template constexpr bool simple_view() { return (bool)simple_view_; } namespace views { /// \addtogroup group-views /// @{ struct view_access { template struct impl { // clang-format off template static constexpr auto CPP_auto_fun(bind)(Ts &&... ts) ( return V::bind(static_cast(ts)...) ) // clang-format on }; }; struct make_view_fn { template constexpr view operator()(Fun fun) const { return view{std::move(fun)}; } }; /// \ingroup group-views /// \sa make_view_fn RANGES_INLINE_VARIABLE(make_view_fn, make_view) template struct view : pipeable_base { private: View view_; friend pipeable_access; // Piping requires range arguments or lvalue containers. template static constexpr auto CPP_fun(pipe)(Rng && rng, Vw && v)( // requires viewable_range && invocable) { return v.view_(static_cast(rng)); } public: view() = default; constexpr explicit view(View a) noexcept( std::is_nothrow_move_constructible::value) : view_(std::move(a)) {} // Calling directly requires a viewable_range. template constexpr auto operator()(Rng && rng, Rest &&... rest) const -> CPP_ret(invoke_result_t)( // requires viewable_range && invocable) { return view_(static_cast(rng), static_cast(rest)...); } // Currying overload. // clang-format off template constexpr auto CPP_auto_fun(operator())(Ts &&... ts)(const) ( return make_view( view_access::impl::bind(view_, static_cast(ts)...)) ) // clang-format on }; /// \endcond } // namespace views } // namespace ranges #endif