xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::core::CountingIterator< DummyValue, Count > Class Template Reference

An iterator that can be used to count the length of an output sequence. More...

#include <xentara/utils/core/CountingIterator.hpp>

Classes

class  Sink
 a dummy object used for assigning values More...
 

Public Types

using value_type = DummyValue
 The element type.
 
using difference_type = std::make_signed_t< Count >
 The type used for distances.
 
using reference = Sink
 A reference to an element.
 
using pointer = void
 A pointer to an element.
 
using iterator_category = std::output_iterator_tag
 The iterator category, for use in pre-C++20 code.
 
using iterator_concept = std::output_iterator_tag
 The iterator concept, for use in C++20 code.
 

Public Member Functions

constexpr CountingIterator () noexcept=default
 Default constructor.
 
 CountingIterator (std::reference_wrapper< Count > count) noexcept
 Constructor.
 
constexpr auto operator++ () noexcept -> CountingIterator &
 Pre-increment operator.
 
constexpr auto operator++ (int) noexcept -> CountingIterator
 Post-increment operator.
 
constexpr auto operator-- () noexcept -> CountingIterator &
 Pre-decrement operator.
 
constexpr auto operator-- (int) noexcept -> CountingIterator
 Post-decrement operator.
 
constexpr auto operator+= (difference_type offset) noexcept -> CountingIterator &
 Addition assignment operator.
 
constexpr auto operator-= (difference_type offset) noexcept -> CountingIterator &
 Subtraction assignment operator.
 
constexpr auto operator* () const noexcept -> reference
 Indirection operator.
 
constexpr auto operator[] (difference_type) const noexcept -> reference
 Subscript operator.
 

Related Symbols

(Note that these are not member symbols.)

template<typename DummyValue , tools::Integral Count>
auto countingIterator (std::reference_wrapper< Count > count) -> CountingIterator< DummyValue, Count >
 Creates a counting iterator.
 

Detailed Description

template<typename DummyValue, tools::Integral Count = std::ptrdiff_t>
class xentara::utils::core::CountingIterator< DummyValue, Count >

An iterator that can be used to count the length of an output sequence.

This iterator simply keeps track of how many times it is incremented.

Template Parameters
DummyValueThe type of the values written. This is only used to define the embedded types, the class itself does not use the type.
CountThe type to use for the counter

Member Typedef Documentation

◆ difference_type

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::difference_type = std::make_signed_t<Count>

The type used for distances.

◆ iterator_category

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::iterator_category = std::output_iterator_tag

The iterator category, for use in pre-C++20 code.

◆ iterator_concept

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::iterator_concept = std::output_iterator_tag

The iterator concept, for use in C++20 code.

◆ pointer

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::pointer = void

A pointer to an element.

◆ reference

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::reference = Sink

A reference to an element.

◆ value_type

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
using xentara::utils::core::CountingIterator< DummyValue, Count >::value_type = DummyValue

The element type.

Constructor & Destructor Documentation

◆ CountingIterator() [1/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr xentara::utils::core::CountingIterator< DummyValue, Count >::CountingIterator ( )
constexprdefaultnoexcept

Default constructor.

This constructor creates a dummy object that doesn't actually count anything.

◆ CountingIterator() [2/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
xentara::utils::core::CountingIterator< DummyValue, Count >::CountingIterator ( std::reference_wrapper< Count >  count)
noexcept

Constructor.

Parameters
countThe counter to update

Member Function Documentation

◆ operator*()

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator* ( ) const -> reference
constexprnoexcept

Indirection operator.

Returns
A sink that descards all assigned values

◆ operator++() [1/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator++ ( ) -> CountingIterator &
constexprnoexcept

Pre-increment operator.

Increments the count by one.

◆ operator++() [2/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator++ ( int  ) -> CountingIterator
constexprnoexcept

Post-increment operator.

Increments the count by one.

◆ operator+=()

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator+= ( difference_type  offset) -> CountingIterator &
constexprnoexcept

Addition assignment operator.

Adds a certain offset to the count.

◆ operator--() [1/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator-- ( ) -> CountingIterator &
constexprnoexcept

Pre-decrement operator.

Decrements the count by one.

◆ operator--() [2/2]

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator-- ( int  ) -> CountingIterator
constexprnoexcept

Post-decrement operator.

Decrements the count by one.

◆ operator-=()

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator-= ( difference_type  offset) -> CountingIterator &
constexprnoexcept

Subtraction assignment operator.

Subtracts a certain offset from the count.

◆ operator[]()

template<typename DummyValue , tools::Integral Count = std::ptrdiff_t>
constexpr auto xentara::utils::core::CountingIterator< DummyValue, Count >::operator[] ( difference_type  ) const -> reference
constexprnoexcept

Subscript operator.

Returns
A sink that descards all assigned values

Friends And Related Symbol Documentation

◆ countingIterator()

template<typename DummyValue , tools::Integral Count>
auto countingIterator ( std::reference_wrapper< Count >  count) -> CountingIterator<DummyValue, Count>
related

Creates a counting iterator.

Parameters
countThe counter to update. If you want to pass a regular variable to update, you should wrap the variable in std::ref() to enable template type deduction.
Returns
An iterator that can be used to update the counter