/// \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_INDIRECT_HPP #define RANGES_V3_VIEW_INDIRECT_HPP #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-views /// @{ template struct indirect_view : view_adaptor, Rng> { private: friend range_access; template struct adaptor : adaptor_base { friend adaptor; using CRng = meta::const_if_c; adaptor() = default; CPP_template(bool Other)( // requires IsConst && (!Other)) constexpr adaptor(adaptor) noexcept {} // clang-format off constexpr auto CPP_auto_fun(read)(iterator_t const &it)(const) ( return **it ) constexpr auto CPP_auto_fun(iter_move)(iterator_t const &it)(const) ( return ranges::iter_move(*it) ) // clang-format on }; CPP_member constexpr auto begin_adaptor() noexcept -> CPP_ret(adaptor)( // requires(!simple_view())) { return {}; } CPP_member constexpr auto begin_adaptor() const noexcept -> CPP_ret(adaptor)( // requires range) { return {}; } CPP_member constexpr auto end_adaptor() noexcept -> CPP_ret(adaptor)( // requires(!simple_view())) { return {}; } CPP_member constexpr auto end_adaptor() const noexcept -> CPP_ret(adaptor)( // requires range) { return {}; } public: indirect_view() = default; explicit constexpr indirect_view(Rng rng) : indirect_view::view_adaptor{detail::move(rng)} {} CPP_member constexpr auto CPP_fun(size)()(const requires sized_range) { return ranges::size(this->base()); } CPP_member constexpr auto CPP_fun(size)()(requires sized_range) { return ranges::size(this->base()); } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 template indirect_view(Rng &&)->indirect_view>; #endif namespace views { struct indirect_fn { template constexpr auto CPP_fun(operator())(Rng && rng)( const requires viewable_range && input_range && // We shouldn't need to strip references to test if something // is readable. https://github.com/ericniebler/stl2/issues/594 // readable>) ((bool)readable>)) // Cast to bool needed for GCC (???) { return indirect_view>{all(static_cast(rng))}; } }; /// \relates indirect_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, indirect) } // namespace views /// @} } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::indirect_view) #endif