11 template<
typename Value>
15 template<
typename Value>
19 template<
typename Value>
31 template<
typename Value>
83 virtual std::unique_ptr<Strategy<Value>>
clone()
const = 0;
96 template<
typename Value,
class Derived>
99 std::unique_ptr<Strategy<Value>>
clone()
const override {
100 return std::make_unique<Derived>(
static_cast<const Derived &
>(*this));
111 template<
class Value>
112 class Union :
public CloneHelper<Value, Union<Value>> {
116 strategies_.push_back(strategy.
clone());
117 strategies_.push_back(other_strategy.
clone());
126 strategies_.reserve(strategy.strategies_.size());
127 for (
const auto &sub_strategy: strategy.strategies_) {
128 strategies_.push_back(sub_strategy->clone());
136 static std::random_device random_device;
137 size_t max_index = strategies_.size() - 1;
138 std::uniform_int_distribution<size_t> distribution(0, max_index);
139 size_t index = distribution(random_device);
140 return (*strategies_[index])();
145 result.strategies_.push_back(strategy.
clone());
151 for (
const auto &sub_strategy: strategy.strategies_) {
152 result.strategies_.push_back(sub_strategy->clone());
158 std::vector<std::unique_ptr<Strategy<Value>>> strategies_;
172 template<
typename Value>
173 class Filtered :
public CloneHelper<Value, Filtered<Value>> {
202 std::function<Value()> producer([&]() -> Value {
224 template<
typename Value>
251 Value product = (*strategy_)();
std::function< Product(Product)> Converter
Definition: facility.h:10
Union< Value > operator||(const Union< Value > &strategy) const override
Definition: bases.h:149
Facility< Product > expand(const Converter< Product > &converter) const
Definition: facility.h:24
Union< Value > operator||(const Strategy< Value > &strategy) const override
Definition: bases.h:143
Facility< Value > facility_
Definition: bases.h:257
Mapped(const Strategy< Value > &strategy, const Facility< Value > &facility)
Definition: bases.h:227
virtual std::unique_ptr< Strategy< Value > > clone() const =0
Filtered(const Filtered< Value > &strategy)
Definition: bases.h:185
virtual Filtered< Value > filter(const Requirement< Value > &requirement) const
Definition: bases.h:64
Union(const Strategy< Value > &strategy, const Strategy< Value > &other_strategy)
Definition: bases.h:114
Mapped< Value > map(const Converter< Value > &converter) const override
Definition: bases.h:241
std::unique_ptr< Strategy< Value > > strategy_
Definition: bases.h:209
Sieve< Value > sieve_
Definition: bases.h:210
Value operator()() const override
Definition: bases.h:135
std::function< bool(Product)> Requirement
Definition: sieve.h:12
virtual Value operator()() const =0
Product convert(Product product) const
Definition: facility.h:30
virtual Union< Value > operator||(const Union< Value > &strategy) const
Definition: bases.h:52
Value operator()() const override
Definition: bases.h:250
Value operator()() const override
Definition: bases.h:201
Filtered(const Strategy< Value > &strategy, const Sieve< Value > &sieve)
Definition: bases.h:175
virtual Union< Value > operator||(const Strategy< Value > &strategy) const
Definition: bases.h:43
std::unique_ptr< Strategy< Value > > clone() const override
Definition: bases.h:99
virtual Mapped< Value > map(const Converter< Value > &converter) const
Definition: bases.h:74
Filtered< Value > filter(const Requirement< Value > &requirement) const override
Definition: bases.h:189
Sieve< Product > expand(const Requirement< Product > &requirement) const
Definition: sieve.h:57
Mapped(const Mapped< Value > &strategy)
Definition: bases.h:237
Product sift(std::function< Product()> producer) const
Definition: sieve.h:64
std::unique_ptr< Strategy< Value > > strategy_
Definition: bases.h:256
Union(const Union< Value > &strategy)
Definition: bases.h:125