Version: SMASH-3.1
smash::Particles::GenericIterator< T > Class Template Reference

#include <particles.h>

template<typename T>
class smash::Particles::GenericIterator< T >

Iterator type that skips over the holes in data_. It implements a standard bidirectional iterator over the ParticleData objects in Particles. Each iterator must expose 5 types to correctly interact with the STL:

  • iterator_category
  • value_type
  • difference_type
  • pointer
  • reference

Prior to C++17 it was common habit to inherit from std::iterator to simplify the implementation of user-defined iterators, but this turned out not to be the most readable choice and this habit has been deprecated in C++17. It is simply better to explicitly expose the 5 types.

Definition at line 245 of file particles.h.

Public Types

using iterator_category = std::bidirectional_iterator_tag
 Required by STL: expose iterator_category More...
 
using value_type = std::remove_const_t< T >
 Required by STL: expose value_type removing const qualification More...
 
using difference_type = std::ptrdiff_t
 Required by STL: expose difference_type More...
 
using pointer = std::add_pointer_t< T >
 Required by STL: expose pointer (of a reference) More...
 
using reference = std::add_lvalue_reference_t< T >
 Required by STL: expose reference (lvalue) More...
 
using const_pointer = std::add_const_t< pointer >
 add const qualification to a pointer More...
 
using const_reference = std::add_const_t< reference >
 add const qualification to a reference More...
 

Public Member Functions

GenericIteratoroperator++ ()
 Advance the iterator to the next valid (not a hole) entry in Particles. More...
 
GenericIterator operator++ (int)
 Postfix variant of the above prefix increment operator. More...
 
GenericIteratoroperator-- ()
 Advance the iterator to the previous valid (not a hole) entry in Particles. More...
 
GenericIterator operator-- (int)
 Postfix variant of the above prefix decrement operator. More...
 
reference operator* ()
 
const_reference operator* () const
 
pointer operator-> ()
 
const_pointer operator-> () const
 
bool operator== (const GenericIterator &rhs) const
 
bool operator!= (const GenericIterator &rhs) const
 
bool operator< (const GenericIterator &rhs) const
 
bool operator> (const GenericIterator &rhs) const
 
bool operator<= (const GenericIterator &rhs) const
 
bool operator>= (const GenericIterator &rhs) const
 

Private Member Functions

 GenericIterator (pointer p)
 Constructs an iterator pointing to the ParticleData pointed to by p. More...
 

Private Attributes

pointer ptr_
 The entry in Particles this iterator points to. More...
 

Friends

class Particles
 

Member Typedef Documentation

◆ iterator_category

template<typename T >
using smash::Particles::GenericIterator< T >::iterator_category = std::bidirectional_iterator_tag

Required by STL: expose iterator_category

Definition at line 250 of file particles.h.

◆ value_type

template<typename T >
using smash::Particles::GenericIterator< T >::value_type = std::remove_const_t<T>

Required by STL: expose value_type removing const qualification

Definition at line 252 of file particles.h.

◆ difference_type

template<typename T >
using smash::Particles::GenericIterator< T >::difference_type = std::ptrdiff_t

Required by STL: expose difference_type

Definition at line 254 of file particles.h.

◆ pointer

template<typename T >
using smash::Particles::GenericIterator< T >::pointer = std::add_pointer_t<T>

Required by STL: expose pointer (of a reference)

Definition at line 256 of file particles.h.

◆ reference

template<typename T >
using smash::Particles::GenericIterator< T >::reference = std::add_lvalue_reference_t<T>

Required by STL: expose reference (lvalue)

Definition at line 258 of file particles.h.

◆ const_pointer

template<typename T >
using smash::Particles::GenericIterator< T >::const_pointer = std::add_const_t<pointer>

add const qualification to a pointer

Definition at line 260 of file particles.h.

◆ const_reference

template<typename T >
using smash::Particles::GenericIterator< T >::const_reference = std::add_const_t<reference>

add const qualification to a reference

Definition at line 262 of file particles.h.

Constructor & Destructor Documentation

◆ GenericIterator()

template<typename T >
smash::Particles::GenericIterator< T >::GenericIterator ( pointer  p)
inlineprivate

Constructs an iterator pointing to the ParticleData pointed to by p.

This constructor may only be called from the Particles class.

Parameters
[in]pThe particle which is pointed by the iterator.

Definition at line 271 of file particles.h.

271 : ptr_(p) {} // NOLINT(runtime/explicit)
pointer ptr_
The entry in Particles this iterator points to.
Definition: particles.h:274
constexpr int p
Proton.

Member Function Documentation

◆ operator++() [1/2]

template<typename T >
GenericIterator& smash::Particles::GenericIterator< T >::operator++ ( )
inline

Advance the iterator to the next valid (not a hole) entry in Particles.

