Created
April 14, 2017 22:53
-
-
Save exjam/301649036ab7900a03a707719188bccb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Type> | |
class be_val | |
{ | |
public: | |
be_val() | |
{ | |
} | |
be_val(Type x) | |
{ | |
mStorage = x; | |
} | |
Type value() const | |
{ | |
return mStorage; // byte_swap(storage) | |
} | |
operator Type() const | |
{ | |
return value(); | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() == std::declval<const OtherType>())> | |
bool operator ==(const OtherType &other) const | |
{ | |
return value() == other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() != std::declval<const OtherType>())> | |
bool operator !=(const OtherType &other) const | |
{ | |
return value() != other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() >= std::declval<const OtherType>())> | |
bool operator >=(const OtherType &other) const | |
{ | |
return value() >= other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() <= std::declval<const OtherType>())> | |
bool operator <=(const OtherType &other) const | |
{ | |
return value() <= other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() > std::declval<const OtherType>())> | |
bool operator >(const OtherType &other) const | |
{ | |
return value() > other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() < std::declval<const OtherType>())> | |
bool operator <(const OtherType &other) const | |
{ | |
return value() < other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() + std::declval<const OtherType>())> | |
Type operator +(const OtherType &other) const | |
{ | |
return value() + other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() - std::declval<const OtherType>())> | |
Type operator -(const OtherType &other) const | |
{ | |
return value() - other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() * std::declval<const OtherType>())> | |
Type operator *(const OtherType &other) const | |
{ | |
return value() * other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() / std::declval<const OtherType>())> | |
Type operator /(const OtherType &other) const | |
{ | |
return value() / other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() % std::declval<const OtherType>())> | |
Type operator %(const OtherType &other) const | |
{ | |
return value() % other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() | std::declval<const OtherType>())> | |
Type operator |(const OtherType &other) const | |
{ | |
return value() | other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() & std::declval<const OtherType>())> | |
Type operator &(const OtherType &other) const | |
{ | |
return value() & other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() ^ std::declval<const OtherType>())> | |
Type operator ^(const OtherType &other) const | |
{ | |
return value() ^ other; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() + std::declval<const OtherType>())> | |
be_val &operator +=(const OtherType &other) | |
{ | |
*this = value() + other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() - std::declval<const OtherType>())> | |
be_val &operator -=(const OtherType &other) | |
{ | |
*this = value() - other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() * std::declval<const OtherType>())> | |
be_val &operator *=(const OtherType &other) | |
{ | |
*this = value() * other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() / std::declval<const OtherType>())> | |
be_val &operator /=(const OtherType &other) | |
{ | |
*this = value() / other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() % std::declval<const OtherType>())> | |
be_val &operator %=(const OtherType &other) | |
{ | |
*this = value() % other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() | std::declval<const OtherType>())> | |
be_val &operator |=(const OtherType &other) | |
{ | |
*this = value() | other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() & std::declval<const OtherType>())> | |
be_val &operator &=(const OtherType &other) | |
{ | |
*this = value() & other; | |
return *this; | |
} | |
template<typename OtherType, typename = decltype(std::declval<const Type>() ^ std::declval<const OtherType>())> | |
be_val &operator ^=(const OtherType &other) | |
{ | |
*this = value() ^ other; | |
return *this; | |
} | |
template<typename = decltype(std::declval<const Type>() + 1)> | |
be_val &operator ++() | |
{ | |
*this = value() + 1; | |
return *this; | |
} | |
template<typename = decltype(std::declval<const Type>() + 1)> | |
be_val operator ++(int) | |
{ | |
auto before = *this; | |
*this = value() + 1; | |
return before; | |
} | |
template<typename = decltype(std::declval<const Type>() - 1)> | |
be_val &operator --() | |
{ | |
*this = value() - 1; | |
return *this; | |
} | |
template<typename = decltype(std::declval<const Type>() - 1)> | |
be_val operator --(int) | |
{ | |
auto before = *this; | |
*this = value() - 1; | |
return before; | |
} | |
template<typename = decltype(std::declval<Type>().operator ->())> | |
auto operator ->() -> decltype(std::declval<Type>().operator ->()) | |
{ | |
return value().operator ->(); | |
} | |
template<typename = decltype(std::declval<const Type>().operator ->())> | |
auto operator ->() const -> decltype(std::declval<const Type>().operator ->()) | |
{ | |
return value().operator ->(); | |
} | |
template<typename = decltype(std::declval<Type>().operator *())> | |
auto operator *() -> decltype(std::declval<Type>().operator *()) | |
{ | |
return value().operator *(); | |
} | |
template<typename = decltype(std::declval<const Type>().operator *())> | |
auto operator *() const -> decltype(std::declval<const Type>().operator *()) | |
{ | |
return value().operator *(); | |
} | |
private: | |
Type mStorage; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment