This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: valarray<double>::operator%() not working
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: Lance Olav Eastgate <lance at ccmr dot cornell dot edu>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: 22 Feb 2002 19:56:34 +0100
- Subject: Re: valarray<double>::operator%() not working
- Organization: CodeSourcery, LLC
- References: <Pine.LNX.4.44.0202221246580.17425-100000@flour.ccmr.cornell.edu>
Lance Olav Eastgate <lance@ccmr.cornell.edu> writes:
| When I try to use the binary operator% or operator%= with valarray<double>
| this doesn't work (in gcc 3.0.2). The reason, as far as I understand, is
| that operator% is only defined for integers.
Right.
| The element-by-element
| modulus in _DEFINE_ARRAY_FUNCTION (in valarray_array.h, line 419, gcc
| 3.0.2) thus doesn't work when _Tp is a double. Thus for two doubles or
| floats, std::fmod (or similar) needs to be used.
But valarray<double> isn't intended to be operand of operator%.
You might want to use function objects and the member function
valarray<>::apply() to get the effect you want.
| Perhaps the operator% etc could be overloaded to take two doubles?
That is impossible -- operator overloading works only for user-defined
types (or types "derived" from them).
-- Gaby