10 #ifndef STRONG_TYPEDEF_TYPE_HPP
11 #define STRONG_TYPEDEF_TYPE_HPP
13 #include "../3rdparty/fmt/format.h"
18 namespace StrongType {
23 template <
typename TType,
typename TBaseType>
25 friend constexpr
bool operator ==(
const TType &lhs,
const TType &rhs) {
return lhs.value == rhs.value; }
26 friend constexpr
bool operator ==(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value == rhs; }
28 friend constexpr
bool operator !=(
const TType &lhs,
const TType &rhs) {
return lhs.value != rhs.value; }
29 friend constexpr
bool operator !=(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value != rhs; }
31 friend constexpr
bool operator <=(
const TType &lhs,
const TType &rhs) {
return lhs.value <= rhs.value; }
32 friend constexpr
bool operator <=(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value <= rhs; }
34 friend constexpr
bool operator <(
const TType &lhs,
const TType &rhs) {
return lhs.value < rhs.value; }
35 friend constexpr
bool operator <(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value < rhs; }
37 friend constexpr
bool operator >=(
const TType &lhs,
const TType &rhs) {
return lhs.value >= rhs.value; }
38 friend constexpr
bool operator >=(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value >= rhs; }
40 friend constexpr
bool operator >(
const TType &lhs,
const TType &rhs) {
return lhs.value > rhs.value; }
41 friend constexpr
bool operator >(
const TType &lhs,
const TBaseType &rhs) {
return lhs.value > rhs; }
53 template <
typename TType,
typename TBaseType>
55 friend constexpr TType &operator ++(TType &lhs) { lhs.value++;
return lhs; }
56 friend constexpr TType &operator --(TType &lhs) { lhs.value--;
return lhs; }
57 friend constexpr TType operator ++(TType &lhs,
int) { TType res = lhs; lhs.value++;
return res; }
58 friend constexpr TType operator --(TType &lhs,
int) { TType res = lhs; lhs.value--;
return res; }
60 friend constexpr TType &operator +=(TType &lhs,
const TType &rhs) { lhs.value += rhs.value;
return lhs; }
61 friend constexpr TType operator +(
const TType &lhs,
const TType &rhs) {
return TType{ lhs.value + rhs.value }; }
62 friend constexpr TType operator +(
const TType &lhs,
const TBaseType &rhs) {
return TType{ lhs.value + rhs }; }
64 friend constexpr TType &operator -=(TType &lhs,
const TType &rhs) { lhs.value -= rhs.value;
return lhs; }
65 friend constexpr TType operator -(
const TType &lhs,
const TType &rhs) {
return TType{ lhs.value - rhs.value }; }
66 friend constexpr TType operator -(
const TType &lhs,
const TBaseType &rhs) {
return TType{ lhs.value - rhs }; }
74 constexpr TType &operator *=(
const TType &rhs) =
delete;
75 constexpr TType operator *(
const TType &rhs) =
delete;
76 constexpr TType operator *(
const TBaseType &rhs) =
delete;
78 constexpr TType &operator /=(
const TType &rhs) =
delete;
79 constexpr TType operator /(
const TType &rhs) =
delete;
80 constexpr TType operator /(
const TBaseType &rhs) =
delete;
82 constexpr TType &operator %=(
const TType &rhs) =
delete;
83 constexpr TType operator %(
const TType &rhs) =
delete;
84 constexpr TType operator %(
const TBaseType &rhs) =
delete;
86 constexpr TType &operator &=(
const TType &rhs) =
delete;
87 constexpr TType operator &(
const TType &rhs) =
delete;
88 constexpr TType operator &(
const TBaseType &rhs) =
delete;
90 constexpr TType &operator |=(
const TType &rhs) =
delete;
91 constexpr TType operator |(
const TType &rhs) =
delete;
92 constexpr TType operator |(
const TBaseType &rhs) =
delete;
94 constexpr TType &operator ^=(
const TType &rhs) =
delete;
95 constexpr TType operator ^(
const TType &rhs) =
delete;
96 constexpr TType operator ^(
const TBaseType &rhs) =
delete;
98 constexpr TType &operator <<=(
const TType &rhs) =
delete;
99 constexpr TType operator <<(
const TType &rhs) =
delete;
100 constexpr TType operator <<(
const TBaseType &rhs) =
delete;
102 constexpr TType &operator >>=(
const TType &rhs) =
delete;
103 constexpr TType operator >>(
const TType &rhs) =
delete;
104 constexpr TType operator >>(
const TBaseType &rhs) =
delete;
106 constexpr TType operator ~() =
delete;
107 constexpr TType operator -() =
delete;
118 template <
typename TCompatibleType>
120 template <
typename TType,
typename TBaseType>
122 friend constexpr
bool operator ==(
const TType &lhs, TCompatibleType rhs) {
return lhs.value ==
static_cast<TBaseType
>(rhs); }
123 friend constexpr
bool operator !=(
const TType &lhs, TCompatibleType rhs) {
return lhs.value !=
static_cast<TBaseType
>(rhs); }
125 friend constexpr
bool operator <=(
const TType &lhs, TCompatibleType rhs) {
return lhs.value <=
static_cast<TBaseType
>(rhs); }
126 friend constexpr
bool operator <(
const TType &lhs, TCompatibleType rhs) {
return lhs.value <
static_cast<TBaseType
>(rhs); }
127 friend constexpr
bool operator >=(
const TType &lhs, TCompatibleType rhs) {
return lhs.value >=
static_cast<TBaseType
>(rhs); }
128 friend constexpr
bool operator >(
const TType &lhs, TCompatibleType rhs) {
return lhs.value >
static_cast<TBaseType
>(rhs); }
130 friend constexpr TType operator +(
const TType &lhs, TCompatibleType rhs) {
return {
static_cast<TBaseType
>(lhs.value + rhs) }; }
131 friend constexpr TType operator -(
const TType &lhs, TCompatibleType rhs) {
return {
static_cast<TBaseType
>(lhs.value - rhs) }; }
149 template <
typename TBaseType,
typename TTag,
typename... TProperties>
150 struct EMPTY_BASES
Typedef :
public StrongTypedefBase,
public TProperties::template mixin<Typedef<TBaseType, TTag, TProperties...>, TBaseType>... {
151 using BaseType = TBaseType;
157 constexpr
Typedef(
const TBaseType &value) : value(value) {}
159 constexpr
Typedef &operator =(
const Typedef &rhs) { this->value = rhs.value;
return *
this; }
160 constexpr
Typedef &operator =(
Typedef &&rhs) { this->value = std::move(rhs.value);
return *
this; }
161 constexpr
Typedef &operator =(
const TBaseType &rhs) { this->value = rhs;
return *
this; }
164 constexpr TBaseType base()
const {
return this->value; }
169 template <
typename TCompatibleType>
friend struct Compatible;
Mix-in which makes the new Typedef comparable with itself and its base type.
Mix-in which makes the new Typedef compatible with another type (which is not the base type).
Mix-in which makes the new Typedef behave more like an integer.
Templated helper to make a type-safe 'typedef' representing a single POD value.
Non-templated base for StrongType::Typedef for use with type trait queries.