From 8b0c7b011d62a34d67ec92001a453466cf51d3d6 Mon Sep 17 00:00:00 2001
From: parmaski <89462537+parmaski@users.noreply.github.com>
Date: Mon, 17 Oct 2022 09:35:24 +0900
Subject: [PATCH 1/2] Add Limit the use of tag and namespace, if appropriate
---
cppguide.html | 50 +++++++++++++++++++++++++-------------------------
1 file changed, 25 insertions(+), 25 deletions(-)
diff --git a/cppguide.html b/cppguide.html
index a7f32245a..9076a3e01 100644
--- a/cppguide.html
+++ b/cppguide.html
@@ -958,7 +958,7 @@
Common patterns
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.Common patterns
If you do really prefer a dynamic container from the standard library, consider using
a function-local static pointer, as described below
.
- 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
@@ -1190,7 +1190,7 @@ Implicit Conversions
when it's obvious.string_view
parameter takes the
+ function with a std::string_view
parameter takes the
place of separate overloads for std::string
and
const char*
.Inheritance
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 +1629,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 +1681,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 +1812,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 +1827,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
@@ -2030,7 +2030,7 @@const
or ref qualification may make utility code more usable, more efficient, or both. (See TotW 148 for more.)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.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 +2797,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.
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 +4202,7 @@Struct Data Members
Constant Names
-Variables declared constexpr or const, and whose value is fixed for +
Variables declared
@@ -4455,7 +4455,7 @@constexpr
orconst
, 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 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.cc
files 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 From eb77c1b552a9b09c3538b5d2b8cd5d224473610d Mon Sep 17 00:00:00 2001 From: parmaski <89462537+parmaski@users.noreply.github.com> Date: Mon, 17 Oct 2022 09:49:43 +0900 Subject: [PATCH 2/2] Add necessaryand remove unnecessary
--- cppguide.html | 84 ++++++++------------------------------------------- 1 file changed, 13 insertions(+), 71 deletions(-) diff --git a/cppguide.html b/cppguide.html index 9076a3e01..8404516b3 100644 --- a/cppguide.html +++ b/cppguide.html @@ -174,9 +174,8 @@C++ Version
Do not use non-standard extensions.
-Consider portability to other environments -before using features from C++14 and C++17 in your project. -+Consider portability to other environments +before using features from C++14 and C++17 in your project.
Header Files
@@ -230,15 +229,11 @@The #define Guard
<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 projectfoo
should have the following guard:#ifndef FOO_BAR_BAZ_H_ #define FOO_BAR_BAZ_H_ @@ -436,14 +431,11 @@Names and Order of Includes
A blank line --Other libraries' .h
files.A blank line -- Your project's .h
+Your project's @@ -1180,8 +1172,8 @@.h
files.Implicit Conversions
Func({42, 3.14}); // Error-This kind of code isn't technically an implicit conversion, but the -language treats it as one as far asexplicit
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.@@ -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
@@ -2108,18 +2094,12 @@cpplint
positives and false negatives, but it is still a valuable tool. - - -- -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 downloadcpplint.py
separately.Other C++ Features
@@ -2243,14 +2223,10 @@Exceptions
nested functions, without the obscuring and error-prone bookkeeping of error codes. - - -- Exceptions are used by most other modern languages. Using them in C++ would make it more consistent with Python, Java, and the C++ that others are familiar with.
-- Some third-party C++ libraries use exceptions, and turning them off internally makes it harder to @@ -3746,9 +3722,6 @@
Boost
- - -- - -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 @@
Boost
We are actively considering adding other Boost features to the list, so this list may be expanded in the future.
-Other C++ Features
@@ -4242,10 +4211,10 @@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. @@ -4652,8 +4614,8 @@
Don'ts
} -Self-describing code doesn't need a comment. The comment from -the example above would be obvious: +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
aTODO
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