Public Member Functions | Public Attributes | List of all members
WireCell::GeneratorIter< Callable, Value > Struct Template Reference

#include <GeneratorIter.h>

Inheritance diagram for WireCell::GeneratorIter< Callable, Value >:

Public Member Functions

 GeneratorIter (const Callable &func)
 
void advance ()
 
Value operator* () const
 
GeneratorIteroperator++ ()
 
GeneratorIter operator++ (int)
 
bool operator== (const GeneratorIter &rhs) const
 
bool operator!= (const GeneratorIter &rhs) const
 
 operator bool () const
 

Public Attributes

size_t count
 
Callable func
 
Value last_val
 

Detailed Description

template<typename Callable, typename Value>
struct WireCell::GeneratorIter< Callable, Value >

A generator iterator using a Callable.

Requirements on Callable

Inspired by: http://stackoverflow.com/questions/27604201/implement-lazy-generator-as-forward-iterator-in-c

Definition at line 31 of file GeneratorIter.h.

Constructor & Destructor Documentation

template<typename Callable , typename Value >
WireCell::GeneratorIter< Callable, Value >::GeneratorIter ( const Callable &  func)
inline

Definition at line 37 of file GeneratorIter.h.

Member Function Documentation

template<typename Callable , typename Value >
void WireCell::GeneratorIter< Callable, Value >::advance ( )
inline

Definition at line 42 of file GeneratorIter.h.

42  {
43  if (func) {
44  last_val = func();
45  }
46  }
template<typename Callable , typename Value >
WireCell::GeneratorIter< Callable, Value >::operator bool ( ) const
inline

Definition at line 66 of file GeneratorIter.h.

66  {
67  return func;
68  }
template<typename Callable , typename Value >
bool WireCell::GeneratorIter< Callable, Value >::operator!= ( const GeneratorIter< Callable, Value > &  rhs) const
inline

Definition at line 62 of file GeneratorIter.h.

62  {
63  return !(*this == rhs);
64  }
template<typename Callable , typename Value >
Value WireCell::GeneratorIter< Callable, Value >::operator* ( ) const
inline

Definition at line 47 of file GeneratorIter.h.

47  {
48  return last_val;
49  }
template<typename Callable , typename Value >
GeneratorIter& WireCell::GeneratorIter< Callable, Value >::operator++ ( )
inline

Definition at line 50 of file GeneratorIter.h.

50  {
51  advance();
52  return *this;
53  }
template<typename Callable , typename Value >
GeneratorIter WireCell::GeneratorIter< Callable, Value >::operator++ ( int  )
inline

Definition at line 54 of file GeneratorIter.h.

54  {
55  GeneratorIter res = *this;
56  advance();
57  return res;
58  }
GeneratorIter(const Callable &func)
Definition: GeneratorIter.h:37
template<typename Callable , typename Value >
bool WireCell::GeneratorIter< Callable, Value >::operator== ( const GeneratorIter< Callable, Value > &  rhs) const
inline

Definition at line 59 of file GeneratorIter.h.

59  {
60  return (!func && !rhs.func) || (func == rhs.func && count == rhs.count);
61  }

Member Data Documentation

template<typename Callable , typename Value >
size_t WireCell::GeneratorIter< Callable, Value >::count

Definition at line 70 of file GeneratorIter.h.

template<typename Callable , typename Value >
Callable WireCell::GeneratorIter< Callable, Value >::func

Definition at line 71 of file GeneratorIter.h.

template<typename Callable , typename Value >
Value WireCell::GeneratorIter< Callable, Value >::last_val

Definition at line 72 of file GeneratorIter.h.


The documentation for this struct was generated from the following file: