【发布时间】:2020-03-20 08:04:55
【问题描述】:
我在 cppreference 上看到了很多示例代码。 例如,以下 URL 有一个代码。
https://en.cppreference.com/w/cpp/language/list_initialization
从上面的例子中,我们可以观察到大括号的缩进在struct 和function 上是不同的,如下所示。
struct Foo { // left-brace is on the same line with the name of the struct
std::vector<int> mem = {1, 2, 3}; // default indent seems 4 spaces
std::vector<int> mem2;
Foo() : mem2{-1, -2, -3} {}
}; // right-brace starts with a new line
std::pair<std::string, std::string> f(std::pair<std::string, std::string> p)
{ // left-brace starts with a new line for function
return {p.second, p.first}; // list-initialization in return statement
} // right-brace starts with a new line for function
int main()
{ // same as above
//...
} // same as above
编码风格在哪里描述?
【问题讨论】:
-
这叫Stroustrup风格
标签: c++ coding-style std