diff --git a/stream.hpp b/stream.hpp index 66cd1a9a..75e75cdc 100644 --- a/stream.hpp +++ b/stream.hpp @@ -21,9 +21,37 @@ #define __UTIL_STREAM_HPP #include +#include "types/bits.hpp" namespace util { namespace stream { + //--------------------------------------------------------------------- + template + struct numeric + { + numeric (T _val): val (_val) { ; } + T val; + }; + + template + std::ostream& operator<< (std::ostream &os, numeric n) + { + static_assert (std::is_fundamental::value, + "numeric streamer is intended for chars"); + + using integral_t = typename std::conditional< + std::is_floating_point::value, + T, + typename std::conditional< + std::is_signed::value, + sized_type< intmax_t>::sint, + sized_type::uint + >::type + >::type; + + return os << (integral_t)n.val; + } + //--------------------------------------------------------------------- class null : public std::ostream { public: