[Nfd-dev] C++11 code style

Junxiao Shi shijunxiao at email.arizona.edu
Sun Nov 2 12:41:51 PST 2014


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?


`auto` specifier can be used to declare variables at any scope: block
scope, namespace scope, init statement of for loop.
The proposed rule is to forbid using `auto` specifier at namespace scope,
because such usage makes the code less readable.

Yours, Junxiao

On Sun, Nov 2, 2014 at 1:03 PM, Alex Afanasyev <alexander.afanasyev at ucla.edu
> wrote:

>
> On Nov 2, 2014, at 9:20 AM, Junxiao Shi <shijunxiao at email.arizona.edu>
> wrote:
>
> Dear folks
>
> We need to define some new code style rules for C++11 syntax.
>
> I'd start with three new rules:
>
> rule x. Range-based for should be in the following form:
>
> for (auto i : range) {
>   statements;
> }
>
>
>
> rule x. Lambda expression should be in the following form:
>
> [&capture1, capture2] (Type1 arg1, Type2 arg2)
> {
>
>   statements;
>
> }
>
>
> I prefer different style, which more aligns with the existing code (and is
> more gnu style):
>
> [&capture1, capture2] (Type1 arg1, Type2 arg2) {
>   statements;
> }
>
>
> If the function body has only one line, and the whole expression can fit
> in one line, the following form is also acceptable:
>
> [&capture1, capture2] (Type1 arg1, Type2 arg2) { statement; }
>
>
> that’s fine too
>
>
> rule x. `auto` type should only be used for local variables.
>
>
> Where else, potentially, it can be used?
>
>
> What other rules do we need?
>
> Yours, Junxiao
> _______________________________________________
> Nfd-dev mailing list
> Nfd-dev at lists.cs.ucla.edu
> http://www.lists.cs.ucla.edu/mailman/listinfo/nfd-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20141102/99d10526/attachment.html>


More information about the Nfd-dev mailing list