Skip to content

Instantly share code, notes, and snippets.

@jmlvanre
Last active August 29, 2015 14:19
Show Gist options
  • Save jmlvanre/b533778d65947205d316 to your computer and use it in GitHub Desktop.
Save jmlvanre/b533778d65947205d316 to your computer and use it in GitHub Desktop.
lambda style
auto lambda = [] () { return true };

auto lambda = [] () {
  ...;
};

socket.send([] () {
  ...;
});

socket.send([] () {
  ...
}).then([] () {
  ...
});

socket.send([
    =,
    &someLongCapture1,
    &someLongCapture2,
    &someLongCapture3,
    &someLongCapture4] () {
  ...
});


socket.send([
    =,
    &someLongCapture1,
    &someLongCapture2,
    &someLongCapture3,
    &someLongCapture4] () {
  ...
});
OR
socket.send(
  [=, &someLongCapture1, &someLongCapture2, &someLongCapture3] (const T& arg) {
  ...
});


socket.send([
    =,
    &someLongCapture1,
    &someLongCapture2,
    someLongCapture3] mutable () {
  ...
});
OR
socket.send(
  [=, &someLongCapture1, &someLongCapture2, someLongCapture3] mutable () {
  ...
});


socket.send([
    =,
    &someLongCapture,
    &someLongCapture2,
    &someLongCapture3] (const T& someParam) {
  ...
});
OR
socket.send([
    =,
    &someLongCapture,
    &someLongCapture2,
    &someLongCapture3] (
        const T& someLongParam1,
        const T& someLongParam2,
        const T& someLongParam3) {
  ...
});
@joerg84
Copy link

joerg84 commented Apr 21, 2015

Mesos clang format style: Clang-format-3.5

//removed space between capture specification and parentheses
auto lambda = []() { return true };

//removed space betweem capture specification and parentheses
auto lambda = []() {
  ...;
  ...;
};

//removed space between capture specification and parenthesis
socket.send([]() {
  ...;
  ...;
});


//removed space between capture specification and parentheses
socket.send([]() {
              ...;
              ...;
            })
  .then([]() {
    ...;
    ...;
  });

//removed space between capture specification and parentheses
socket.send([=,
             &someLongCapture1,
             &someLongCapture2,
             &someLongCapture3,
             &someLongCapture4]() {
  ...;
  ...;
});

//as above
//removed space between mutable and parentheses
socket.send([=,
             &someLongCapture1,
             &someLongCapture2,
             &someLongCapture3,
             &someLongCapture4]() {
  ...;
  ...;
});

OR

  socket.send(
    [=, &someLongCapture1, &someLongCapture2, &someLongCapture3](const T& arg) {
      ...;
      ...;
    });


//removed space between mutable and parentheses,
//breaking up into new lines depends on capture length (see below)
socket.send(
  [=, &someLongCapture1, &someLongCapture2, someLongCapture3] mutable() {
    ...;
    ...;
  });
OR
  socket.send(
    [=, &someLongCapture1, &someLongCapture2, someLongCapture3] mutable() {
      ...
    });


//moved = up to initial line of capture
socket.send([=,
             &someLongCapturexxxxxxxxxxxxxxxx,
             &someLongCapture2xxxxxxxxxxxxxxxx,
             &someLongCapture3xxxxxxxxxxxxxxxx](const T& someParam) {
  ...;
  ...;
});
OR
// first const on same line
socket.send([=,
             &someLongCapturexxxxxxxxxxxxxxxx,
             &someLongCapturexxxxxxxxxxxxxxxx,
             &someLongCapture3xxxxxxxxxxxxxxx](const T& someLongParam1,
                                               const T& someLongParam2,
                                               const T& someLongParam3) {
  ...
});

@mpark
Copy link

mpark commented Apr 23, 2015

clang-format-3.5

