RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
|
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. | |
T | operator() () |
Increment the counter by the step value and return the previous value. | |
T | operator++ () |
Pre-increment the counter by the step value. | |
T | operator++ (int) |
Post-increment the counter by the step value. | |
T | operator+= (const int n) |
Increment the counter by n steps. | |
T | operator-- () |
Pre-decrement the counter by the step value. | |
T | operator-- (int) |
Post-decrement the counter by the step value. | |
T | 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. | |
A generic counter class with customizable initial value and step.
T | The type of the counter, default is unsigned long. |
|
inlineexplicit |
Constructor.
init | The initial value of the counter. |
step | The step value for each increment or decrement. |
|
inline |
Increment the counter by the step value and return the previous value.
|
inline |
Pre-increment the counter by the step value.
|
inline |
Post-increment the counter by the step value.
|
inline |
Increment the counter by n steps.
n | The number of steps to increment. |
|
inline |
Pre-decrement the counter by the step value.
|
inline |
Post-decrement the counter by the step value.
|
inline |
Decrement the counter by n steps.
n | The number of steps to decrement. |
|
inline |
Set the counter to a specific value.
value | The value to set the counter to. |