From c885dc260bf95fc8a720a03c90e2436a33d82119 Mon Sep 17 00:00:00 2001
From: Daniel Cheng Single-line nested namespace declarations
are preferred in new code, but are not required.namespace my_project::my_component {
+
+ ...
+
+} // namespace my_project::my_component
+
structs should be used for passive objects that carry
data, and may have associated constants. All fields must be public. The
-struct must not have invariants that imply relationships between
+struct type itself must not have invariants that imply relationships between
different fields, since direct user access to those fields may
-break those invariants. Constructors, destructors, and helper methods may
-be present; however, these methods must not require or enforce any
-invariants.
If more functionality or invariants are required, or struct has wide visibility and expected to
evolve, then a class is more appropriate. If in doubt, make it a class.
@@ -1927,8 +1934,8 @@ instead.
class MyClass {
public:
- void Analyze(const std::string &text);
- void Analyze(const char *text, size_t textlen);
+ void Analyze(const std::string& text);
+ void Analyze(const char* text, size_t textlen);
};
@@ -2021,13 +2028,13 @@ doubt, use overloads.
C++ allows two different forms of function declarations. In the older form, the return type appears before the function name. For example:
-int foo(int x); +int Foo(int x);The newer form uses the
-autokeyword before the function name and a trailing return type after the argument list. For example, the declaration above could equivalently be written:auto foo(int x) -> int; +auto Foo(int x) -> int;The trailing return type is in the function's scope. This doesn't make a difference for a simple case like
particularly true when the return type depends on template parameters. For example:intbut it matters @@ -2046,17 +2053,16 @@ doubt, use overloads.template <typename T, typename U> - auto add(T t, U u) -> decltype(t + u); + auto Add(T t, U u) -> decltype(t + u);versustemplate <typename T, typename U> - decltype(declval<T&>() + declval<U&>()) add(T t, U u); + decltype(declval<T&>() + declval<U&>()) Add(T t, U u);-Trailing return type syntax is relatively new and it has no - analogue in C++-like languages such as C and Java, so some readers may - find it unfamiliar.
+Trailing return type syntax has no analogue in C++-like languages + such as C and Java, so some readers may find it unfamiliar.
Existing codebases have an enormous number of function declarations that aren't going to get changed to use the new syntax, so the realistic choices are using the old syntax only or using a mixture @@ -2169,8 +2175,8 @@ all copies, and the object is deleted when the last where the resource releases take place.
std::unique_ptr expresses ownership
- transfer using move semantics, which are
- relatively new and may confuse some programmers.Some people favor the form int const *foo
+
Some people favor the form int const* foo
to const int* foo. They argue that this is
more readable because it's more consistent: it keeps the
rule that const always follows the object
@@ -4493,10 +4499,10 @@ class UrlTableTester { ...
struct UrlTableProperties { ...
// typedefs
-typedef hash_map<UrlTableProperties *, std::string> PropertiesMap;
+typedef hash_map<UrlTableProperties*, std::string> PropertiesMap;
// using aliases
-using PropertiesMap = hash_map<UrlTableProperties *, std::string>;
+using PropertiesMap = hash_map<UrlTableProperties*, std::string>;
// enums
enum class UrlTableError { ...
@@ -4696,8 +4702,8 @@ than where the original name appears.
If you are naming something that is analogous to an -existing C or C++ entity then you can follow the existing +
If you are naming something that is analogous to an existing C or C++ +entity (or a Rust entity via interop), then you can follow the existing naming convention scheme.
TODOs should include the string
TODO in all caps, followed by the bug ID, name, e-mail address, or other identifier
of the person or issue with the best context
-about the problem referenced by the TODO.
+about the problem referenced by the TODO.
Recommended styles are (in order of preference):
-// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. +// TODO: bug 12345678 - Remove this after the 2047q4 compatibility window expires. // TODO: example.com/my-design-doc - Manually fix up this code the next time it's touched. // TODO(bug 12345678): Update this list after the Foo service is turned down. // TODO(John): Use a "\*" here for concatenation operator. @@ -5979,8 +5986,8 @@ if (x && !y) std::vector<std::string> x; y = static_cast<char*>(x); -// Spaces between type and pointer are OK, but be consistent. -std::vector<char *> x; +// No spaces between type and pointer. +std::vector<char*> x;Vertical Whitespace
@@ -6048,7 +6055,7 @@ style: and encouraged, that you use these types when calling Windows API functions. Even so, keep as close as you can to the underlying C++ types. For example, use -const TCHAR *instead of +const TCHAR*instead ofLPCTSTR.