|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-03-25 05:14:36
Aleksey Gurtovoy wrote:
>
> How about this:
>
> template< typename T >
> struct operators
> {
> private:
> T& self() { return static_cast<T&>(*this); }
> T const& self() const { return static_cast<T const&>(*this); }
>
> private:
> template<typename U> static T do_add(T x, U const& y) { return x += y; }
>
> protected:
> // ...
> T operator+(T const& other) { return T(self()) += other; }
>
> // ...
> template<typename U> friend T operator+(T& x, U const& y) { return
> x.do_add(x,y); }
> template<typename U> friend T operator+(U const& y, T& x) { return
> x.do_add(x,y); }
> };
Hm, what if the class T contains 'operator U'? For me, this doesn't seem
to work and is therefore dangerous as operator U is prefered over the
given operator+. Thus the code used is not what the user intended. For
all this operator-stuff, I have another version which uses #defines.
It's not what I'd call cool, but it works reliably and yields very few
surprises compared to the native C++-version. Should we consider such an
old solution?
Regards, Daniel
PS: I once intended to clarify a statement I made just a minute ago, but
if I reply to my own post, it doesn't appear in the mailing list. Is
this intendet behaviour of the list or is it a bug?
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk