From: Eljay Love-Jensen <eljay@adobe.com>
To: learning c++ <learning_c@hotmail.com>, gcc-help@gcc.gnu.org
Subject: Re: function object, function pointer and function.
Date: Mon, 30 Aug 2004 18:22:00 -0000 [thread overview]
Message-ID: <6.1.2.0.2.20040830121802.01f2b8d0@iplan-mn.corp.adobe.com> (raw)
In-Reply-To: <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
prev parent reply other threads:[~2004-08-30 17:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-30 17:25 learning c++
2004-08-30 18:22 ` Eljay Love-Jensen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6.1.2.0.2.20040830121802.01f2b8d0@iplan-mn.corp.adobe.com \
--to=eljay@adobe.com \
--cc=gcc-help@gcc.gnu.org \
--cc=learning_c@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).