-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcoding-style.cpp
More file actions
119 lines (96 loc) · 1.9 KB
/
Copy pathcoding-style.cpp
File metadata and controls
119 lines (96 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <utility>
#include <string>
//Put spaces around pointers and references
int main(int argc, char ** argv)
{
//Use tabs for indentation
//Use english names typed in CamelCase (for types)
//or camelCase (for functions and variables)
struct Person
{
private:
const char * firstName;
const char * surname;
public:
Person(const char * firstName, const char * surname)
: firstName(firstName)
, surname(surname)
{}
const char * getFirstName() const
{
return firstName;
}
const char * getSurname() const
{
return surname;
}
};
//When default ctors and dtors suffice and you want
//to be explicit about it, use the C++11 "default" notation
struct SimpleClass
{
SimpleClass() = default;
~SimpleClass() = default;
}
//Put braces in separate lines
if (true)
{
// ...
}
else
{
// ...
}
while (false)
{
}
for (;;)
{
}
auto l = [](int x) -> int
{
return x;
};
//The exceptions are empty or simple one-liner functions,
//which can be formatted in the following way
struct A
{
void doNothing() {}
static int getTheUltimateAnswer()
{ return 42; }
};
//...as well as initializer lists
std::pair<double, double> position {
34.0, 85.0
};
//..and namespaces
//namespace Foo {
//...
//}
//There's no preset limit on line length,
//but try to be reasonable about it
//Split long declarations and function calls
struct B
{
static std::string concatenate(
const std::string & a,
const std::string & b,
const std::string & c
)
{
return a + " " + b + " " + c;
}
};
auto text = B::concatenate(
"Lorem ipsum ",
"dolor sit amet, ",
"consectetur adipiscing elit"
);
return 0;
}
//Don't indent the first level of namespace content
namespace Foo {
static const unsigned int THE_ULTIMATE_ANSWER = 42;
}
//When in doubt - use Common Sense™ and stay consistent.
//Don't hesitate to ask or propose extensions to this guideline.