Skip to content

Commit

Permalink
Add a few rules about spaces around lambdas and templates to the styl…
Browse files Browse the repository at this point in the history
…e guide

https://bugs.webkit.org/show_bug.cgi?id=273724

Reviewed by Chris Dumez and Darin Adler.

Fleshes out the rules spaces in and around lambdas and templates.

* Websites/webkit.org/code-style.md:

Canonical link: https://commits.webkit.org/278374@main
  • Loading branch information
weinig authored and Sam Weinig committed May 4, 2024
1 parent b25db3d commit e96d0ed
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions Websites/webkit.org/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,37 +246,78 @@ if(condition)
doIt();
```
[](#spacing-function-paren) Do not place spaces between a function and its parentheses, or between a parenthesis and its content.
[](#spacing-function-paren-prior) Do not place spaces between the name, angle brackets and parentheses of a function declaration or invocation.
###### Right:
```cpp
f();
void g() { ... }
h<int>();
```
###### Wrong:
```cpp
f ();
void g () { ... }
h <int> ();
```
[](#spacing-function-paren-inside) Do not place spaces between the parenthesis and its parameters, or angle brackets and its parameters of a function declaration or invocation.
###### Right:
```cpp
f(a, b);
void g(int a) { ... }
h<int>();
```
###### Wrong:
```cpp
f (a, b);
f( a, b );
void g( int a ) { ... }
h< int >();
```
[](#spacing-lambda-paren) Do not place spaces between square brackets and parentheses of a lambda function but do place a space before braces.
[](#spacing-lambda-paren) Do not place spaces between square brackets, angle brackets and parentheses of a lambda function but do place a space before braces.
###### Right:
```cpp
[](int x) { return x; }
[this] { return m_member; }
[=]<typename T> { return T(); }
[&]<typename X>(X parameter) { return parameter; }
```
###### Wrong:
```cpp
[] (int x) { return x; }
[this]{ return m_member; }
[=] <typename T> { return T(); }
[&]<typename X> (X parameter) { return parameter; }
```
[](#spacing-template) Do not place spaces between the identifier `template` and its angle brackets.
###### Right:
```cpp
template<typename T> T foo();
template<typename U> struct Bar { };
```
###### Wrong:
```cpp
template <typename T> T foo();
template <typename U> struct Bar { };
[](#spacing-braced-init) When initializing an object, place a space before the leading brace as well as between the braces and their content.
###### Right:
Expand Down

0 comments on commit e96d0ed

Please sign in to comment.