// // any.h // stream // // Created by Sam Jaffe on 3/29/23. // #pragma once #include #include #include #include namespace stream::ranges { template class any_view { private: template using sentinel_iterator = common_iterator, detail::end_t>; template using iter_cast_t = std::conditional_t, sentinel_iterator, It>; using make_iter_t = any_iterator (*)(void *); private: std::shared_ptr impl_{nullptr}; make_iter_t begin_{nullptr}; make_iter_t end_{nullptr}; public: template any_view(std::shared_ptr impl) : impl_(impl), begin_(begin_function()), end_(end_function()) {} template any_view(S & impl) : any_view(std::shared_ptr(&impl, [](void *) {})) {} template any_view(S const & impl) : any_view(std::shared_ptr(&impl, [](void *) {})) {} template any_view(S && impl) : any_view(std::make_shared(std::forward(impl))) {} auto begin() const { return begin_(impl_.get()); } auto end() const { return end_(impl_.get()); } private: template static make_iter_t begin_function() { return [](void * p) -> any_iterator { return iter_cast_t>(static_cast(p)->begin()); }; } template static make_iter_t end_function() { return [](void * p) -> any_iterator { return iter_cast_t>(static_cast(p)->end()); }; } }; template any_view(std::shared_ptr) -> any_view>; template any_view(S &) -> any_view>; template any_view(S const &) -> any_view>; template any_view(S &&) -> any_view>; }