|
Boost : |
From: Moore, Paul (Paul.Moore_at_[hidden])
Date: 1999-12-21 05:08:06
From: Dave Abrahams [mailto:abrahams_at_[hidden]]
>
> Better yet, just put the abs specialization for rational<>
> into the global namespace.
Yes, probably. I'll go with that.
[re: Friend templates]
> Your sample is too small, but that doesn't really matter. Why
> bother with friend templates when abs doesn't need to be a friend
> at all?
I know about the sample size :-( For abs we don't have an issue, but I'm
concerned about cases where we might. The fact that rational exposes its
guts for all to see can't be viewed as a generally applicable technique :-)
My hidden agenda here is to understand the issues well enough to never need
to think about it again. My brain is hurting...
> Speaking of friends, you could use the Barton & Nackmann
> trick if partial ordering doesn't work in MSVC (does it?):
Aha!!! This may be the missing piece of the puzzle. I was not aware of what
"partial ordering" is. I'll look in the standard, but can you give a summary
of the implications here, and I'll test it out?
>
> template <class X>
> struct rational_abs
> {
> friend abs(const X& x)
> { using std::abs; return X(abs(x.numerator(), x.denominator()); }
> };
>
> template <class T>
> class rational : rational_abs<rational<T> >, ...
Urg. I don't really see what this is doing. Could you elaborate? It seems to
be forcing the lookup for friend abs() to be at class scope instead of
namespace. It's also making the abs(rational) not be a template... I think.
(I'd never heard of the "Barton & Nackmann trick" - where did it come from?
Are these sorts of tricks collected anywhere?)
My brain is *really* hurting...
> Try the B&N trick described above. That should solve a lot of
> problems by not requiring so much template smarts from the compiler. This
> would simply generate a single abs() overload for each version of
> rational. Hmm, though to get abs() into the global namespace you might
need to
> put rational_abs there, too. Maybe you need to call it
boost_rational_abs__()
> for MSVC's purposes.
I think that not requiring so much template smarts is the key here.
> On broken compilers, the bigint implementer had better put
> the abs() in the global namespace as I have been proposing, or I
> think we are sunk.
Yes, I worried about that.
Paul.
PS If Santa is listening, I'd like a new compiler :-)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk