43template <auto enumV,
typename BaseT>
46 static_assert(std::is_arithmetic_v<BaseT>,
47 "StrongType only available for arithmetic types");
49 std::is_enum_v<
decltype(enumV)>,
50 "StrongType must be instantiated with scoped enum (enum class)");
56 explicit constexpr StrongType(BaseT tv) : v(tv) {}
57 explicit constexpr operator BaseT()
const {
return v; }
58 constexpr BaseT &as_base() {
return v; }
59 [[nodiscard]]
constexpr BaseT as_base()
const {
return v; }
69 friend constexpr StrongT operator*(StrongT lhs,
const StrongT &rhs) {
72 constexpr StrongT &operator/=(
const StrongT &rhs) {
76 friend constexpr StrongT operator/(StrongT lhs,
const StrongT &rhs) {
79 constexpr StrongT &operator+=(
const StrongT &rhs) {
83 friend constexpr StrongT operator+(StrongT lhs,
const StrongT &rhs) {
86 constexpr StrongT &operator-=(
const StrongT &rhs) {
90 friend constexpr StrongT operator-(StrongT lhs,
const StrongT &rhs) {
99 friend constexpr StrongT operator*(StrongT lhs,
const BaseT &rhs) {
102 friend constexpr StrongT operator*(
const BaseT &lhs, StrongT rhs) {
113 friend constexpr StrongT operator/(StrongT lhs,
const BaseT &rhs) {
123 StrongT result(*
this);
127 constexpr StrongT &operator--() {
131 constexpr StrongT operator--(
int) {
132 StrongT result(*
this);
139 return lhs.v == rhs.v;
141 friend constexpr bool operator!=(
const StrongT &lhs,
const StrongT &rhs) {
142 return !(lhs == rhs);
144 friend constexpr bool operator<(
const StrongT &lhs,
const StrongT &rhs) {
145 return lhs.v < rhs.v;
147 friend constexpr bool operator>(
const StrongT &lhs,
const StrongT &rhs) {
150 friend constexpr bool operator<=(
const StrongT &lhs,
const StrongT &rhs) {
153 friend constexpr bool operator>=(
const StrongT &lhs,
const StrongT &rhs) {
161 friend constexpr bool operator!=(
const StrongT &lhs,
const BaseT &&rhs) {
164 friend constexpr bool operator<(
const StrongT &lhs,
const BaseT &&rhs) {
167 friend constexpr bool operator>(
const StrongT &lhs,
const BaseT &&rhs) {
170 friend constexpr bool operator<=(
const StrongT &lhs,
const BaseT &&rhs) {
173 friend constexpr bool operator>=(
const StrongT &lhs,
const BaseT &&rhs) {
176 friend constexpr bool operator==(
const BaseT &&lhs,
const StrongT &rhs) {
179 friend constexpr bool operator!=(
const BaseT &&lhs,
const StrongT &rhs) {
182 friend constexpr bool operator<(
const BaseT &&lhs,
const StrongT &rhs) {
185 friend constexpr bool operator>(
const BaseT &&lhs,
const StrongT &rhs) {
188 friend constexpr bool operator<=(
const BaseT &&lhs,
const StrongT &rhs) {
191 friend constexpr bool operator>=(
const BaseT &&lhs,
const StrongT &rhs) {
199 friend std::istream &operator>>(std::istream &is, StrongT &rhs) {
General-purpose utility library.
Definition Array.hpp:23
A light-weight easy-to-use single-file header-only template class for strong typing.
Definition StrongType.hpp:44
constexpr StrongT & operator*=(const BaseT &rhs)
Provides Base*Strong and Strong*Base operators for scalar multiplication.
Definition StrongType.hpp:95
constexpr StrongT & operator/=(const BaseT &rhs)
Provide Strong/Base, but NOT Base/Strong (still scalar multiplication).
Definition StrongType.hpp:109
constexpr StrongT & operator++()
Provides pre/post increment/decrement (++, –) operators.
Definition StrongType.hpp:118
constexpr StrongT & operator*=(const StrongT &rhs)
Provides operators for regular arithmetic operations.
Definition StrongType.hpp:65
friend std::ostream & operator<<(std::ostream &os, const StrongT &rhs)
Provides iostream interface, works as it would for BaseT.
Definition StrongType.hpp:196
friend constexpr bool operator==(const StrongT &lhs, const BaseT &&rhs)
Provides comparison operators with BaseT rvalue literals (not lvalues).
Definition StrongType.hpp:158
friend constexpr bool operator==(const StrongT &lhs, const StrongT &rhs)
Provides comparison operators.
Definition StrongType.hpp:138
BaseT BaseType
makes 'BaseType' publicly accessible
Definition StrongType.hpp:62