This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: function object, function pointer and function.
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: learning c++ <learning_c at hotmail dot com>, gcc-help at gcc dot gnu dot org
- Date: Mon, 30 Aug 2004 12:25:19 -0500
- Subject: Re: function object, function pointer and function.
- References: <BAY12-F300yki4jsGvs00011487@hotmail.com>
Hi,
In the situation you presented, the & in your "int count1 =
count_if(v1.begin(), v1.end(), &lessThan20Function);" line is
superfluous. Although it is perfectly good code, and acceptable to all
compilers.
In my experience, it would be omitted. By convention.
Also in my experience, there is a preference to function objects over
function pointers.
For some really neat stuff, the BOOST (www.boost.org) library has a lambda
library, which would allow you to put the body of the predicate right in
your count_if statement -- and in a quite abbreviated form. It'd look
something like...
int count = count_if(v1.begin(), v1.end(), _1 > 20);
HTH,
--Eljay