/// \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_COMMON_HPP #define RANGES_V3_VIEW_COMMON_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-views /// @{ namespace detail { /// \cond // clang-format off CPP_def ( template(typename R) concept random_access_and_sized_range, random_access_range && sized_range ); // clang-format on template using common_view_iterator_t = meta::if_c, iterator_t, common_iterator_t, sentinel_t>>; template struct is_common_range : meta::bool_> {}; /// \endcond } // namespace detail template::value> struct common_view : view_interface, range_cardinality::value> { private: CPP_assert(view_); CPP_assert(!(common_range && view_)); Rng rng_; sentinel_t end_(std::false_type) { return ranges::end(rng_); } iterator_t end_(std::true_type) { return ranges::begin(rng_) + ranges::distance(rng_); } template auto end_(std::false_type) const -> CPP_ret(sentinel_t>)( // requires Const && range>) { return ranges::end(rng_); } template auto end_(std::true_type) const -> CPP_ret(iterator_t>)( // requires Const && range>) { return ranges::begin(rng_) + ranges::distance(rng_); } public: common_view() = default; explicit common_view(Rng rng) : rng_(detail::move(rng)) {} Rng base() const { return rng_; } detail::common_view_iterator_t begin() { return detail::common_view_iterator_t{ranges::begin(rng_)}; } detail::common_view_iterator_t end() { return detail::common_view_iterator_t{ end_(meta::bool_>{})}; } CPP_member auto CPP_fun(size)()(requires sized_range) { return ranges::size(rng_); } template auto begin() const -> CPP_ret(detail::common_view_iterator_t>)( // requires range>) { return detail::common_view_iterator_t>{ ranges::begin(rng_)}; } template auto end() const -> CPP_ret(detail::common_view_iterator_t>)( // requires range>) { return detail::common_view_iterator_t>{ end_(meta::bool_>>{})}; } CPP_member auto CPP_fun(size)()(const requires sized_range) { return ranges::size(rng_); } }; #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 CPP_template(typename Rng)(requires !common_range) common_view(Rng &&) ->common_view>; #endif template struct common_view : identity_adaptor { CPP_assert(common_range); using identity_adaptor::identity_adaptor; }; namespace views { struct cpp20_common_fn { template auto operator()(Rng && rng) const -> CPP_ret(common_view>)( // requires viewable_range && (!common_range)) { return common_view>{all(static_cast(rng))}; } }; struct common_fn { template auto operator()(Rng && rng) const -> CPP_ret(common_view>)( // requires viewable_range) { return common_view>{all(static_cast(rng))}; } }; /// \relates common_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(view, common) } // namespace views /// @} /// \cond template using bounded_view RANGES_DEPRECATED( "The name bounded_view is deprecated. " "Please use common_view instead.") = common_view; /// \endcond namespace views { /// \cond namespace { RANGES_DEPRECATED( "The name views::bounded is deprecated. " "Please use views::common instead.") RANGES_INLINE_VAR constexpr auto & bounded = common; } // namespace template using bounded_t RANGES_DEPRECATED("The name views::bounded_t is deprecated.") = decltype(common(std::declval())); /// \endcond } // namespace views namespace cpp20 { namespace views { RANGES_INLINE_VARIABLE(ranges::views::view, common) } CPP_template(typename Rng)( // requires view_ && (!common_range)) // using common_view = ranges::common_view; } // namespace cpp20 } // namespace ranges #include RANGES_SATISFY_BOOST_RANGE(::ranges::common_view) #endif