Boost logo

Boost :

From: Paul Moore (gustav_at_[hidden])
Date: 2000-04-21 12:06:15


From: Dave Abrahams [mailto:abrahams_at_[hidden]]
> Q. Where is it written that std::swap() is supposed to be efficient or
> nonthrowing?
>
> A. It isn't.
> (except when used on the standard containers, where it is guaranteed to be
> nonthrowing, but not neccessarily efficient).

Oh. Common usage seems to imply that it is nonthrowing - but I never checked
whether that was really the case. As for efficiency, again I understood that
the whole idea was that { T tmp(a); b=a; a=tmp; } was the fallback, but
specialised versions could do better, if that was possible.

Thinking about it, there's no guarantee that the generic version doesn't
throw, so I must be confused...

Is there a published rationale for the standard? I think I need it...

> Classes do not *need* to extend std:: functions. You and I may
> not like it, but there are alternatives.

Hm. Fair enough. I think this is where I first came into this. Is the
implication that my rational number class implement its abs()

namespace boost {
    template <typename T> class rational<T> { ... };
    template <typename T> rational<T> abs(rational<T> r) {
        using std::abs;
        return rational<T>(abs(r.numerator()), abs(r.denominator()));
    }
}

relying on Koenig lookup? And doesn't it imply that *all* generic functions
which want to use std:: functions have to use the using trick?

I thought Alan's defect report included something which explained why this
may not be enough - but I don't have the report to hand just now...

I'm not trying to be difficult here, or to fan the flames, but I do want to
know how I can write correct code for something like this (and what my users
need to be aware of if I do so...) I recall that part of my problem was
getting rational<> to work with MSVC - but I didn't think that was the whole
of it. Maybe it's time to try to get mingw working (if I can get it to
recognise std:: as a genuine namespace) and download the free Borland
compiler, and try to thrash out just what I need to do to get proper
portable code working...

> What workarounds are required of users?

Alan's defect report had a discussion of a function myswap() - I understood
why it was necessary when I read it, but I can't say I do now...

Paul.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk