Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT > Class Template Reference

Internal helper class: actual implementation of nested iterator. More...

#include <NestedIterator.h>

Inheritance diagram for lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >:

Classes

struct  BeginPositionTag
 
struct  EndPositionTag
 

Public Types

using OuterIterator_t = ITER
 
using InnerContainerExtractor_t = INNERCONTEXTRACT
 
using InnerContainer_t = typename InnerContainerExtractor_t::result_type
 
using InnerIterator_t = typename InnerContainer_t::const_iterator
 
using iterator_type = deep_const_fwd_iterator_nested< OuterIterator_t, InnerContainerExtractor_t >
 
using value_type = typename InnerIterator_t::value_type
 Type of the value pointed by the iterator. More...
 

Public Member Functions

 deep_const_fwd_iterator_nested ()=default
 Default constructor: invalid iterator. More...
 
 deep_const_fwd_iterator_nested (OuterIterator_t src, OuterIterator_t end)
 Constructor: starts from the container at the specified iterator. More...
 
template<class CONT >
 deep_const_fwd_iterator_nested (const CONT &cont, BeginPositionTag)
 Constructor: starts from the beginning of the specified container. More...
 
template<class CONT >
 deep_const_fwd_iterator_nested (const CONT &cont, EndPositionTag)
 Constructor: starts from the end of the specified container. More...
 
iterator_typeoperator++ ()
 Prefix increment operator: points to the next element. More...
 
iterator_type operator++ (int)
 Postfix increment operator: points to the next element. More...
 
void swap (iterator_type &with)
 Swaps this with the specified iterator. More...
 
Dereference operators
const value_typeoperator* () const
 
const value_typeoperator-> () const
 
Comparison operators

Returns true if the two iterators are equivalent

bool operator== (const iterator_type &as) const
 
bool operator!= (const iterator_type &as) const
 Returns true if the two iterators are not equivalent. More...
 
 operator bool () const
 Bonus: convert to bool to find out if we are at the end. More...
 
bool operator! () const
 

Static Public Attributes

static constexpr BeginPositionTag begin = {}
 
static constexpr EndPositionTag end = {}
 

Protected Member Functions

 deep_const_fwd_iterator_nested (OuterIterator_t end)
 Internal constructor: past-the-end iterator pointing to specified place. More...
 

Protected Attributes

OuterIterator_t outer_iter
 points to current inner container More...
 
OuterIterator_t outer_end
 points to past-the-end inner container More...
 
InnerIterator_t inner_iter
 points to the current element More...
 
InnerIterator_t inner_end
 stores the end of current inner container More...
 

Private Member Functions

void init_inner ()
 
void reset_inner ()
 
void skip_empty ()
 points to the next item More...
 
bool is_end () const
 
const InnerContainerExtractor_t::result_type & extract_container (const typename OuterIterator_t::value_type &v)
 Extracts the value out of the inner iterator. More...
 

Detailed Description

template<typename ITER, typename INNERCONTEXTRACT>
class lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >

Internal helper class: actual implementation of nested iterator.

Definition at line 59 of file NestedIterator.h.

Member Typedef Documentation

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerContainer_t = typename InnerContainerExtractor_t::result_type

Definition at line 157 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerContainerExtractor_t = INNERCONTEXTRACT

Definition at line 156 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::InnerIterator_t = typename InnerContainer_t::const_iterator

Definition at line 160 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::iterator_type = deep_const_fwd_iterator_nested <OuterIterator_t, InnerContainerExtractor_t>

Definition at line 164 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::OuterIterator_t = ITER

Definition at line 155 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
using lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::value_type = typename InnerIterator_t::value_type

Type of the value pointed by the iterator.

Definition at line 167 of file NestedIterator.h.

Constructor & Destructor Documentation

template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( )
default

Default constructor: invalid iterator.

This constructor sets the iterator in an invalid, end-of-container state.

template<typename ITER , typename INNERCONTEXTRACT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( OuterIterator_t  src,
OuterIterator_t  end 
)

Constructor: starts from the container at the specified iterator.

Parameters
srcthe starting point of the iterator
endthe end point of the iterator

This constructor does not set and end. Due to how the class works, if the outer container has an "end", reaching it with this iterator has a undefined behaviour. You most likely want to use the constructor where you can also specify the end of the container.

Definition at line 323 of file NestedIterator.h.

323  :
324  outer_iter(src), outer_end(end)
325  {
326  if (is_end()) return;
327  init_inner();
328  skip_empty();
329  } // deep_const_fwd_iterator_nested(OuterIterator_t, OuterIterator_t)
OuterIterator_t outer_iter
points to current inner container
OuterIterator_t outer_end
points to past-the-end inner container
static constexpr EndPositionTag end
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
template<class CONT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( const CONT &  cont,
BeginPositionTag   
)
inline

Constructor: starts from the beginning of the specified container.

Parameters
contthe container
[anonymous]tag to select the begin-of-container behaviour

The second parameter is used just to choose which constructor to use. Two constants are provided, begin and end, defined in the iterator itself (no explicit namespace is required). Example:

using Data_t = std::vector<std::vector<float>>;
Data_t data(5, { 1., 3., 5. });
deep_const_fwd_iterator_nested<Data_t::const_iterator> iData(data, begin),
data_end(data, end);

Definition at line 212 of file NestedIterator.h.

212  :
214  { skip_empty(); }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
template<class CONT >
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( const CONT &  cont,
EndPositionTag   
)
inline

Constructor: starts from the end of the specified container.

Parameters
contthe container
[anonymous]tag to select the end-of-container behaviour

The second parameter is used just to choose which constructor to use. Two constants are provided, begin and end, defined in the iterator itself (no explicit namespace is required). Example:

using Data_t = std::vector<std::vector<float>>;
Data_t data(5, { 1., 3., 5. });
deep_const_fwd_iterator_nested<Data_t::const_iterator> iData(data, begin),
data_end(data, end);

Definition at line 233 of file NestedIterator.h.

233  :
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::deep_const_fwd_iterator_nested ( OuterIterator_t  end)
inlineprotected

Internal constructor: past-the-end iterator pointing to specified place.

Definition at line 298 of file NestedIterator.h.

298  :
deep_const_fwd_iterator_nested()=default
Default constructor: invalid iterator.
static constexpr EndPositionTag end

Member Function Documentation

template<typename ITER, typename INNERCONTEXTRACT>
const InnerContainerExtractor_t::result_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::extract_container ( const typename OuterIterator_t::value_type &  v)
inlineprivate

Extracts the value out of the inner iterator.

Definition at line 310 of file NestedIterator.h.

311  { return InnerContainerExtractor_t()(v); }
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::init_inner ( )
private

Definition at line 353 of file NestedIterator.h.

353  {
356  } // deep_const_fwd_iterator_nested<>::init_inner()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
InnerIterator_t inner_iter
points to the current element
const InnerContainerExtractor_t::result_type & extract_container(const typename OuterIterator_t::value_type &v)
Extracts the value out of the inner iterator.
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::is_end ( ) const
inlineprivate

Definition at line 306 of file NestedIterator.h.

306 { return outer_iter == outer_end; }
OuterIterator_t outer_iter
points to current inner container
OuterIterator_t outer_end
points to past-the-end inner container
template<typename ITER, typename INNERCONTEXTRACT>
lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator bool ( ) const
inline

Bonus: convert to bool to find out if we are at the end.

Returns
whether this operator is past-the-end

Definition at line 283 of file NestedIterator.h.

283 { return !is_end(); }
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator! ( ) const
inline

Definition at line 284 of file NestedIterator.h.

284 { return is_end(); }
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator!= ( const iterator_type as) const
inline

Returns true if the two iterators are not equivalent.

Definition at line 270 of file NestedIterator.h.

271  {
272  return (as.outer_iter != outer_iter)
273  || ((as.inner_iter != inner_iter) && (!is_end() || !as.is_end()));
274  }
InnerIterator_t inner_iter
points to the current element
OuterIterator_t outer_iter
points to current inner container
static constexpr double as
Definition: Units.h:101
template<typename ITER, typename INNERCONTEXTRACT>
const value_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator* ( ) const
inline

Definition at line 257 of file NestedIterator.h.

257 { return *inner_iter; }
InnerIterator_t inner_iter
points to the current element
template<typename ITER , typename INNERCONTEXTRACT >
deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT > & lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator++ ( )

Prefix increment operator: points to the next element.

Returns
this iterator, already incremented

The behaviour of this method on a past-the-end iterator is undefined (currently, chances are it will access invalid memory).

Definition at line 334 of file NestedIterator.h.

334  {
335  ++inner_iter;
336  skip_empty();
337  return *this;
338  } // deep_const_fwd_iterator_nested<>::operator++()
InnerIterator_t inner_iter
points to the current element
void skip_empty()
points to the next item
template<typename ITER, typename INNERCONTEXTRACT>
iterator_type lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator++ ( int  )
inline

Postfix increment operator: points to the next element.

Returns
a copy of this iterator before the increment

The behaviour of this method on a past-the-end iterator is undefined (currently, chances are it will access invalid memory).

Definition at line 252 of file NestedIterator.h.

253  { iterator_type old(*this); this->operator++(); return old; }
iterator_type & operator++()
Prefix increment operator: points to the next element.
deep_const_fwd_iterator_nested< OuterIterator_t, InnerContainerExtractor_t > iterator_type
template<typename ITER, typename INNERCONTEXTRACT>
const value_type& lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator-> ( ) const
inline

Definition at line 258 of file NestedIterator.h.

258 { return *inner_iter; }
InnerIterator_t inner_iter
points to the current element
template<typename ITER, typename INNERCONTEXTRACT>
bool lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::operator== ( const iterator_type as) const
inline

Definition at line 264 of file NestedIterator.h.

265  {
266  return (as.outer_iter == outer_iter)
267  && ((as.inner_iter == inner_iter) || (is_end() && as.is_end()));
268  }
InnerIterator_t inner_iter
points to the current element
OuterIterator_t outer_iter
points to current inner container
static constexpr double as
Definition: Units.h:101
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::reset_inner ( )
private

Definition at line 360 of file NestedIterator.h.

361  { inner_end = inner_iter = {}; }
InnerIterator_t inner_iter
points to the current element
InnerIterator_t inner_end
stores the end of current inner container
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::skip_empty ( )
private

points to the next item

Definition at line 364 of file NestedIterator.h.

364  {
365  while(inner_iter == inner_end) {
366  ++outer_iter;
367  if (is_end()) {
368  reset_inner();
369  return;
370  } // if
371  init_inner();
372  } // while inner iterator ended
373  } // skip_empty()
InnerIterator_t inner_iter
points to the current element
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
template<typename ITER , typename INNERCONTEXTRACT >
void lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::swap ( iterator_type with)

Swaps this with the specified iterator.

Definition at line 343 of file NestedIterator.h.

344  {
345  std::swap(outer_iter, with.outer_iter);
346  std::swap(outer_end, with.outer_end);
347  std::swap(inner_iter, with.inner_iter);
348  std::swap(inner_end, with.inner_end);
349  } // deep_const_fwd_iterator_nested<>::swap()
InnerIterator_t inner_iter
points to the current element
InnerIterator_t inner_end
stores the end of current inner container
OuterIterator_t outer_iter
points to current inner container
OuterIterator_t outer_end
points to past-the-end inner container
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)

Member Data Documentation

template<typename ITER, typename INNERCONTEXTRACT>
constexpr BeginPositionTag lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::begin = {}
static

Definition at line 173 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
constexpr EndPositionTag lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::end = {}
static

Definition at line 174 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
InnerIterator_t lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_end
protected

stores the end of current inner container

Definition at line 295 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
InnerIterator_t lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::inner_iter
protected

points to the current element

Definition at line 294 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
OuterIterator_t lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_end
protected

points to past-the-end inner container

Definition at line 292 of file NestedIterator.h.

template<typename ITER, typename INNERCONTEXTRACT>
OuterIterator_t lar::deep_const_fwd_iterator_nested< ITER, INNERCONTEXTRACT >::outer_iter
protected

points to current inner container

Definition at line 291 of file NestedIterator.h.


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