/* * Counter.hpp * * Created on: 22 èþë. 2019 ã. * Author: titov */ #ifndef SOURCE_COMMON_COUNTER_HPP_ #define SOURCE_COMMON_COUNTER_HPP_ template struct Counter { Counter( T max_value = T() ); explicit operator bool() const; void operator++(); void operator=( T rh ); Counter & operator=( const Counter & rh ); T value() const { return current_value; } private: T max_value; T current_value; }; template inline Counter::Counter( T max_value ) : max_value(max_value), current_value(0) {} template inline Counter::operator bool() const { return current_value == max_value; } template inline void Counter::operator++() { if( current_value < max_value ) ++current_value; } template inline void Counter::operator=( T rh ) { current_value = rh; } template inline Counter & Counter::operator=( const Counter & rh ) { max_value = rh.max_value; current_value = rh.current_value; return *this; } #endif /* SOURCE_COMMON_COUNTER_HPP_ */