| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // to.h
- // stream
- //
- // Created by Sam Jaffe on 3/29/23.
- //
- #pragma once
- #include <map>
- #include <set>
- #include <vector>
- #include <stream/forward.h>
- #include <stream/view/common.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename C> class store {
- private:
- C & to_;
- public:
- store(C & to) : to_(to) {}
- template <typename Stream>
- friend void operator|(Stream && stream, store && store) {
- store.to_.emplace(store.to_.end(), stream.begin(), stream.end());
- }
- };
- template <template <typename...> class C> struct to_range {
- template <typename Stream> friend auto operator|(Stream && stream, to_range) {
- if constexpr (detail::has_sentinal_v<Stream>) {
- common_view common(FWD(stream));
- return C(common.begin(), common.end());
- } else {
- return C(stream.begin(), stream.end());
- }
- }
- };
- template <template <typename...> class C> auto to() { return to_range<C>(); }
- inline auto to_vector() { return to<std::vector>(); }
- inline auto to_map() { return to<std::map>(); }
- inline auto to_set() { return to<std::set>(); }
- }
- #include <stream/detail/undef.h>
|