Boost logo

Boost :

From: Moore, Paul (Paul.Moore_at_[hidden])
Date: 1999-12-09 06:58:51

It struck me that my rational number class could do with a std::abs()
implementation. What is the accepted way to do this? Should I do

namespace boost {
    template <typename Int> class rational<Int> {

    template typename<Int> inline rational<Int> abs(rational<Int> r);

or should I put my abs() into namespace std, using

namespace boost {
    template <typename Int> class rational<Int> {

namespace std {
    template typename<Int> inline boost::rational<Int>
abs(boost::rational<Int> r);

I sort of lean towards the latter, as code like

    using std::abs;
    using boost::rational;
    int n = -1;
    rational<int> r(-1);
    n = abs(n);
    r = abs(r);

seems natural to me. Requiring an additional "using boost::abs" seems
unintuitive. But I'm not sure if it is legitimate to add overloads in the
std:: namespace like this... I couldn't find any examples of things like
this which I could learn from (std::swap specialisations seem to be
implemented as member functions).

Does anyone have any suggestions?


Boost list run by bdawes at, gregod at, cpdaniel at, john at