rational: add ostream operator
required for upcoming TAP changes
This commit is contained in:
parent
f0a05e06e2
commit
4c5bc46ad9
20
rational.cpp
20
rational.cpp
@ -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)
|
||||
|
@ -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>);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user