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.
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??
Cheers
Steve
Steve Hill
Centre for Neural and Adaptive Systems
School of Computing
University of Plymouth