From f0021afc71c6d16396cef54a8b08cd082eb37780 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 6 Feb 2015 16:35:23 +1100 Subject: [PATCH] fixed: add ostream operators --- fixed.cpp | 10 ++++++++++ fixed.hpp | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/fixed.cpp b/fixed.cpp index e2dd788e..64b2ef97 100644 --- a/fixed.cpp +++ b/fixed.cpp @@ -191,12 +191,22 @@ LOGIC_OP(<=) LOGIC_OP(>) LOGIC_OP(>=) +/////////////////////////////////////////////////////////////////////////////// +// iostream operators +template +std::ostream& +util::operator<< (std::ostream &os, fixed v) +{ + return os << v.to_double (); +} + /////////////////////////////////////////////////////////////////////////////// // Instantiations #define INSTANTIATE(I,E) \ template class util::fixed<(I),(E)>; \ +template std::ostream& util::operator<< (std::ostream&, fixed<(I),(E)>); \ template bool util::operator== (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ template bool util::operator!= (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ template bool util::operator< (util::fixed<(I),(E)>, util::fixed<(I),(E)>); \ diff --git a/fixed.hpp b/fixed.hpp index a7e542f4..34902986 100644 --- a/fixed.hpp +++ b/fixed.hpp @@ -23,6 +23,7 @@ #include "types/bits.hpp" #include +#include namespace util { template @@ -75,6 +76,10 @@ namespace util { template bool operator<= (util::fixed, util::fixed); template bool operator> (util::fixed, util::fixed); template bool operator>= (util::fixed, util::fixed); + + + template + std::ostream& operator<< (std::ostream&, fixed); } #endif // __UTIL_FIXED_HPP