This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project. See the libstdc++ home page for more information.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: stl function.h



>>>>> Steve Hill <stevehi@soc.plym.ac.uk> wrote:

> Hi,
> in functions.h, the functors minus and divides are declared. 
> These (in my linux version) are taken from stl_function.h. minus is
> declared as

> template <class T>
> struct minus : public binary_function<T, T, T> {
>     T operator()(const T& x, const T& y) const { return x - y; }
> };

> with divides being declared in a similar fashion.

> Why not define functors additive_inverse (OK, I know negates does this) and
> multiplicitive_inverse, so the operator() in minus and divides would be
> respectively defined as

> T operator()(const T& x,const T& y)
> {
> 	return plus(x,additive_inverse(y));
> };

> and

> T operator()(const T& x,const T& y)
> {
> 	return multiplies(x, multiplicitive_inverse(y));
> };
	
> The reason I'm enquiring about this, is that logically speaking, dividon
> is usually defined as multiplication by a multiplicative inverse. Ok, for
> reals, ints etc, this is a trivial thing, but say for matricies, the 
> multiplicitive inverse is a non trivial thing to compute.

> Is this just me being a bit anal?? 

Formelly, yes. The Standard does not know anything about matrix.

There are plenty occasions where mutliplies<>()(x, y) is well defined
and multiplicitive_inverse(y) not defined at all.

OTOH if you're computing with matrices, you're better off defining your
own plus<> and multiplies<>.

libstdc++, first, is trying to catch up the ISO C++ Standard library.

-- Gaby