RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
Loading...
Searching...
No Matches
rush::Counter< T > Class Template Reference

A generic counter class with customizable initial value and step. More...

#include <counter.hpp>

Public Member Functions

 Counter (const T init=0, const T step=1)
 Constructor.
 
operator() ()
 Increment the counter by the step value and return the previous value.
 
operator++ ()
 Pre-increment the counter by the step value.
 
operator++ (int)
 Post-increment the counter by the step value.
 
operator+= (const int n)
 Increment the counter by n steps.
 
operator-- ()
 Pre-decrement the counter by the step value.
 
operator-- (int)
 Post-decrement the counter by the step value.
 
operator-= (const int n)
 Decrement the counter by n steps.
 
void set (const T value)
 Set the counter to a specific value.
 
void reset ()
 Reset the counter to its initial value.
 

Detailed Description

template<typename T = unsigned long>
class rush::Counter< T >

A generic counter class with customizable initial value and step.

Template Parameters
TThe type of the counter, default is unsigned long.

Constructor & Destructor Documentation

◆ Counter()

template<typename T = unsigned long>
rush::Counter< T >::Counter ( const T init = 0,
const T step = 1 )
inlineexplicit

Constructor.

Parameters
initThe initial value of the counter.
stepThe step value for each increment or decrement.

Member Function Documentation

◆ operator()()

template<typename T = unsigned long>
T rush::Counter< T >::operator() ( )
inline

Increment the counter by the step value and return the previous value.

Returns
The value of the counter before incrementing.

◆ operator++() [1/2]

template<typename T = unsigned long>
T rush::Counter< T >::operator++ ( )
inline

Pre-increment the counter by the step value.

Returns
The new value of the counter after incrementing.

◆ operator++() [2/2]

template<typename T = unsigned long>
T rush::Counter< T >::operator++ ( int )
inline

Post-increment the counter by the step value.

Returns
The value of the counter before incrementing.

◆ operator+=()

template<typename T = unsigned long>
T rush::Counter< T >::operator+= ( const int n)
inline

Increment the counter by n steps.

Parameters
nThe number of steps to increment.
Returns
The value of the counter after incrementing.

◆ operator--() [1/2]

template<typename T = unsigned long>
T rush::Counter< T >::operator-- ( )
inline

Pre-decrement the counter by the step value.

Returns
The new value of the counter after decrementing.

◆ operator--() [2/2]

template<typename T = unsigned long>
T rush::Counter< T >::operator-- ( int )
inline

Post-decrement the counter by the step value.

Returns
The value of the counter before decrementing.

◆ operator-=()

template<typename T = unsigned long>
T rush::Counter< T >::operator-= ( const int n)
inline

Decrement the counter by n steps.

Parameters
nThe number of steps to decrement.
Returns
The value of the counter after decrementing.

◆ set()

template<typename T = unsigned long>
void rush::Counter< T >::set ( const T value)
inline

Set the counter to a specific value.

Parameters
valueThe value to set the counter to.

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