On Apr 11, 9:34 pm, Arne Mertz <n...@arne-mertz.de> wrote:
> SG schrieb:
> > On 11 Apr., 18:30, Arne Mertz <n...@arne-mertz.de> wrote:
> > You either write
> > return T(u) / t; // suggested previously
> > or you write
> > T temp = u;
> > temp /= t;
> > return temp;
> Unfortunately, *I* write nothing there. The function is part
> of the boost libraries (boost/operators.hpp, line 240). It is
> only used in the absence of two #defines, so as a workaround I
> had to check for those defines and set one of them explicitly.
Have you actually read the documentation of Boost:

perators?
They provide operators for user defined classes. Not in the
best way, of course---you really want to use the Barton and
Nackman trick here, and provide them as friends of a base
class. But that's not the point here: if you instantiate e.g.
operator/ with X as the first template argument, then it is a
pre-condition that X has a member function operator/=.
Otherwise, you're not using the library as specified.
Of course, I can't find any way you could reasonably use the
library as it is specified---you need operator/ to be somewhere
where ADL will find it, and ADL will not look into namespace
boost. (That's why the Barton and Nackman trick is preferred.)
And of course, there really isn't any good reason to not support
classes with operator/= as a free function---arguably, it should
be a free function, because that is the only way to make it
require an lvalue. (On the other hand, operator= can't be a
free function, so you've lost this aspect anyway, and you might
as well go ahead and make them all members. I know I usuallly
do.)
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34