rational: add ostream operator

required for upcoming TAP changes
This commit is contained in:
Danny Robson 2018-04-16 15:54:51 +10:00
parent f0a05e06e2
commit 4c5bc46ad9
2 changed files with 22 additions and 4 deletions

View File

@ -162,8 +162,20 @@ rational<T>::operator/ (const T rhs) const
}
//-----------------------------------------------------------------------------
template struct util::rational<uint32_t>;
template struct util::rational< int32_t>;
///////////////////////////////////////////////////////////////////////////////
template <typename ValueT>
std::ostream&
util::operator<< (std::ostream &os, util::rational<ValueT> val)
{
return os << val.n << "/" << val.d;
}
template util::rational<uint32_t> util::operator/ (uint32_t, util::rational<uint32_t>);
///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATE(TYPE) \
template struct util::rational<TYPE>; \
template util::rational<TYPE> util::operator/ (TYPE, util::rational<TYPE>); \
template std::ostream& util::operator<< (std::ostream&, util::rational<TYPE>);
INSTANTIATE(uint32_t)
INSTANTIATE(int32_t)

View File

@ -18,6 +18,7 @@
#define __UTIL_RATIONAL_HPP
#include <type_traits>
#include <iosfwd>
namespace util {
template <typename T>
@ -68,6 +69,11 @@ namespace util {
{
return rhs * lhs;
}
///////////////////////////////////////////////////////////////////////////
template <typename ValueT>
std::ostream& operator<< (std::ostream&, rational<ValueT>);
};