class ResultGen = void>
ResultGen compose(const GenImpl<Value, Source>& source) const;
- /**
- * operator|() - For composing two operators without binding it to a
- * particular generator.
- */
- template<class Next,
- class Composed = detail::Composed<Self, Next>>
- Composed operator|(const Operator<Next>& op) const {
- return Composed(this->self(), op.self());
- }
protected:
Operator() = default;
Operator(const Operator&) = default;
Operator(Operator&&) = default;
};
+/**
+ * operator|() - For composing two operators without binding it to a
+ * particular generator.
+ */
+template<class Left,
+ class Right,
+ class Composed = detail::Composed<Left, Right>>
+Composed operator|(const Operator<Left>& left,
+ const Operator<Right>& right) {
+ return Composed(left.self(), right.self());
+}
+
+template<class Left,
+ class Right,
+ class Composed = detail::Composed<Left, Right>>
+Composed operator|(const Operator<Left>& left,
+ Operator<Right>&& right) {
+ return Composed(left.self(), std::move(right.self()));
+}
+
+template<class Left,
+ class Right,
+ class Composed = detail::Composed<Left, Right>>
+Composed operator|(Operator<Left>&& left,
+ const Operator<Right>& right) {
+ return Composed(std::move(left.self()), right.self());
+}
+
+template<class Left,
+ class Right,
+ class Composed = detail::Composed<Left, Right>>
+Composed operator|(Operator<Left>&& left,
+ Operator<Right>&& right) {
+ return Composed(std::move(left.self()), std::move(right.self()));
+}
+
/**
* GenImpl - Core abstraction of a generator, an object which produces values by
* passing them to a given handler lambda. All generator implementations must
return true;
});
}
-
- template<class Next,
- class Chain = detail::Chain<Value, Self, Next>,
- class ValueNext>
- Chain operator+(const GenImpl<ValueNext, Next>& next) const {
- static_assert(
- std::is_same<Value, ValueNext>::value,
- "Generators may ony be combined if Values are the exact same type.");
- return Chain(*this, next);
- }
};
+template<class LeftValue,
+ class Left,
+ class RightValue,
+ class Right,
+ class Chain = detail::Chain<LeftValue, Left, Right>>
+Chain operator+(const GenImpl<LeftValue, Left>& left,
+ const GenImpl<RightValue, Right>& right) {
+ static_assert(
+ std::is_same<LeftValue, RightValue>::value,
+ "Generators may ony be combined if Values are the exact same type.");
+ return Chain(left.self(), right.self());
+}
+
+template<class LeftValue,
+ class Left,
+ class RightValue,
+ class Right,
+ class Chain = detail::Chain<LeftValue, Left, Right>>
+Chain operator+(const GenImpl<LeftValue, Left>& left,
+ GenImpl<RightValue, Right>&& right) {
+ static_assert(
+ std::is_same<LeftValue, RightValue>::value,
+ "Generators may ony be combined if Values are the exact same type.");
+ return Chain(left.self(), std::move(right.self()));
+}
+
+template<class LeftValue,
+ class Left,
+ class RightValue,
+ class Right,
+ class Chain = detail::Chain<LeftValue, Left, Right>>
+Chain operator+(GenImpl<LeftValue, Left>&& left,
+ const GenImpl<RightValue, Right>& right) {
+ static_assert(
+ std::is_same<LeftValue, RightValue>::value,
+ "Generators may ony be combined if Values are the exact same type.");
+ return Chain(std::move(left.self()), right.self());
+}
+
+template<class LeftValue,
+ class Left,
+ class RightValue,
+ class Right,
+ class Chain = detail::Chain<LeftValue, Left, Right>>
+Chain operator+(GenImpl<LeftValue, Left>&& left,
+ GenImpl<RightValue, Right>&& right) {
+ static_assert(
+ std::is_same<LeftValue, RightValue>::value,
+ "Generators may ony be combined if Values are the exact same type.");
+ return Chain(std::move(left.self()), std::move(right.self()));
+}
+
/**
* operator|() which enables foreach-like usage:
* gen | [](Value v) -> void {...};
class Op>
auto operator|(const GenImpl<Value, Gen>& gen, const Operator<Op>& op) ->
decltype(op.self().compose(gen)) {
- return op.self().compose(gen);
+ return op.self().compose(gen.self());
+}
+
+template<class Value,
+ class Gen,
+ class Op>
+auto operator|(GenImpl<Value, Gen>&& gen, const Operator<Op>& op) ->
+decltype(op.self().compose(std::move(gen.self()))) {
+ return op.self().compose(std::move(gen.self()));
}
namespace detail {
const First first_;
const Second second_;
public:
- explicit Chain(const GenImpl<Value, First>& first,
- const GenImpl<Value, Second>& second)
- : first_(first.self())
- , second_(second.self()) {}
+ explicit Chain(First first, Second second)
+ : first_(std::move(first))
+ , second_(std::move(second)) {}
template<class Handler>
bool apply(Handler&& handler) const {
class Yield : public GenImpl<Value, Yield<Value, Source>> {
const Source source_;
public:
- explicit Yield(const Source& source)
- : source_(source) {
+ explicit Yield(Source source)
+ : source_(std::move(source)) {
}
template<class Handler>
const Source source_;
const Predicate pred_;
public:
- explicit Generator(const Source& source, const Predicate& pred)
- : source_(source), pred_(pred) {}
+ explicit Generator(Source source, const Predicate& pred)
+ : source_(std::move(source)), pred_(pred) {}
template<class Body>
void foreach(Body&& body) const {
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), predicate_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
const Source source_;
const Predicate pred_;
public:
- explicit Generator(const Source& source, const Predicate& pred)
- : source_(source), pred_(pred) {}
+ explicit Generator(Source source, const Predicate& pred)
+ : source_(std::move(source)), pred_(pred) {}
template<class Body>
void foreach(Body&& body) const {
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), predicate_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
const Source source_;
const Predicate pred_;
public:
- explicit Generator(const Source& source, const Predicate& pred)
- : source_(source), pred_(pred) {}
+ explicit Generator(Source source, const Predicate& pred)
+ : source_(std::move(source)), pred_(pred) {}
template<class Handler>
bool apply(Handler&& handler) const {
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), predicate_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
const Source source_;
const size_t count_;
public:
- explicit Generator(const Source& source, size_t count)
- : source_(source) , count_(count) {}
+ explicit Generator(Source source, size_t count)
+ : source_(std::move(source)) , count_(count) {}
template<class Handler>
bool apply(Handler&& handler) const {
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), count_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
const Source source_;
const size_t count_;
public:
- explicit Generator(const Source& source, size_t count)
- : source_(source) , count_(count) {}
+ explicit Generator(Source source, size_t count)
+ : source_(std::move(source)) , count_(count) {}
template<class Body>
void foreach(Body&& body) const {
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), count_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
return std::move(vals);
}
public:
- Generator(const Source& source,
+ Generator(Source source,
const Selector& selector,
const Comparer& comparer)
- : source_(source) , selector_(selector) , comparer_(comparer) {}
+ : source_(std::move(source)),
+ selector_(selector),
+ comparer_(comparer) {}
VectorType operator|(const Collect<VectorType>&) const {
return asVector();
}
};
+ template<class Source,
+ class Value,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()), selector_, comparer_);
+ }
+
template<class Source,
class Value,
class Gen = Generator<Value, Source>>
const Second second_;
public:
Composed() {}
- Composed(const First& first, const Second& second)
- : first_(first)
- , second_(second) {}
+ Composed(First first, Second second)
+ : first_(std::move(first))
+ , second_(std::move(second)) {}
template<class Source,
class Value,
SecondRet compose(const GenImpl<Value, Source>& source) const {
return second_.compose(first_.compose(source.self()));
}
+
+ template<class Source,
+ class Value,
+ class FirstRet = decltype(std::declval<First>()
+ .compose(std::declval<Source>())),
+ class SecondRet = decltype(std::declval<Second>()
+ .compose(std::declval<FirstRet>()))>
+ SecondRet compose(GenImpl<Value, Source>&& source) const {
+ return second_.compose(first_.compose(std::move(source.self())));
+ }
};
/*
public GenImpl<InnerValue, Generator<Inner, Source, InnerValue>> {
const Source source_;
public:
- explicit Generator(const Source& source)
- : source_(source) {}
+ explicit Generator(Source source)
+ : source_(std::move(source)) {}
template<class Handler>
bool apply(Handler&& handler) const {
}
};
+ template<class Value,
+ class Source,
+ class Gen = Generator<Value, Source>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()));
+ }
+
template<class Value,
class Source,
class Gen = Generator<Value, Source>>
: public GenImpl<InnerValue, Generator<Source, Range, InnerValue>> {
const Source source_;
public:
- Generator(const Source& source)
- : source_(source) {}
+ explicit Generator(Source source)
+ : source_(std::move(source)) {}
template<class Body>
void foreach(Body&& body) const {
}
};
+ template<class Value,
+ class Source,
+ class Gen = Generator<Source, Value>>
+ Gen compose(GenImpl<Value, Source>&& source) const {
+ return Gen(std::move(source.self()));
+ }
+
template<class Value,
class Source,
class Gen = Generator<Source, Value>>
class WrapperImpl : public WrapperBase {
const Wrapped wrapped_;
public:
- WrapperImpl(const Wrapped& wrapped)
- : wrapped_(wrapped) {
+ explicit WrapperImpl(Wrapped wrapped)
+ : wrapped_(std::move(wrapped)) {
}
virtual bool apply(const std::function<bool(Value)>& handler) const {
std::unique_ptr<const WrapperBase> wrapper_;
public:
- template<class SourceValue,
- class Self>
- /* implicit */ VirtualGen(const GenImpl<SourceValue, Self>& source)
- : wrapper_(new WrapperImpl<Self>(source.self()))
+ template<class Self>
+ /* implicit */ VirtualGen(Self source)
+ : wrapper_(new WrapperImpl<Self>(std::move(source)))
{ }
VirtualGen(VirtualGen&& source)