Commit 11cc0c8f authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

folly::gen to range-v3: relo op|

Summary:
Relocate "folly::gen to range-v3" pipe-adapters into the corresponding adapter-struct (fix compile-time errors, plus improve clarity about the linkage between the `operator|` and corresponding type).

Context: pipe-adapters ("pipe fittings") that allow a `|`-based pipeline mixing {std-containers and/or range-v3} with folly::gen, e.g.,

```
auto result = myVec              // anything consistent with range-v3 or these adapters
    | ranges::view::filter(...)  // zero-or-more range-v3 pipe-elems
    | <adapter-goes-here>        // <==**one of the pipe-adapters provided by this task**
    | folly::gen::blah();        // trailing pipe-elems are folly::gen
```

This diff relocates those folly::gen-to-range-v3 adapters.

Reviewed By: yfeldblum, ericniebler

Differential Revision: D16053008

fbshipit-source-id: 078a95990d5277ac0c4e02452cd8fd36bead8306
parent 525c49f9
...@@ -2542,10 +2542,30 @@ class RangeV3CopySource ...@@ -2542,10 +2542,30 @@ class RangeV3CopySource
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
struct container_to_gen_fn {}; struct container_to_gen_fn {
struct rangev3_to_gen_fn {}; template <typename Container>
struct rangev3_to_gen_copy_fn {}; friend auto operator|(Container&& c, container_to_gen_fn) {
struct rangev3_will_be_consumed_fn {}; return gen::from(std::forward<Container>(c));
}
};
struct rangev3_to_gen_fn {
template <typename Range>
friend auto operator|(Range&& r, rangev3_to_gen_fn) {
using DecayedRange = std::decay_t<Range>;
using DecayedValue = std::decay_t<decltype(*r.begin())>;
return RangeV3Source<DecayedRange, DecayedValue>(r);
}
};
struct rangev3_to_gen_copy_fn {
template <typename Range>
friend auto operator|(Range&& r, rangev3_to_gen_copy_fn) {
using RangeDecay = std::decay_t<Range>;
using Value = std::decay_t<decltype(*r.begin())>;
return RangeV3CopySource<RangeDecay, Value>(std::move(r));
}
};
#endif // FOLLY_USE_RANGEV3 #endif // FOLLY_USE_RANGEV3
} // namespace detail } // namespace detail
...@@ -2561,25 +2581,6 @@ constexpr detail::container_to_gen_fn from_container; ...@@ -2561,25 +2581,6 @@ constexpr detail::container_to_gen_fn from_container;
constexpr detail::rangev3_to_gen_fn from_rangev3; constexpr detail::rangev3_to_gen_fn from_rangev3;
constexpr detail::rangev3_to_gen_copy_fn from_rangev3_copy; constexpr detail::rangev3_to_gen_copy_fn from_rangev3_copy;
template <typename Container>
auto operator|(Container&& c, detail::container_to_gen_fn) {
return gen::from(std::forward<Container>(c));
}
template <typename Range>
auto operator|(Range&& r, detail::rangev3_to_gen_fn) {
using DecayedRange = std::decay_t<Range>;
using DecayedValue = std::decay_t<decltype(*r.begin())>;
return detail::RangeV3Source<DecayedRange, DecayedValue>(r);
}
template <typename Range>
auto operator|(Range&& r, detail::rangev3_to_gen_copy_fn) {
using RangeDecay = std::decay_t<Range>;
using Value = std::decay_t<decltype(*r.begin())>;
return detail::RangeV3CopySource<RangeDecay, Value>(std::move(r));
}
template <typename Range> template <typename Range>
auto rangev3_to_gen_call(Range&& r) { auto rangev3_to_gen_call(Range&& r) {
using Value = std::decay_t<decltype(*r.begin())>; using Value = std::decay_t<decltype(*r.begin())>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment