You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CppCoreGuidelines.md
+31-31Lines changed: 31 additions & 31 deletions
Original file line number
Diff line number
Diff line change
@@ -371,7 +371,7 @@ The second version leaves the reader guessing and opens more possibilities for u
371
371
372
372
##### Example
373
373
374
-
void do_something(vector<string>& v)
374
+
void f(vector<string>& v)
375
375
{
376
376
string val;
377
377
cin >> val;
@@ -388,7 +388,7 @@ The second version leaves the reader guessing and opens more possibilities for u
388
388
That loop is a restricted form of `std::find`.
389
389
A much clearer expression of intent would be:
390
390
391
-
void do_something(vector<string>& v)
391
+
void f(vector<string>& v)
392
392
{
393
393
string val;
394
394
cin >> val;
@@ -2315,13 +2315,13 @@ When copying is cheap, nothing beats the simplicity and safety of copying, and f
2315
2315
2316
2316
##### Example
2317
2317
2318
-
void f(const string& s); // OK: pass by reference to const; always cheap
2318
+
void f1(const string& s); // OK: pass by reference to const; always cheap
2319
2319
2320
-
void f2(string s); // bad: potentially expensive
2320
+
void f2(string s); // bad: potentially expensive
2321
2321
2322
-
void f3(int x); // OK: Unbeatable
2322
+
void f3(int x); // OK: Unbeatable
2323
2323
2324
-
void f4(const int& x); // bad: overhead on access in f4()
2324
+
void f4(const int& x); // bad: overhead on access in f4()
2325
2325
2326
2326
For advanced uses (only), where you really need to optimize for rvalues passed to "input-only" parameters:
2327
2327
@@ -4707,7 +4707,7 @@ If the state of a base class object must depend on the state of a derived part o
4707
4707
}
4708
4708
};
4709
4709
4710
-
class D : public B { /* "¦ */ }; // some derived class
4710
+
class D : public B { /* ... */ }; // some derived class
4711
4711
4712
4712
shared_ptr<D> p = D::Create<D>(); // creating a D object
4713
4713
@@ -5739,13 +5739,13 @@ Such as on an ABI (link) boundary.
5739
5739
};
5740
5740
5741
5741
class D2 : public Device {
5742
-
// ... differnt data ...
5743
-
5742
+
// ... different data ...
5743
+
5744
5744
void write(span<const char> outbuf) override;
5745
5745
void read(span<char> inbuf) override;
5746
5746
};
5747
5747
5748
-
A user can now use `D1`s and `D2`s interrchangeably through the interface provided by `Device`.
5748
+
A user can now use `D1`s and `D2`s interchangeably through the interface provided by `Device`.
5749
5749
Furthermore, we can update `D1` and `D2` in a ways that are not binarily compatible with older versions as long as all access goes through `Device`.
5750
5750
5751
5751
##### Enforcement
@@ -6745,7 +6745,7 @@ Readability. Convention. Reusability. Support for generic code
6745
6745
return os << /* class members here */;
6746
6746
}
6747
6747
6748
-
By itself, `cout_my_class` would be OK, but it is not usable/composabe with code that rely on the `<<` convention for output:
6748
+
By itself, `cout_my_class` would be OK, but it is not usable/composable with code that rely on the `<<` convention for output:
6749
6749
6750
6750
My_class var { /* ... */ };
6751
6751
// ...
@@ -7027,7 +7027,7 @@ Here, we ignore such cases.
7027
7027
* [R.30: Take smart pointers as parameters only to explicitly express lifetime semantics](#Rr-smartptrparam)
7028
7028
* [R.31: If you have non-`std` smart pointers, follow the basic pattern from `std`](#Rr-smart)
7029
7029
* [R.32: Take a `unique_ptr<widget>` parameter to express that a function assumes ownership of a `widget`](#Rr-uniqueptrparam)
7030
-
* [R.33: Take a `unique_ptr<widget>&` parameter to express that a function reseats the`widget`](#Rr-reseat)
7030
+
* [R.33: Take a `unique_ptr<widget>&` parameter to express that a function reseats the`widget`](#Rr-reseat)
7031
7031
* [R.34: Take a `shared_ptr<widget>` parameter to express that a function is part owner](#Rr-sharedptrparam-owner)
7032
7032
* [R.35: Take a `shared_ptr<widget>&` parameter to express that a function might reseat the shared pointer](#Rr-sharedptrparam)
7033
7033
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const)
@@ -7272,7 +7272,7 @@ The members of a scoped object are themselves scoped and the scoped object's con
7272
7272
7273
7273
##### Example
7274
7274
7275
-
The following example is inefficient (because it has unnecessary allocation and deallocation), vulnerable to exception throws and returns in the "¦ part (leading to leaks), and verbose:
7275
+
The following example is inefficient (because it has unnecessary allocation and deallocation), vulnerable to exception throws and returns in the `...` part (leading to leaks), and verbose:
7276
7276
7277
7277
void f(int n)
7278
7278
{
@@ -8445,7 +8445,7 @@ solution:
8445
8445
j = f4();
8446
8446
}
8447
8447
8448
-
Now the compiler cannot even simply detect a used-before-set. Further, we've introduced complexity in the state space for widget: which operations are valid on an `unint` widget and which are not?
8448
+
Now the compiler cannot even simply detect a used-before-set. Further, we've introduced complexity in the state space for widget: which operations are valid on an `uninit` widget and which are not?
8449
8449
8450
8450
##### Note
8451
8451
@@ -9127,7 +9127,7 @@ It is easy to overlook the fallthrough. Be explicit:
9127
9127
break;
9128
9128
case Warning:
9129
9129
write_event_log();
9130
-
// fall through
9130
+
// fallthrough
9131
9131
case Error:
9132
9132
display_error_window(); // Bad
9133
9133
break;
@@ -9149,7 +9149,7 @@ Multiple case labels of a single statement is OK:
bool operator==(int, Bad::S) { cout << "T0\n"; return true; } // compate to int
12265
+
bool operator==(int, Bad::S) { cout << "T0\n"; return true; } // compare to int
12266
12266
12267
12267
void test()
12268
12268
{
@@ -15691,7 +15691,7 @@ Alternatively, we will decide that no change is needed and delete the entry.
15691
15691
* How granular should namespaces be? All classes/functions designed to work together and released together (as defined in Sutter/Alexandrescu) or something narrower or wider?
15692
15692
* Should there be inline namespaces (à la `std::literals::*_literals`)?
15693
15693
* Avoid implicit conversions
15694
-
* Const member functions should be thread safe "¦ aka, but I don't really change the variable, just assign it a value the first time it’s called "¦ argh
15694
+
* Const member functions should be thread safe ... aka, but I don't really change the variable, just assign it a value the first time it’s called ... argh
15695
15695
* Always initialize variables, use initialization lists for member variables.
15696
15696
* Anyone writing a public interface which takes or returns `void*` should have their toes set on fire. That one has been a personal favorite of mine for a number of years. :)
15697
15697
* Use `const`-ness wherever possible: member functions, variables and (yippee) `const_iterators`
0 commit comments