int main()
{
  auto lambda = []() { return true };

  auto lambda = []() { s1; };

  auto lambda = []() {
    s1;
    s2;
  };

  socket.send([]() { s1; });

  socket.send([]() {
                s1;
                s2;
              }).then([]() { s1; });

  socket.send([]() {
                s1;
                s2;
              }).then([]() {
    s1;
    s2;
  });

  socket.send([]() {
                s1;
                s2;
              })
    .then([]() {
      s1;
      s2;
    })
    .then([]() {
      s1;
      s2;
    });

  socket.send([=,
               &someLongCapture1,
               &someLongCapture2,
               &someLongCapture3,
               &someLongCapture4]() {
    s1;
    s2;
  });

  socket.send(
    [=, &someLongCapture1, &someLongCapture2, someLongCapture3]() mutable {
      s1;
      s2;
    });

  socket.send(
    [=, &someLongCapture1, &someLongCapture2, someLongCapture3]() mutable {
      s1;
      s2;
    });

  socket.send([=, &someLongCapture1, &someLongCapture2, &someLongCapture3](
    const T& someParam) { s1; });

  socket.send([=, &someLongCapture, &someLongCapture2, &someLongCapture3](
    const T& someParam) {
    s1;
    s2;
  });

  socket.send([=, &someLongCapture, &someLongCapture2, &someLongCapture3](
    const T& someLongParam1, const T& someLongParam2, const T& someLongParam3) {
    s1;
    s2;
    s3;
  });
}

clang-format-3.6 with BinPackArguments: false which was introduced in 3.6.

int main()
{
  auto lambda = []() { return true };

  auto lambda = []() { s1; };

  auto lambda = []() {
    s1;
    s2;
  };

  socket.send([]() { s1; });

  socket.send([]() {
    s1;
    s2;
  }).then([]() { s1; });

  socket.send([]() {
    s1;
    s2;
  })
    .then([]() {
      s1;
      s2;
    });

  socket.send([]() {
    s1;
    s2;
  })
    .then([]() {
      s1;
      s2;
    })
    .then([]() {
      s1;
      s2;
    });

  socket.send([=,
               &someLongCapture1,
               &someLongCapture2,
               &someLongCapture3,
               &someLongCapture4]() {
    s1;
    s2;
  });

  socket.send(
    [=, &someLongCapture1, &someLongCapture2, someLongCapture3]() mutable {
      s1;
      s2;
    });

  socket.send(
    [=, &someLongCapture1, &someLongCapture2, someLongCapture3]() mutable {
      s1;
      s2;
    });

  socket.send([=, &someLongCapture1, &someLongCapture2, &someLongCapture3](
    const T& someParam) { s1; });

  socket.send([=, &someLongCapture, &someLongCapture2, &someLongCapture3](
    const T& someParam) {
    s1;
    s2;
  });

  socket.send([=, &someLongCapture, &someLongCapture2, &someLongCapture3](
    const T& someLongParam1, const T& someLongParam2, const T& someLongParam3) {
    s1;
    s2;
    s3;
  });
}

@joerg84
Copy link

joerg84 commented Apr 23, 2015

As discussed: I get the same results for both version.

@mpark
Copy link

mpark commented Apr 23, 2015

A few more cases. Note that the known limitation of "jaggedness" is still present.

  socket.send([=, &someLongCapture, &someLongCapture2, &someLongCapture3](
    const T& someLongParam1,
    const T& someLongParam2,
    const T& someLongParam3,
    const T& someLongParam4) {
    s1;
    s2;
    s3;
  });

  socket.send([=, &someLongCapture](const T& someLongParam1,
                                    const T& someLongParam2,
                                    const T& someLongParam3,
                                    const T& someLongParam4) {
    s1;
    s2;
    s3;
  });

  socket.send([=,
               &someLongCapture,
               &someLongCapture2,
               &someLongCapture3,
               &someLongCapture4](const T& someLongParam1,
                                  const T& someLongParam2,
                                  const T& someLongParam3,
                                  const T& someLongParam4) {
    s1;
    s2;
    s3;
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment