cauldron  0.0.0
 All Classes Namespaces Files Functions Variables Typedefs
sets.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <set>
5 
6 #include "bases.h"
7 
8 
9 namespace cauldron {
15 template<typename Element>
16 class Sets : public CloneHelper<std::set<Element>, Sets<Element>> {
19  public:
24  Sets(const SizesStrategy &sizes,
25  const ElementsStrategy &elements) :
26  sizes_(sizes.clone()),
27  elements_(elements.clone()) {};
28 
34  Sets(const Sets<Element> &sets) :
35  sizes_(sets.sizes_->clone()),
36  elements_(sets.elements_->clone()) {};
37 
41  std::set<Element> operator()() const override {
42  size_t size = (*sizes_)();
43  std::set<Element> result;
44  Requirement<Element> element_unique(
45  [&result](Element value) -> bool {
46  return result.find(value) == result.end();
47  });
48  Filtered<Element> elements = (*elements_).filter(element_unique);
49  std::generate_n(std::inserter(result,
50  result.begin()),
51  size,
52  elements);
53  return result;
54  }
55 
56  private:
57  std::unique_ptr<SizesStrategy> sizes_;
58  std::unique_ptr<ElementsStrategy> elements_;
59 };
60 }
Definition: bases.h:32
Sets(const Sets< Element > &sets)
Definition: sets.h:34
Definition: bases.h:97
std::function< bool(Product)> Requirement
Definition: sieve.h:12
Definition: sets.h:16
std::set< Element > operator()() const override
Definition: sets.h:41
std::unique_ptr< Strategy< std::set< Element > > > clone() const override
Definition: bases.h:99
Filtered< Value > filter(const Requirement< Value > &requirement) const override
Definition: bases.h:189
Definition: bases.h:16
Sets(const SizesStrategy &sizes, const ElementsStrategy &elements)
Definition: sets.h:24