diff --git a/cppguide.html b/cppguide.html index c6dce95df..6c52c111c 100644 --- a/cppguide.html +++ b/cppguide.html @@ -247,14 +247,37 @@

The #define Guard

+

Include What You Use

+ +

If a source or header file refers to a symbol defined elsewhere, +the file should directly include a header file which properly intends +to provide a declaration or definition of that symbol. It should not +include header files for any other reason. +

+ +

Do not rely on transitive inclusions. This allows people to remove +no-longer-needed #include statements from their headers without +breaking clients. This also applies to related headers +- foo.cc should include bar.h if it uses a +symbol from it even if foo.h +includes bar.h.

+

Forward Declarations

Avoid using forward declarations where possible. -Instead, #include the headers you need.

+ Instead, include the headers you need. +

+

-

A "forward declaration" is a declaration of a class, -function, or template without an associated definition.

+

A "forward declaration" is a declaration of an entity + without an associated definition.

+
// In a C++ source file:
+class B;
+void FuncInB();
+extern int variable_in_b;
+ABSL_DECLARE_FLAG(flag_in_b);
+

- - -

Please see Names and Order -of Includes for rules about when to #include a header.

+Try to avoid forward declarations of entities +defined in another project.

Inline Functions

@@ -453,14 +469,6 @@

Names and Order of Includes

alphabetically. Note that older code might not conform to this rule and should be fixed when convenient.

-

You should include all the headers that define the symbols you rely -upon, except in the unusual case of forward -declaration. If you rely on symbols from bar.h, -don't count on the fact that you included foo.h which -(currently) includes bar.h: include bar.h -yourself, unless foo.h explicitly demonstrates its intent -to provide you the symbols of bar.h.

-

For example, the includes in google-awesome-project/src/foo/internal/fooserver.cc @@ -563,7 +571,7 @@

Namespaces

-

Template metaprogramming

+

Template Metaprogramming

Avoid complicated template programming.

@@ -3639,7 +3649,7 @@

Template metaprogramming

Template metaprogramming allows extremely flexible interfaces that are type safe and high performance. Facilities like -Google Test, +Google Test, std::tuple, std::function, and Boost.Spirit would be impossible without it.

@@ -3795,8 +3805,6 @@

Boost

the future.

- -

std::hash

Do not define specializations of std::hash.

@@ -3870,7 +3878,7 @@

std::hash

-

Other C++ Features

+

Other C++ Features

As with Boost, some modern C++ extensions encourage coding practices that hamper @@ -4029,6 +4037,21 @@

Aliases

using ::foo::Bar; +

Inclusive Language

+ +

In all code, including naming and comments, use inclusive language +and avoid terms that other programmers might find disrespectful or offensive +(such as "master" and "slave", "blacklist" and "whitelist", or "redline"), +even if the terms also have an ostensibly neutral meaning. +Similarly, use gender-neutral language unless you're referring +to a specific person (and using their preferred pronouns). For example, +use "they"/"them"/"their" for people of unspecified gender +(even +when singular), and "it"/"its" for software, computers, and other +things that aren't people.

+ + +

Naming

The most important consistency rules are those that govern @@ -4270,8 +4293,8 @@

Function Names

Namespace Names

-Namespace names are all lower-case. Top-level namespace names are -based on the project name +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. @@ -4446,11 +4469,10 @@

Class Comments

// Iterates over the contents of a GargantuanTable.
 // Example:
-//    GargantuanTableIterator* iter = table->NewIterator();
+//    std::unique_ptr<GargantuanTableIterator> iter = table->NewIterator();
 //    for (iter->Seek("foo"); !iter->done(); iter->Next()) {
 //      process(iter->key(), iter->value());
 //    }
-//    delete iter;
 class GargantuanTableIterator {
   ...
 };
@@ -4494,7 +4516,9 @@ 

Function Declarations

declaration:

-

When declaring a pointer variable or argument, you may -place the asterisk adjacent to either the type or to the +

When declaring a pointer or reference variable or argument, you may +place the asterisk/ampersand adjacent to either the type or the variable name:

// These are fine, space preceding.
@@ -5385,6 +5406,7 @@ 

Pointer and Reference Expressions

int x, *y;  // Disallowed - no & or * in multiple declaration
+int* x, *y;  // Disallowed - no & or * in multiple declaration; inconsistent spacing
 char * c;  // Bad - spaces on both sides of *
 const std::string & str;  // Bad - spaces on both sides of &
 
@@ -5440,9 +5462,6 @@

Return Values

Variable and Array Initialization

-

Your choice of =, (), or -{}.

-

You may choose between =, (), and {}; the following are all correct: