105 template <
typename T,
typename Computer>
128 Computer* computer_ptr)
129 : curr_val_ptr(init_val_ptr), step_count_ptr(step_count_ptr),
130 computer_ptr(computer_ptr){};
146 : curr_val_ptr(nullptr), step_count_ptr(step_count_ptr),
147 computer_ptr(nullptr) {}
176 (*computer_ptr)(*step_count_ptr, *curr_val_ptr);
208 return *(this->step_count_ptr) == *(other.step_count_ptr);
222 return !(*
this == other);
227 size_t* step_count_ptr;
228 Computer* computer_ptr;
279 template <
typename T,
typename Computer>
class Generator {
308 Generator(
const T& init_val,
size_t iter_count, Computer&& computer)
309 : init_val(init_val), curr_step_count(0), total_iter_count(iter_count),
310 computer(
std::move(computer)),
311 begin_it(&(this->init_val), &(this->curr_step_count),
313 end_it(&(this->total_iter_count)){};
325 : init_val(other.init_val), curr_step_count(other.curr_step_count),
326 total_iter_count(other.total_iter_count), computer(other.computer),
327 begin_it(
iter_type(&(this->init_val), &(this->curr_step_count),
329 end_it(
iter_type(&(this->total_iter_count))) {}
343 this->init_val = other.init_val;
344 this->curr_step_count = other.curr_step_count;
345 this->total_iter_count = other.total_iter_count;
346 this->computer = other.computer;
348 this->begin_it =
iter_type(&(this->init_val), &(this->curr_step_count),
349 &(this->total_iter_count));
350 this->end_it =
iter_type(&(this->total_iter_count));
365 : init_val(
std::move(other.init_val)),
366 curr_step_count(
std::move(other.curr_step_count)),
367 total_iter_count(
std::move(other.total_iter_count)),
368 computer(
std::move(other.computer)),
369 begin_it(
iter_type(&(this->init_val), &(this->curr_step_count),
371 end_it(
iter_type(&(this->total_iter_count))) {}
385 this->init_val =
std::move(other.init_val);
386 this->curr_step_count =
std::move(other.curr_step_count);
387 this->total_iter_count =
std::move(other.total_iter_count);
388 this->computer =
std::move(other.computer);
390 this->begin_it =
iter_type(&(this->init_val), &(this->curr_step_count),
392 this->end_it =
iter_type(&(this->total_iter_count));
437 size_t curr_step_count;
438 size_t total_iter_count;
bool operator!=(const ComputationIterator &other) const
Inquality operator.
Definition: generator.hpp:221
A template generator that generates values from an initial value by applying a computation to the pre...
Definition: generator.hpp:279
const T * operator->() const
Member access operator to access the members of the most recently computed value. ...
Definition: generator.hpp:195
ComputationIterator(size_t *step_count_ptr)
ComputationIterator constructor that takes a pointer for the current step only.
Definition: generator.hpp:145
iter_type begin()
Return the iterator pointing to the previously computed value.
Definition: generator.hpp:421
Generator(const Generator &other)
Copy constructor.
Definition: generator.hpp:324
const T & operator*() const
Dereference operator to the get a const reference to the most recently computed value.
Definition: generator.hpp:187
Generator & operator=(Generator &&other)
Move assignment operator.
Definition: generator.hpp:384
Generator(Generator &&other)
Move constructor.
Definition: generator.hpp:364
iter_type end()
Return the end iterator.
Definition: generator.hpp:433
bool operator==(const ComputationIterator &other) const
Equality operator.
Definition: generator.hpp:207
ComputationIterator(T *init_val_ptr, size_t *step_count_ptr, Computer *computer_ptr)
ComputationIterator constructor that takes pointers for initial value, current step count and the com...
Definition: generator.hpp:127
ComputationIterator & operator++()
Pre-increment operator that computes the next value of the computation and updates step_count and cur...
Definition: generator.hpp:175
Main namespace for bnmf-algs library.
Definition: alloc_model_funcs.hpp:12
Generator(const T &init_val, size_t iter_count, Computer &&computer)
Generator constructor.
Definition: generator.hpp:308
Generator & operator=(const Generator &other)
Copy assignment operator.
Definition: generator.hpp:342
A template iterator that generates values via computation using the previous value.
Definition: generator.hpp:106