/// \file // Range v3 library // // Copyright Filip Matzner 2017 // // 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_EXPERIMENTAL_VIEW_SHARED_HPP #define RANGES_V3_EXPERIMENTAL_VIEW_SHARED_HPP #include #include #include #include #include #include #include namespace ranges { namespace experimental { template struct shared_view : view_interface, range_cardinality::value> { private: // shared storage std::shared_ptr rng_ptr_; public: shared_view() = default; // construct from a range rvalue explicit shared_view(Rng && t) : rng_ptr_{std::make_shared(std::move(t))} {} // use the stored range's begin and end iterator_t begin() const { return ranges::begin(*rng_ptr_); } sentinel_t end() const { return ranges::end(*rng_ptr_); } CPP_member auto CPP_fun(size)()(const requires sized_range) { return ranges::size(*rng_ptr_); } }; /// \relates all /// \addtogroup group-views /// @{ namespace views { struct shared_fn : pipeable_base { public: template auto operator()(Rng && t) const -> CPP_ret(shared_view)( // requires range && (!view_)&&(!std::is_reference::value)) { return shared_view{std::move(t)}; } }; /// \relates all_fn /// \ingroup group-views RANGES_INLINE_VARIABLE(shared_fn, shared) template using shared_t = detail::decay_t()))>; } // namespace views /// @} } // namespace experimental } // namespace ranges #endif // include guard