Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lambda without parentheses

Use case

Cleaner lambdas with no parameters.

Explanation

[]{} is now valid instead of [](){}. Small but reduces visual noise.

Code

#include <print>
#include <thread>

int main() {
  auto analyzer = [] { std::println("Running analysis."); };

  analyzer();

  return 0;
}

View on GitHub.

Output

$ ./src/c++23/build/lambda-without-parentheses
Running analysis.