Re: function object, function pointer and function.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux