Warning, file /include/range/v3/experimental/view/shared.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RANGES_V3_EXPERIMENTAL_VIEW_SHARED_HPP
0014 #define RANGES_V3_EXPERIMENTAL_VIEW_SHARED_HPP
0015
0016 #include <memory>
0017 #include <type_traits>
0018
0019 #include <meta/meta.hpp>
0020
0021 #include <range/v3/functional/compose.hpp>
0022 #include <range/v3/range/access.hpp>
0023 #include <range/v3/range/concepts.hpp>
0024 #include <range/v3/range/primitives.hpp>
0025 #include <range/v3/view/all.hpp>
0026
0027 #include <range/v3/detail/prologue.hpp>
0028
0029 namespace ranges
0030 {
0031
0032
0033 namespace experimental
0034 {
0035 template<typename Rng>
0036 struct shared_view
0037 : view_interface<shared_view<Rng>, range_cardinality<Rng>::value>
0038 {
0039 private:
0040
0041 std::shared_ptr<Rng> rng_ptr_;
0042
0043 public:
0044 shared_view() = default;
0045
0046
0047 explicit shared_view(Rng rng)
0048 : rng_ptr_{std::make_shared<Rng>(std::move(rng))}
0049 {}
0050
0051
0052 iterator_t<Rng> begin() const
0053 {
0054 return ranges::begin(*rng_ptr_);
0055 }
0056 sentinel_t<Rng> end() const
0057 {
0058 return ranges::end(*rng_ptr_);
0059 }
0060
0061 CPP_auto_member
0062 auto CPP_fun(size)()(const
0063 requires sized_range<Rng>)
0064 {
0065 return ranges::size(*rng_ptr_);
0066 }
0067 };
0068
0069 template<typename SharedFn>
0070 struct shared_closure;
0071
0072 struct RANGES_STRUCT_WITH_ADL_BARRIER(shared_closure_base)
0073 {
0074
0075 template(typename Rng, typename SharedFn)(
0076 requires range<Rng> AND (!viewable_range<Rng>) AND
0077 constructible_from<detail::decay_t<Rng>, Rng>)
0078 friend constexpr auto operator|(Rng && rng, shared_closure<SharedFn> vw)
0079 {
0080 return static_cast<SharedFn &&>(vw)(static_cast<Rng &&>(rng));
0081 }
0082
0083 template<typename SharedFn, typename Pipeable>
0084 friend constexpr auto operator|(shared_closure<SharedFn> sh, Pipeable pipe)
0085 -> CPP_broken_friend_ret(shared_closure<composed<Pipeable, SharedFn>>)(
0086 requires (is_pipeable_v<Pipeable>))
0087 {
0088 return shared_closure<composed<Pipeable, SharedFn>>{compose(
0089 static_cast<Pipeable &&>(pipe), static_cast<SharedFn &&>(sh))};
0090 }
0091 };
0092
0093 template<typename SharedFn>
0094 struct shared_closure
0095 : shared_closure_base
0096 , SharedFn
0097 {
0098 shared_closure() = default;
0099 constexpr explicit shared_closure(SharedFn fn)
0100 : SharedFn(static_cast<SharedFn &&>(fn))
0101 {}
0102 };
0103
0104 namespace views
0105 {
0106 struct shared_fn
0107 {
0108 template(typename Rng)(
0109 requires range<Rng> AND (!viewable_range<Rng>)AND
0110 constructible_from<detail::decay_t<Rng>, Rng>)
0111 shared_view<detail::decay_t<Rng>> operator()(Rng && rng) const
0112 {
0113 return shared_view<detail::decay_t<Rng>>{static_cast<Rng &&>(rng)};
0114 }
0115 };
0116
0117
0118
0119 RANGES_INLINE_VARIABLE(shared_closure<shared_fn>, shared)
0120 }
0121 }
0122
0123 template<typename SharedFn>
0124 RANGES_INLINE_VAR constexpr bool
0125 is_pipeable_v<experimental::shared_closure<SharedFn>> = true;
0126
0127 }
0128
0129 #include <range/v3/detail/epilogue.hpp>
0130
0131 #endif