From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31277 invoked by alias); 30 Aug 2004 17:25:30 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 31220 invoked from network); 30 Aug 2004 17:25:29 -0000 Received: from unknown (HELO psmtp.com) (12.158.35.214) by sourceware.org with SMTP; 30 Aug 2004 17:25:29 -0000 Received: from source ([192.150.22.7]) by exprod6ob4.obsmtp.com ([12.158.35.250]) with SMTP; Mon, 30 Aug 2004 10:25:23 PDT Received: from inner-relay-1.corp.adobe.com (inner-relay-1 [153.32.1.51]) by smtp-relay-7.sea.adobe.com (8.12.10/8.12.10) with ESMTP id i7UHPMNf005334; Mon, 30 Aug 2004 10:25:22 -0700 (PDT) Received: from iplan-mn (iplan-mn.corp.adobe.com [130.248.25.5]) by inner-relay-1.corp.adobe.com (8.12.9/8.12.9) with ESMTP id i7UHPJTk011801; Mon, 30 Aug 2004 10:25:20 -0700 (PDT) Received: from mn-eljay-a51m.adobe.com ([130.248.178.90]) by iplan-mn.corp.adobe.com (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0I390073KSE5I1@iplan-mn.corp.adobe.com>; Mon, 30 Aug 2004 12:25:19 -0500 (CDT) Date: Mon, 30 Aug 2004 18:22:00 -0000 From: Eljay Love-Jensen Subject: Re: function object, function pointer and function. In-reply-to: X-Sender: eljay@iplan-mn.corp.adobe.com To: learning c++ , gcc-help@gcc.gnu.org Message-id: <6.1.2.0.2.20040830121802.01f2b8d0@iplan-mn.corp.adobe.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii; format=flowed Content-transfer-encoding: 7BIT References: X-SW-Source: 2004-08/txt/msg00283.txt.bz2 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