diff --git a/endian.hpp b/endian.hpp index a61ca2d8..ac11d842 100644 --- a/endian.hpp +++ b/endian.hpp @@ -9,12 +9,15 @@ #ifndef __UTIL_ENDIAN_HPP #define __UTIL_ENDIAN_HPP +#include "std.hpp" #include "types/bits.hpp" #include #include #include +#include + namespace cruft { //------------------------------------------------------------------------- // CXX: Update using "if constexpr" when available. It doesn't seem to be @@ -200,5 +203,42 @@ namespace cruft { endian::scheme src; }; + + + namespace endian { + template + struct value { + + operator ValueT () const + { + return convert (raw); + } + + decltype(auto) operator+ () const { return +this->operator ValueT (); } + + ValueT operator<< (size_t s) const { return convert (raw) << s; } + + auto& operator= (ValueT const &val) { raw = convert (val); return *this; } + + ValueT raw; + }; + + + template using little = value; + template using big = value; + + + template + std::ostream& + operator<< (std::ostream &os, value const &val) + { + return os << +ValueT(val); + } + } + + using bu16 = endian::big; + using bu32 = endian::big; } + + #endif