|
|
@ -608,9 +608,9 @@ namespace mynamespace {
|
|
|
|
// All declarations are within the namespace scope.
|
|
|
|
// All declarations are within the namespace scope.
|
|
|
|
// Notice the lack of indentation.
|
|
|
|
// Notice the lack of indentation.
|
|
|
|
class MyClass {
|
|
|
|
class MyClass {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
...
|
|
|
|
...
|
|
|
|
void Foo();
|
|
|
|
void Foo();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace mynamespace
|
|
|
|
} // namespace mynamespace
|
|
|
@ -770,9 +770,9 @@ void Function2();
|
|
|
|
<p>instead of</p>
|
|
|
|
<p>instead of</p>
|
|
|
|
<pre class="badcode">namespace myproject {
|
|
|
|
<pre class="badcode">namespace myproject {
|
|
|
|
class FooBar {
|
|
|
|
class FooBar {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
static void Function1();
|
|
|
|
static void Function1();
|
|
|
|
static void Function2();
|
|
|
|
static void Function2();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} // namespace myproject
|
|
|
|
} // namespace myproject
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
@ -1199,12 +1199,12 @@ other code, and to document that your class is copyable and/or cheaply movable
|
|
|
|
if that's an API guarantee.</p>
|
|
|
|
if that's an API guarantee.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre class="badcode">class Foo {
|
|
|
|
<pre class="badcode">class Foo {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Foo(Foo&& other) : field_(other.field) {}
|
|
|
|
Foo(Foo&& other) : field_(other.field) {}
|
|
|
|
// Bad, defines only move constructor, but not operator=.
|
|
|
|
// Bad, defines only move constructor, but not operator=.
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
Field field_;
|
|
|
|
Field field_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
@ -1788,9 +1788,9 @@ string&</code> and overload it with another that
|
|
|
|
takes <code>const char*</code>.</p>
|
|
|
|
takes <code>const char*</code>.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre>class MyClass {
|
|
|
|
<pre>class MyClass {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void Analyze(const string &text);
|
|
|
|
void Analyze(const string &text);
|
|
|
|
void Analyze(const char *text, size_t textlen);
|
|
|
|
void Analyze(const char *text, size_t textlen);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -3118,10 +3118,10 @@ For example, avoid patterns like:</p>
|
|
|
|
<pre class="badcode">class WOMBAT_TYPE(Foo) {
|
|
|
|
<pre class="badcode">class WOMBAT_TYPE(Foo) {
|
|
|
|
// ...
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
EXPAND_PUBLIC_WOMBAT_API(Foo)
|
|
|
|
EXPAND_PUBLIC_WOMBAT_API(Foo)
|
|
|
|
|
|
|
|
|
|
|
|
EXPAND_WOMBAT_COMPARISONS(Foo, ==, <)
|
|
|
|
EXPAND_WOMBAT_COMPARISONS(Foo, ==, <)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
@ -3384,16 +3384,16 @@ that take <code>std::initializer_list<T></code>, which is automatically
|
|
|
|
created from <i>braced-init-list</i>:</p>
|
|
|
|
created from <i>braced-init-list</i>:</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre>class MyType {
|
|
|
|
<pre>class MyType {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// std::initializer_list references the underlying init list.
|
|
|
|
// std::initializer_list references the underlying init list.
|
|
|
|
// It should be passed by value.
|
|
|
|
// It should be passed by value.
|
|
|
|
MyType(std::initializer_list<int> init_list) {
|
|
|
|
MyType(std::initializer_list<int> init_list) {
|
|
|
|
for (int i : init_list) append(i);
|
|
|
|
for (int i : init_list) append(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MyType& operator=(std::initializer_list<int> init_list) {
|
|
|
|
MyType& operator=(std::initializer_list<int> init_list) {
|
|
|
|
clear();
|
|
|
|
clear();
|
|
|
|
for (int i : init_list) append(i);
|
|
|
|
for (int i : init_list) append(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
MyType m{2, 3, 5, 7};
|
|
|
|
MyType m{2, 3, 5, 7};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
@ -3406,9 +3406,9 @@ constructors of data types, even if they do not have
|
|
|
|
// Calls ordinary constructor as long as MyOtherType has no
|
|
|
|
// Calls ordinary constructor as long as MyOtherType has no
|
|
|
|
// std::initializer_list constructor.
|
|
|
|
// std::initializer_list constructor.
|
|
|
|
class MyOtherType {
|
|
|
|
class MyOtherType {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit MyOtherType(string);
|
|
|
|
explicit MyOtherType(string);
|
|
|
|
MyOtherType(int, string);
|
|
|
|
MyOtherType(int, string);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
MyOtherType m = {1, "b"};
|
|
|
|
MyOtherType m = {1, "b"};
|
|
|
|
// If the constructor is explicit, you can't use the "= {}" form.
|
|
|
|
// If the constructor is explicit, you can't use the "= {}" form.
|
|
|
@ -5209,11 +5209,11 @@ not fit on a single line as you would wrap arguments in a
|
|
|
|
<p>Unused parameters that are obvious from context may be omitted:</p>
|
|
|
|
<p>Unused parameters that are obvious from context may be omitted:</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre>class Foo {
|
|
|
|
<pre>class Foo {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Foo(Foo&&);
|
|
|
|
Foo(Foo&&);
|
|
|
|
Foo(const Foo&);
|
|
|
|
Foo(const Foo&);
|
|
|
|
Foo& operator=(Foo&&);
|
|
|
|
Foo& operator=(Foo&&);
|
|
|
|
Foo& operator=(const Foo&);
|
|
|
|
Foo& operator=(const Foo&);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
@ -5221,13 +5221,13 @@ not fit on a single line as you would wrap arguments in a
|
|
|
|
name in the function definition:</p>
|
|
|
|
name in the function definition:</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre>class Shape {
|
|
|
|
<pre>class Shape {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual void Rotate(double radians) = 0;
|
|
|
|
virtual void Rotate(double radians) = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Circle : public Shape {
|
|
|
|
class Circle : public Shape {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void Rotate(double radians) override;
|
|
|
|
void Rotate(double radians) override;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void Circle::Rotate(double /*radians*/) {}
|
|
|
|
void Circle::Rotate(double /*radians*/) {}
|
|
|
@ -5782,7 +5782,7 @@ beginning of the line.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="summary">
|
|
|
|
<div class="summary">
|
|
|
|
<p>Sections in <code>public</code>, <code>protected</code> and
|
|
|
|
<p>Sections in <code>public</code>, <code>protected</code> and
|
|
|
|
<code>private</code> order, each indented two spaces.</p>
|
|
|
|
<code>private</code> order, each indented one space.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="stylebody">
|
|
|
|
<div class="stylebody">
|
|
|
@ -5793,23 +5793,23 @@ Comments</a> for a discussion of what comments are
|
|
|
|
needed) is:</p>
|
|
|
|
needed) is:</p>
|
|
|
|
|
|
|
|
|
|
|
|
<pre>class MyClass : public OtherClass {
|
|
|
|
<pre>class MyClass : public OtherClass {
|
|
|
|
public: // Note the 1 space indent!
|
|
|
|
public: // Note the 1 space indent!
|
|
|
|
MyClass(); // Regular 2 space indent.
|
|
|
|
MyClass(); // Regular 2 space indent.
|
|
|
|
explicit MyClass(int var);
|
|
|
|
explicit MyClass(int var);
|
|
|
|
~MyClass() {}
|
|
|
|
~MyClass() {}
|
|
|
|
|
|
|
|
|
|
|
|
void SomeFunction();
|
|
|
|
void SomeFunction();
|
|
|
|
void SomeFunctionThatDoesNothing() {
|
|
|
|
void SomeFunctionThatDoesNothing() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_some_var(int var) { some_var_ = var; }
|
|
|
|
void set_some_var(int var) { some_var_ = var; }
|
|
|
|
int some_var() const { return some_var_; }
|
|
|
|
int some_var() const { return some_var_; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
bool SomeInternalFunction();
|
|
|
|
bool SomeInternalFunction();
|
|
|
|
|
|
|
|
|
|
|
|
int some_var_;
|
|
|
|
int some_var_;
|
|
|
|
int some_other_var_;
|
|
|
|
int some_other_var_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
@ -5821,7 +5821,7 @@ needed) is:</p>
|
|
|
|
|
|
|
|
|
|
|
|
<li>The <code>public:</code>, <code>protected:</code>,
|
|
|
|
<li>The <code>public:</code>, <code>protected:</code>,
|
|
|
|
and <code>private:</code> keywords should be indented
|
|
|
|
and <code>private:</code> keywords should be indented
|
|
|
|
two spaces.</li>
|
|
|
|
one space.</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li>Except for the first instance, these keywords
|
|
|
|
<li>Except for the first instance, these keywords
|
|
|
|
should be preceded by a blank line. This rule is
|
|
|
|
should be preceded by a blank line. This rule is
|
|
|
@ -5942,12 +5942,12 @@ int x[] = {0};
|
|
|
|
|
|
|
|
|
|
|
|
// Spaces around the colon in inheritance and initializer lists.
|
|
|
|
// Spaces around the colon in inheritance and initializer lists.
|
|
|
|
class Foo : public Bar {
|
|
|
|
class Foo : public Bar {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// For inline function implementations, put spaces between the braces
|
|
|
|
// For inline function implementations, put spaces between the braces
|
|
|
|
// and the implementation itself.
|
|
|
|
// and the implementation itself.
|
|
|
|
Foo(int b) : Bar(), baz_(b) {} // No spaces inside empty braces.
|
|
|
|
Foo(int b) : Bar(), baz_(b) {} // No spaces inside empty braces.
|
|
|
|
void Reset() { baz_ = 0; } // Spaces separating braces from implementation.
|
|
|
|
void Reset() { baz_ = 0; } // Spaces separating braces from implementation.
|
|
|
|
...
|
|
|
|
...
|
|
|
|
</pre>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
<p>Adding trailing whitespace can cause extra work for
|
|
|
|
<p>Adding trailing whitespace can cause extra work for
|
|
|
|