[Nfd-dev] C++11 code style

Davide Pesavento davide.pesavento at lip6.fr
Sun Nov 2 16:14:11 PST 2014


On Sun, Nov 2, 2014 at 9:57 PM, Alex Afanasyev
<alexander.afanasyev at ucla.edu> wrote:
>
> On Nov 2, 2014, at 12:41 PM, Junxiao Shi <shijunxiao at email.arizona.edu>
> wrote:
>
> Dear folks
>
> The choice between
>
> [&capture1, capture2] (Type1 arg1, Type2 arg2)
> {
>   statements;
> }
>
> and
>
> [&capture1, capture2] (Type1 arg1, Type2 arg2) {
>   statements;
> }
>
> depends on whether a lambda expression is more like a function, or a block
> statement (similar to if/for/while).
> A lambda expression is an inline function and rule 1.5 mandates the first
> style for functions.
> Another possible understanding is: put "{" on the next line for everything
> down to named function level, and put "{" on the same line for everything
> inside a named function. This makes the second style preferred.
> What do others on nfd-dev think?
>
>
> Even though lambda function is logically a function, it is used as a block
> statement.  Therefore, the rule (if any) should be closer to a block
> statement rule, then to function.
>

It's really a minor matter, but I agree with Alex wrt braces
positioning. The rationale is that most of the time lambdas are
directly passed as arguments to function calls, e.g.

myfunc(foo, [&bar] (int baz) {
    bar += baz;
});

and the above style looks more natural to me.

Thanks,
Davide



More information about the Nfd-dev mailing list