/// \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_REF_HPP #define RANGES_V3_VIEW_REF_HPP #include #include #include #include #include #include #include #include RANGES_DISABLE_WARNINGS namespace ranges { template struct ref_view; /// \cond namespace _ref_view_ { struct adl_hook {}; template constexpr iterator_t begin(ref_view && rng) noexcept( noexcept(rng.begin())) { return rng.begin(); } template constexpr iterator_t begin(ref_view const && rng) noexcept( noexcept(rng.begin())) { return rng.begin(); } template constexpr sentinel_t end(ref_view && rng) noexcept(noexcept(rng.end())) { return rng.end(); } template constexpr sentinel_t end(ref_view const && rng) noexcept( noexcept(rng.end())) { return rng.end(); } } // namespace _ref_view_ /// \endcond /// \addtogroup group-views /// @{ template struct ref_view : view_interface, range_cardinality::value> , private _ref_view_::adl_hook { private: CPP_assert(range); static_assert(std::is_object::value, ""); Rng * rng_ = nullptr; // exposition only public: constexpr ref_view() noexcept = default; constexpr ref_view(Rng & rng) noexcept : rng_(detail::addressof(rng)) {} constexpr Rng & base() const noexcept { return *rng_; } constexpr iterator_t begin() const noexcept(noexcept(ranges::begin(*rng_))) { return ranges::begin(*rng_); } constexpr sentinel_t end() const noexcept(noexcept(ranges::end(*rng_))) { return ranges::end(*rng_); } CPP_member constexpr auto empty() const noexcept(noexcept(ranges::empty(*rng_))) -> CPP_ret(bool)( // requires detail::can_empty_) { return ranges::empty(*rng_); } CPP_member constexpr auto CPP_fun(size)()(const noexcept(noexcept(ranges::size(*rng_))) // requires sized_range) { return ranges::size(*rng_); } CPP_member constexpr auto CPP_fun(data)()(const noexcept(noexcept(ranges::data(*rng_))) // requires contiguous_range) { return ranges::data(*rng_); } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 CPP_template(typename R)(requires range) ref_view(R &)->ref_view; #endif namespace views { struct ref_fn { template constexpr auto operator()(Rng & rng) const noexcept -> CPP_ret(ref_view)( // requires range) { return ref_view(rng); } template void operator()(Rng const && rng) const = delete; }; /// \relates const_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, ref) } // namespace views namespace cpp20 { CPP_template(typename Rng)( // requires std::is_object::value) // using ref_view = ranges::ref_view; } } // namespace ranges RANGES_RE_ENABLE_WARNINGS #include RANGES_SATISFY_BOOST_RANGE(::ranges::ref_view) #endif