diff --git a/cppguide.html b/cppguide.html index a7f32245a..8404516b3 100644 --- a/cppguide.html +++ b/cppguide.html @@ -174,9 +174,8 @@
Do not use non-standard extensions.
-Consider portability to other environments +before using features from C++14 and C++17 in your project.
<PROJECT>_<PATH>_<FILE>_H_.
-
-
-To guarantee uniqueness, they should
be based on the full path in a project's source tree. For
example, the file foo/src/bar/baz.h in
project foo should have the following
guard:
#ifndef FOO_BAR_BAZ_H_ #define FOO_BAR_BAZ_H_ @@ -436,14 +431,11 @@Names and Order of Includes
.h files..h
+ .h
files.constexpr variable of
- string_view, character array, or character pointer, pointing
+ std::string_view, character array, or character pointer, pointing
to a string literal. String literals have static storage duration already
and are usually sufficient.
See TotW #140.unique_ptr, shared_ptr): smart
+ std::unique_ptr, std::shared_ptr): smart
pointers execute cleanup during destruction and are therefore forbidden.
Consider whether your use case fits into one of the other patterns described
in this section. One simple solution is to use a plain pointer to a
@@ -1180,8 +1172,8 @@ Func({42, 3.14}); // Error
-This kind of code isn't technically an implicit conversion, but the
-language treats it as one as far as explicit is concerned.
+This kind of code isn't technically an implicit conversion, but the
+language treats it as one as far as explicit is concerned.
string_view parameter takes the
+ function with a std::string_view parameter takes the
place of separate overloads for std::string and
const char*.Limit the use of protected to those
member functions that might need to be accessed from
subclasses. Note that data
-members should be private.
private.
Explicitly annotate overrides of virtual functions or virtual
destructors with exactly one of an override or (less
@@ -1629,7 +1621,7 @@
Define operators only on your own types. More precisely,
-define them in the same headers, .cc files, and namespaces
+define them in the same headers, .cc files, and namespaces
as the types they operate on. That way, the operators are available
wherever the type is, minimizing the risk of multiple
definitions. If possible, avoid defining operators as templates,
@@ -1681,18 +1673,18 @@
const) if necessary.
For technical
-reasons, we allow data members of a test fixture class defined in a .cc file to
+reasons, we allow data members of a test fixture class defined in a .cc file to
be protected when using
Google
Test.
-If a test fixture class is defined outside of the .cc file it is used in, for example in a .h file,
+If a test fixture class is defined outside of the .cc file it is used in, for example in a .h file,
make data members private.
Group similar declarations together, placing public parts +
Group similar declarations together, placing public parts
earlier.
A class definition should usually start with a @@ -1812,8 +1804,8 @@
You may write a function that takes a const
std::string& and overload it with another that
takes const char*. However, in this case consider
-std::string_view
- instead.
std::string_view
+instead.
class MyClass {
public:
@@ -1827,7 +1819,7 @@ Function Overloading
identically-named function to take different arguments.
It may be necessary for templatized code, and it can be
convenient for Visitors.
-Overloading based on const or ref qualification may make utility
+
Overloading based on const or ref qualification may make utility
code more usable, more efficient, or both.
(See TotW 148 for more.)
@@ -1961,15 +1953,9 @@ Trailing Return Type Syntax
Google-Specific Magic
-
-
-
There are various tricks and utilities that
we use to make C++ code more robust, and various ways we use
C++ that may differ from what you see elsewhere.
-
-
-
Ownership and Smart Pointers
@@ -2030,7 +2016,7 @@ Ownership and Smart Pointers
bookkeeping, simplifying the code and ruling out large
classes of errors.const objects, shared ownership can be a simple
and efficient alternative to deep copying.Some projects have instructions on
how to run cpplint.py from their project
tools. If the project you are contributing to does not,
you can download
cpplint.py separately.
void f(std::string&&
s); declares a function whose argument is an
-rvalue reference to a std::string.
+rvalue reference to a std::string.
-When the token '&&' is applied to +
When the token && is applied to
an unqualified template argument in a function
parameter, special template argument deduction
rules apply. Such a reference is called forwarding reference.
Friends extend, but do not break, the encapsulation
boundary of a class. In some cases this is better than
-making a member public when you want to give only one
+making a member public when you want to give only one
other class access to it. However, most classes should
interact with other classes solely through their public
members.
int64_t y = int64_t{1} << 42. Do not use
cast formats like (int)x unless the cast is to
-void. You may use cast formats like `T(x)` only when
-`T` is a class type.
+void. You may use cast formats like T(x) only when
+T is a class type.
C++ introduced a @@ -2797,7 +2773,7 @@
const unless they
alter the logical state of the object (or enable the user to modify
- that state, e.g., by returning a non-const reference, but that's
+ that state, e.g., by returning a non-const reference, but that's
rare), or they can't safely be invoked concurrently.Prematurely marking something as constexpr may cause +
Prematurely marking something as constexpr may cause
migration problems if later on it has to be downgraded.
-Current restrictions on what is allowed in constexpr
+Current restrictions on what is allowed in constexpr
functions and constructors may invite obscure workarounds
in these definitions.
In order to maintain a high level of readability for all contributors who might read and maintain code, we only allow an approved subset of Boost features. @@ -3821,10 +3794,6 @@
We are actively considering adding other Boost features to the list, so this list may be expanded in the future.
-Like other declarations, aliases declared in a header file are part of that
header's public API unless they're in a function definition, in the private portion of a class,
- or in an explicitly-marked internal namespace. Aliases in such areas or in .cc files are
+ or in an explicitly-marked internal namespace. Aliases in such areas or in .cc files are
implementation details (because client code can't refer to them), and are not restricted by this
rule.
However, local convenience aliases are fine in function definitions, private sections of - classes, explicitly marked internal namespaces, and in .cc files:
+However, local convenience aliases are fine in function definitions, private sections of
+ classes, explicitly marked internal namespaces, and in .cc files:
// In a .cc file using ::foo::Bar; @@ -4202,7 +4171,7 @@-Self-describing code doesn't need a comment. The comment from -the example above would be obvious: +Struct Data Members
Constant Names
-Variables declared constexpr or const, and whose value is fixed for +
Variables declared
@@ -4242,10 +4211,10 @@constexprorconst, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case. Underscores can be used as separators in the rare cases where capitalization cannot be used for separation. For example:Function Names
Namespace Names
-Namespace names are all lower-case, with words separated by underscores. +Namespace names are all lower-case, with words separated by underscores. Top-level namespace names are based on the project name . Avoid collisions -between nested namespaces and well-known top-level namespaces. +between nested namespaces and well-known top-level namespaces.
The name of a top-level namespace should usually be the name of the project or team whose code is contained in that @@ -4374,26 +4343,19 @@
Comment Style
File Comments
-Start each file with license boilerplate.
-File comments describe the contents of a file. If a file declares, implements, or tests exactly one abstraction that is documented by a comment at the point of declaration, file comments are not required. All other files must have file comments.
-Legal Notice and Author -Line
- +Legal Notice and Author Line
- -Every file should contain license boilerplate. Choose the appropriate boilerplate for the license used by the project (for example, Apache 2.0, BSD, LGPL, GPL).
-If you make significant changes to a file with an author line, consider deleting the author line. @@ -4455,7 +4417,7 @@
Function Declarations
preceding it that describe what the function does and how to use it. These comments may be omitted only if the function is simple and obvious (e.g., simple accessors for obvious properties of the class). -Private methods and functions declared in `.cc` files are not exempt. +Private methods and functions declared in.ccfiles are not exempt. Function comments should be written with an implied subject of This function and should start with the verb phrase; for example, "Opens the file", rather than "Open the file". In general, these comments do not @@ -4652,8 +4614,8 @@Don'ts
}
Self-describing code doesn't need a comment. The comment from +the example above would be obvious:
if (!IsAlreadyProcessed(element)) {
Process(element);
@@ -4699,14 +4661,10 @@ TODO Comments
a TODO with a name, it is almost always your
name that is given.
-
-
-
// TODO(kl@gmail.com): Use a "*" here for concatenation operator.
// TODO(Zeke) change this to use relations.
// TODO(bug 12345): remove the "Last visitors" feature.
-
If your TODO is of the form "At a future
date do something" make sure that you either include a
@@ -4728,26 +4686,18 @@
Formatting
they can all read and understand
everyone's code easily.
-
-
-
To help you format code correctly, we've created a
settings file for emacs.
-
Line Length
Each line of text in your code should be at most 80
characters long.
-
-
-
We recognize that this rule is
controversial, but so much existing code already adheres
to it, and we feel that consistency is important.
-
Those who favor this rule
@@ -5211,7 +5161,6 @@
Loops and Switch Statements
-
switch (var) {
case 0: { // 2 space indent
... // 4 space indent
@@ -5226,7 +5175,6 @@ Loops and Switch Statements
}
}
-
Fall-through from one case label to
another must be annotated using the
@@ -5327,9 +5275,10 @@
Pointer and Reference Expressions
-It is allowed (if unusual) to declare multiple variables in the same
+It is allowed (if unusual) to declare multiple variables in the same
declaration, but it is disallowed if any of those have pointer or
-reference decorations. Such declarations are easily misread.
+reference decorations. Such declarations are easily misread.
+
// Fine if helpful for readability.
int x, y;
@@ -5711,9 +5660,6 @@ Exceptions to the Rules
However, like all good rules, these sometimes have exceptions,
which we discuss here.
-
-
-
Existing Non-conformant Code
You may diverge from the rules when dealing with code that
@@ -5728,10 +5674,6 @@
Existing Non-conformant Code
the code. Remember that consistency includes
local consistency, too.
-
-
-
-
Windows Code
Windows