Boost logo

Boost :

Subject: Re: [boost] [Boost.Local] Review
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-11-23 06:54:58


On 11/23/2011 7:06 PM, Lorenzo Caminiti wrote:
>> just using phoenix and/or lambda :
>> >
>> > int max = 0;
>> > auto small = _1 < max; // (2)
> Or even better:
>
> int max = 0;
> auto small = [max](int x) { return x < max; } // (3)
>
> IMO (and others have second this point), (3) is better than (2)
> because at some point (3+ years from now?) everyone will be
> comfortable with C++11 lambda syntax (3) because it's part of the
> standard while there will still be people on your team that will have
> no idea what you meant in writing (2). By the same token, the syntax
> of (1) (statement syntax for the body) can be considered better than
> the one of (2) even if (1) is more verbose and than (2) (verbosity
> which might be a plus in the context to make the syntax more clear--
> in fact (3) is more verbose than (2) but it is the new standard). All
> of that said, if the a syntax is more or less understandable is a
> subjective matter so I recognize that you and/or Hartmut feel
> differently on this topic.

No it's not better. First: (3) is not polymorphic! (2) can be reused
regardless of the type of _1. To make it clear:

   auto less = _1 < _2;

The above can be reused in any expression as long as they
have the less-than relation. E.g. less(i, 123), less(str, "hello),
etc. It's these simple 1-2-3 liners where Phx/Lambda shine.
You'd have to be absurdly dumb to get those expressions wrong!

Second: (2) is more succinct.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk