Glen Low Guest
|
Posted: Sat Oct 16, 2004 10:08 am Post subject: Function object constancy |
|
|
Looking at 20.3.1 and 20.3.2 of the Standard, we have for example:
template <class T> struct plus: binary_function <T, T, T> {
T operator() (const T&x, const T&y) const { return x + y; }
};
Suppose I want to specialize this for my type Z (as opposed to to
declaring an operator+). In one of Meyer's screeds, he says an
operator overload should generally return a constant object, so what's
the correct way of specializing this, A or B?
template <> struct plus <Z>: binary_function <Z, Z, Z> {
Z operator() (const Z& x, const Z& y) const { ... } // A
const Z operator() (const Z&x, const Z&y) const { ... } // B
}
In particular in declaring a function object that is compatible with
standard requirements, is it OK to have first_argument_type,
second_argument_type and result convertible from the actual parameters
and returns of the operator(), or must they match exactly?
Cheers,
Glen Low, Pixelglow Software
www.pixelglow.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|