Holes are identified by the ParticleData::hole_ member and thus the internal pointer is incremented until all holes are skipped. It is important that the Particles entry pointed to by Particles::end() is not identified as a hole as otherwise the iterator would advance too far.

Returns
the iterator to the next valid particle.

Definition at line 286 of file particles.h.

286  {
287  do {
288  ++ptr_;
289  } while (ptr_->hole_);
290  return *this;
291  }

◆ operator++() [2/2]

template<typename T >
GenericIterator smash::Particles::GenericIterator< T >::operator++ ( int  )
inline

Postfix variant of the above prefix increment operator.

Returns
the iterator before increment.

Definition at line 297 of file particles.h.

297  {
298  GenericIterator old = *this;
299  operator++();
300  return old;
301  }
GenericIterator & operator++()
Advance the iterator to the next valid (not a hole) entry in Particles.
Definition: particles.h:286
GenericIterator(pointer p)
Constructs an iterator pointing to the ParticleData pointed to by p.
Definition: particles.h:271

◆ operator--() [1/2]

template<typename T >
GenericIterator& smash::Particles::GenericIterator< T >::operator-- ( )
inline

Advance the iterator to the previous valid (not a hole) entry in Particles.

Holes are identified by the ParticleData::hole_ member and thus the internal pointer is decremented until all holes are skipped. It is irrelevant whether Particles::data_[0] is a hole because the iteration typically ends at Particles::begin(), which points to a non-hole entry in Particles::data_.

Returns
the iterator to the previous valid particle.

Definition at line 314 of file particles.h.

314  {
315  do {
316  --ptr_;
317  } while (ptr_->hole_);
318  return *this;
319  }

◆ operator--() [2/2]

template<typename T >
GenericIterator smash::Particles::GenericIterator< T >::operator-- ( int  )
inline

Postfix variant of the above prefix decrement operator.

Returns
the iterator before decrement.

Definition at line 325 of file particles.h.

325  {
326  GenericIterator old = *this;
327  operator--();
328  return old;
329  }
GenericIterator & operator--()
Advance the iterator to the previous valid (not a hole) entry in Particles.
Definition: particles.h:314

◆ operator*() [1/2]

template<typename T >
reference smash::Particles::GenericIterator< T >::operator* ( )
inline
Returns
the dereferenced iterator.

Definition at line 332 of file particles.h.

332 { return *ptr_; }

◆ operator*() [2/2]

template<typename T >
const_reference smash::Particles::GenericIterator< T >::operator* ( ) const
inline
Returns
the dereferenced iterator.

Definition at line 334 of file particles.h.

334 { return *ptr_; }

◆ operator->() [1/2]

template<typename T >
pointer smash::Particles::GenericIterator< T >::operator-> ( )
inline
Returns
the dereferenced iterator.

Definition at line 337 of file particles.h.

337 { return ptr_; }

◆ operator->() [2/2]

template<typename T >
const_pointer smash::Particles::GenericIterator< T >::operator-> ( ) const
inline
Returns
the dereferenced iterator.

Definition at line 339 of file particles.h.

339 { return ptr_; }

◆ operator==()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator== ( const GenericIterator< T > &  rhs) const
inline
Returns
whether two iterators point to the same object.

Definition at line 342 of file particles.h.

342  {
343  return ptr_ == rhs.ptr_;
344  }

◆ operator!=()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator!= ( const GenericIterator< T > &  rhs) const
inline
Returns
whether two iterators point to different objects.

Definition at line 346 of file particles.h.

346  {
347  return ptr_ != rhs.ptr_;
348  }

◆ operator<()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator< ( const GenericIterator< T > &  rhs) const
inline
Returns
whether this iterator comes before the iterator rhs.

Definition at line 350 of file particles.h.

350 { return ptr_ < rhs.ptr_; }

◆ operator>()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator> ( const GenericIterator< T > &  rhs) const
inline
Returns
whether this iterator comes after the iterator rhs.

Definition at line 352 of file particles.h.

352 { return ptr_ > rhs.ptr_; }

◆ operator<=()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator<= ( const GenericIterator< T > &  rhs) const
inline
Returns
whether this iterator comes before the iterator rhs or points to the same object.

Definition at line 357 of file particles.h.

357  {
358  return ptr_ <= rhs.ptr_;
359  }

◆ operator>=()

template<typename T >
bool smash::Particles::GenericIterator< T >::operator>= ( const GenericIterator< T > &  rhs) const
inline
Returns
whether this iterator comes after the iterator rhs or points to the same object.

Definition at line 364 of file particles.h.

364  {
365  return ptr_ >= rhs.ptr_;
366  }

Friends And Related Function Documentation

◆ Particles

template<typename T >
friend class Particles
friend

Definition at line 246 of file particles.h.

Member Data Documentation

◆ ptr_

template<typename T >
pointer smash::Particles::GenericIterator< T >::ptr_
private

The entry in Particles this iterator points to.

Definition at line 274 of file particles.h.


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