From ebf09aceb23f1ae3a2b5442b4560e68abe24865f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 23 Sep 2025 14:26:58 -0400 Subject: [PATCH] Further extend. This is becoming more of a SizedInt. --- Numeric/SizedCounter.hpp | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Numeric/SizedCounter.hpp b/Numeric/SizedCounter.hpp index f9f9b722c..96784c81c 100644 --- a/Numeric/SizedCounter.hpp +++ b/Numeric/SizedCounter.hpp @@ -28,20 +28,35 @@ struct SizedCounter { return counter_; } - SizedCounter operator +(const SizedCounter offset) const { - return SizedCounter(counter_ + offset.counter_); + SizedCounter operator +(const SizedCounter offset) const { return SizedCounter(counter_ + offset.counter_); } + SizedCounter operator -(const SizedCounter offset) const { return SizedCounter(counter_ - offset.counter_); } + SizedCounter operator &(const SizedCounter offset) const { return SizedCounter(counter_ & offset.counter_); } + SizedCounter operator |(const SizedCounter offset) const { return SizedCounter(counter_ | offset.counter_); } + SizedCounter operator ^(const SizedCounter offset) const { return SizedCounter(counter_ ^ offset.counter_); } + SizedCounter operator >>(const int shift) const { return SizedCounter(counter_ >> shift); } + SizedCounter operator <<(const int shift) const { return SizedCounter(counter_ << shift); } + + SizedCounter &operator &=(const SizedCounter offset) { + counter_ &= offset.counter_; + return *this; + } + SizedCounter &operator |=(const SizedCounter offset) { + counter_ |= offset.counter_; + return *this; + } + SizedCounter &operator ^=(const SizedCounter offset) { + counter_ ^= offset.counter_; + return *this; } - SizedCounter operator &(const SizedCounter offset) const { - return SizedCounter(counter_ & offset.counter_); + SizedCounter &operator <<=(const int shift) { + counter_ = (counter_ << shift) & Mask; + return *this; } - SizedCounter operator >>(const int shift) const { - return SizedCounter(counter_ >> shift); - } - - SizedCounter operator <<(const int shift) const { - return SizedCounter(counter_ << shift); + SizedCounter &operator >>=(const int shift) { + counter_ >>= shift; + return *this; } SizedCounter &operator ++(int) { @@ -78,6 +93,12 @@ struct SizedCounter { load(value); } + template + requires (index < bits) + bool bit() { + return counter_ & (1 << index); + } + private: IntT counter_{}; };