C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Function object constancy

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Glen Low
Guest





PostPosted: Sat Oct 16, 2004 10:08 am    Post subject: Function object constancy Reply with quote



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! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.