cauldron  0.0.0
 All Classes Namespaces Files Functions Variables Typedefs
vectors.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 
5 #include "bases.h"
6 
7 
8 namespace cauldron {
14 template<typename Element>
15 class Vectors : public CloneHelper<std::vector<Element>, Vectors<Element>> {
18  public:
23  Vectors(const SizesStrategy &sizes,
24  const ElementsStrategy &elements) :
25  sizes_(sizes.clone()),
26  elements_(elements.clone()) {};
27 
33  Vectors(const Vectors<Element> &vectors) :
34  sizes_(vectors.sizes_->clone()),
35  elements_(vectors.elements_->clone()) {};
36 
40  std::vector<Element> operator()() const override {
41  size_t size = (*sizes_)();
42  std::vector<Element> result(size);
43  // FIXME: workaround using lambda to get producer from strategy
44  auto elements_producer = [&]() -> Element {
45  return (*elements_)();
46  };
47  std::generate_n(result.begin(),
48  size,
49  elements_producer);
50  return result;
51  }
52 
53  private:
54  std::unique_ptr<SizesStrategy> sizes_;
55  std::unique_ptr<ElementsStrategy> elements_;
56 };
57 }
Definition: bases.h:32
Vectors(const Vectors< Element > &vectors)
Definition: vectors.h:33
Definition: vectors.h:15
std::vector< Element > operator()() const override
Definition: vectors.h:40
Definition: bases.h:97
std::unique_ptr< Strategy< std::vector< Element > > > clone() const override
Definition: bases.h:99
Vectors(const SizesStrategy &sizes, const ElementsStrategy &elements)
Definition: vectors.h:23