Skip to content

Commit a9c4227

Browse files
committed
delete trailing whitespace
1 parent 55083af commit a9c4227

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

CppCoreGuidelines.md

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,7 +2972,7 @@ The language guarantees that a `T&` refers to an object, so that testing for `nu
29722972
wheel& get_wheel(size_t i) { Expects(i<4); return w[i]; }
29732973
// ...
29742974
};
2975-
2975+
29762976
void use()
29772977
{
29782978
car c;
@@ -5712,7 +5712,7 @@ Interfaces should normally be composed entirely of public pure virtual functions
57125712

57135713
The `Derived` is `delete`d through its `Goof` interface, so its `string` is leaked.
57145714
Give `Goof` a virtual destructor and all is well.
5715-
5715+
57165716

57175717
##### Enforcement
57185718

@@ -5733,14 +5733,14 @@ Such as on an ABI (link) boundary.
57335733

57345734
class D1 : public Device {
57355735
// ... data ...
5736-
5736+
57375737
void write(span<const char> outbuf) override;
57385738
void read(span<char> inbuf) override;
57395739
};
57405740

57415741
class D2 : public Device {
57425742
// ... differnt data ...
5743-
5743+
57445744
void write(span<const char> outbuf) override;
57455745
void read(span<char> inbuf) override;
57465746
};
@@ -5831,7 +5831,7 @@ Use `virtual` only when declaring a new virtual function. Use `override` only wh
58315831
};
58325832

58335833
struct D2 : B {
5834-
virtual void f2(int) final; // BAD; pitfall, D2::f does not override B::f
5834+
virtual void f2(int) final; // BAD; pitfall, D2::f does not override B::f
58355835
};
58365836

58375837
##### Enforcement
@@ -6130,7 +6130,7 @@ However, misuses are (or at least has been) far more common.
61306130
##### Enforcement
61316131

61326132
Flag uses of `final`.
6133-
6133+
61346134

61356135
## <a name="Rh-virtual-default-arg"></a>C.140: Do not provide different default arguments for a virtual function and an overrider
61366136

@@ -6645,7 +6645,7 @@ Many parts of the C++ semantics assumes its default meaning.
66456645
private:
66466646
T* p;
66476647
};
6648-
6648+
66496649
class X {
66506650
Ptr operator&() { return Ptr{this}; }
66516651
// ...
@@ -6753,7 +6753,7 @@ By itself, `cout_my_class` would be OK, but it is not usable/composabe with code
67536753

67546754
##### Note
67556755

6756-
There are strong and vigorous conventions for the meaning most operators, such as
6756+
There are strong and vigorous conventions for the meaning most operators, such as
67576757

67586758
* comparisons (`==`, `!=`, `<`, `<=`, `>`, and `>=`),
67596759
* arithmetic operations (`+`, `-`, `*`, `/`, and `%`)
@@ -9532,7 +9532,7 @@ double or int64 from int32), brace initialization may be used instead.
95329532
This makes it clear that the type conversion was intended and also prevents
95339533
conversions between types that might result in loss of precision. (It is a
95349534
compilation error to try to initialize a float from a double in this fashion,
9535-
for example.)
9535+
for example.)
95369536

95379537
##### Enforcement
95389538

@@ -9589,7 +9589,7 @@ Moving is done implicitly when the source is an rvalue (e.g., value in a `return
95899589

95909590
In general, following the guidelines in this document (including not making variables' scopes needlessly large, writing short functions that return values, returning local variables) help eliminate most need for explicit `std::move`.
95919591

9592-
Explicit `move` is needed to explicitly move an object to another scope, notably to pass it to a "sink" function and in the implementations of the move operations themselves (move constructor, move assignment operator) and swap operations.
9592+
Explicit `move` is needed to explicitly move an object to another scope, notably to pass it to a "sink" function and in the implementations of the move operations themselves (move constructor, move assignment operator) and swap operations.
95939593

95949594
##### Example, bad
95959595

@@ -9612,7 +9612,7 @@ And after you do that, assume the object has been moved from (see [C.64](#Rc-mov
96129612

96139613
string s2 = s1; // ok, takes a copy
96149614
assert(s1=="supercalifragilisticexpialidocious"); // ok
9615-
9615+
96169616
string s3 = move(s1); // bad, if you want to keep using s1's value
96179617
assert(s1=="supercalifragilisticexpialidocious"); // bad, assert will likely fail, s1 likely changed
96189618
}
@@ -9624,9 +9624,9 @@ And after you do that, assume the object has been moved from (see [C.64](#Rc-mov
96249624
void f() {
96259625
auto w = make_unique<widget>();
96269626
// ...
9627-
sink( std::move(w) ); // ok, give to sink()
9627+
sink( std::move(w) ); // ok, give to sink()
96289628
// ...
9629-
sink(w); // Error: unique_ptr is carefully designed so that you cannot copy it
9629+
sink(w); // Error: unique_ptr is carefully designed so that you cannot copy it
96309630
}
96319631

96329632
##### Notes
@@ -9648,7 +9648,7 @@ In general, don't complicate your code without reason (??)
96489648

96499649
Never write `return move(local_variable);`, because the language already knows the variable is a move candidate.
96509650
Writing `move` in this code won't help, and can actually be detrimental because on some compilers it interferes with RVO (the return value optimization) by creating an additional reference alias to the local variable.
9651-
9651+
96529652

96539653
##### Example, bad
96549654

@@ -9676,7 +9676,7 @@ The language already knows that a returned value is a temporary object that can
96769676

96779677
* Flag use of `std::move(x)` where `x` is an rvalue or the language will already treat it as an rvalue, including `return std::move(local_variable);` and `std::move(f())` on a function that returns by value.
96789678
* Flag functions taking an `S&&` parameter if there is no `const S&` overload to take care of lvalues.
9679-
* Flag a `std::move`s argument passed to a parameter, except when the parameter type is one of the following: an `X&&` rvalue reference; a `T&&` forwarding reference where `T` is a template parameter type; or by value and the type is move-only.
9679+
* Flag a `std::move`s argument passed to a parameter, except when the parameter type is one of the following: an `X&&` rvalue reference; a `T&&` forwarding reference where `T` is a template parameter type; or by value and the type is move-only.
96809680
* Flag when `std::move` is applied to a forwarding reference (`T&&` where `T` is a template parameter type). Use `std::forward` instead.
96819681
* Flag when `std::move` is applied to other than an rvalue reference. (More general case of the previous rule to cover the non-forwarding cases.)
96829682
* Flag when `std::forward` is applied to an rvalue reference (`X&&` where `X` is a concrete type). Use `std::move` instead.
@@ -10927,7 +10927,7 @@ This, of course, assumes a good implementation of the exception handling mechani
1092710927
There are also cases where the problems above do not apply, but exceptions cannot be used for other reasons.
1092810928
Some hard real-time systems are an example: An operation has to be completed within a fixed time with an error or a correct answer.
1092910929
In the absence of appropriate time estimation tools, this is hard to guarantee for exceptions.
10930-
Such systems (e.g. flight control software) typically also ban the use of dynamic (heap) memory.
10930+
Such systems (e.g. flight control software) typically also ban the use of dynamic (heap) memory.
1093110931

1093210932
So, the primary guideline for error handling is "use exceptions and [RAII](#Re-raii)."
1093310933
This section deals with the cases where you either do not have an efficient implementation or exceptions
@@ -11065,7 +11065,7 @@ For example:
1106511065
if (!r.second) {
1106611066
// error handling
1106711067
}
11068-
Gadget& g = r.first;
11068+
Gadget& g = r.first;
1106911069
// ...
1107011070
}
1107111071

@@ -11084,7 +11084,7 @@ For example:
1108411084
if (!r.err) {
1108511085
// error handling
1108611086
}
11087-
Gadget& g = r.val;
11087+
Gadget& g = r.val;
1108811088
// ...
1108911089
}
1109011090

@@ -11102,21 +11102,21 @@ This can be messy:
1110211102
if (!g1.valid()) {
1110311103
return {0,g1_error};
1110411104
}
11105-
11105+
1110611106
Gadget g2 = make_gadget(17);
1110711107
if (!g2.valid()) {
1110811108
cleanup(g1);
1110911109
return {0,g2_error};
1111011110
}
11111-
11111+
1111211112
// ...
11113-
11113+
1111411114
if (all_foobar(g1,g2)) {
1111511115
cleanup(g1);
1111611116
cleanup(g2);
1111711117
return {0,foobar_error};
1111811118
// ...
11119-
11119+
1112011120
cleanup(g1);
1112111121
cleanup(g2);
1112211122
return {res,0};
@@ -11128,26 +11128,26 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi
1112811128
std::pair<int,error_indicator> user()
1112911129
{
1113011130
error_indicator err = 0;
11131-
11131+
1113211132
Gadget g1 = make_gadget(17);
1113311133
if (!g1.valid()) {
1113411134
err = g2_error;
1113511135
goto exit;
1113611136
}
11137-
11137+
1113811138
Gadget g2 = make_gadget(17);
1113911139
if (!g2.valid()) {
1114011140
err = g2_error;
1114111141
goto exit;
1114211142
}
11143-
11143+
1114411144
if (all_foobar(g1,g2)) {
1114511145
err = foobar_error;
1114611146
goto exit;
1114711147
}
1114811148
// ...
1114911149

11150-
exit:
11150+
exit:
1115111151
if (g1.valid()) cleanup(g1);
1115211152
if (g1.valid()) cleanup(g2);
1115311153
return {res,err};
@@ -11294,7 +11294,7 @@ but that should be done only when the called function is supposed to modify the
1129411294
{
1129511295
int x = 7;
1129611296
const int y = 9;
11297-
11297+
1129811298
for (;;) {
1129911299
// ...
1130011300
}
@@ -12087,10 +12087,10 @@ The rule supports the view that a concept should reflect a (mathematically) cohe
1208712087
{
1208812088
if (!(x==y) { /* ... */ } // OK
1208912089
if (x!=y) { /* ... */ } //surprise! error
12090-
12090+
1209112091
while (!(x<y)) { /* ... */ } // OK
1209212092
while (x>=y) { /* ... */ } //surprise! error
12093-
12093+
1209412094
x = x+y; // OK
1209512095
x += y; // surprise! error
1209612096
}
@@ -12114,10 +12114,10 @@ It could even be less efficient.
1211412114
{
1211512115
if (!(x==y) { /* ... */ } // OK
1211612116
if (x!=y) { /* ... */ } //OK
12117-
12117+
1211812118
while (!(x<y)) { /* ... */ } // OK
1211912119
while (x>=y) { /* ... */ } //OK
12120-
12120+
1212112121
x = x+y; // OK
1212212122
x += y; // OK
1212312123
}
@@ -13533,7 +13533,7 @@ For a variable-length array, use `std::vector`, which additionally can change it
1353313533
##### Example
1353413534

1353513535
int v[SIZE]; // BAD
13536-
13536+
1353713537
std::array<int,SIZE> w; // ok
1353813538

1353913539
##### Example
@@ -13557,15 +13557,15 @@ Even when other containers seem more suited, such a `map` for O(log N) lookup pe
1355713557

1355813558
##### Note
1355913559

13560-
`string` should not be used as a container of individual characters. A `string` is a textual string; if you want a container of characters, use `vector</*char_type*/>` or `array</*char_type*/>` instead.
13560+
`string` should not be used as a container of individual characters. A `string` is a textual string; if you want a container of characters, use `vector</*char_type*/>` or `array</*char_type*/>` instead.
1356113561

1356213562
##### Exceptions
1356313563

1356413564
If you have a good reason to use another container, use that instead. For example:
1356513565

1356613566
* If `vector` suits your needs but you don't need the container to be variable size, use `array` instead.
1356713567

13568-
* If you want a dictionary-style lookup container that guarantees O(K) or O(log N) lookups, the container will be larger (more than a few KB) and you perform frequent inserts so that the overhead of maintaining a sorted `vector` is infeasible, go ahead and use an `unordered_map` or `map` instead.
13568+
* If you want a dictionary-style lookup container that guarantees O(K) or O(log N) lookups, the container will be larger (more than a few KB) and you perform frequent inserts so that the overhead of maintaining a sorted `vector` is infeasible, go ahead and use an `unordered_map` or `map` instead.
1356913569

1357013570
##### Enforcement
1357113571

@@ -13905,17 +13905,17 @@ Sometimes you may be tempted to resort to `const_cast` to avoid code duplication
1390513905
class foo {
1390613906
bar mybar;
1390713907
public: // BAD, duplicates logic
13908-
bar& get_bar() { /* complex logic around getting a non-const reference to mybar */ }
13909-
const bar& get_bar() const { /* same complex logic around getting a const reference to mybar */ }
13908+
bar& get_bar() { /* complex logic around getting a non-const reference to mybar */ }
13909+
const bar& get_bar() const { /* same complex logic around getting a const reference to mybar */ }
1391013910
};
1391113911

1391213912
Instead, prefer to share implementations. Normally, you can just have the non-`const` function call the `const` function. However, when there is complex logic this can lead to the following pattern that still resorts to a `const_cast`:
1391313913

1391413914
class foo {
1391513915
bar mybar;
1391613916
public: // not great, non-const calls const version but resorts to const_cast
13917-
bar& get_bar() { return const_cast<bar&>(static_cast<const foo&>(*this).get_bar()); }
13918-
const bar& get_bar() const { /* the complex logic around getting a const reference to mybar */ }
13917+
bar& get_bar() { return const_cast<bar&>(static_cast<const foo&>(*this).get_bar()); }
13918+
const bar& get_bar() const { /* the complex logic around getting a const reference to mybar */ }
1391913919
};
1392013920

1392113921
Although this pattern is safe when applied correctly, because the caller must have had a non-`const` object to begin with, it's not ideal because the safety is hard to enforce automatically as a checker rule.
@@ -13927,11 +13927,11 @@ Instead, prefer to put the common code in a common helper function -- and make i
1392713927

1392813928
template<class T> // good, deduces whether T is const or non-const
1392913929
static auto get_bar_impl(T& t) -> decltype(t.get_bar())
13930-
{ /* the complex logic around getting a possibly-const reference to mybar */ }
13930+
{ /* the complex logic around getting a possibly-const reference to mybar */ }
1393113931

1393213932
public: // good
13933-
bar& get_bar() { return get_bar_impl(*this); }
13934-
const bar& get_bar() const { return get_bar_impl(*this); }
13933+
bar& get_bar() { return get_bar_impl(*this); }
13934+
const bar& get_bar() const { return get_bar_impl(*this); }
1393513935
};
1393613936

1393713937
**Exception**: You may need to cast away `const` when calling `const`-incorrect functions. Prefer to wrap such functions in inline `const`-correct wrappers to encapsulate the cast in one place.
@@ -15072,7 +15072,7 @@ Here is an example of the last option:
1507215072

1507315073
template<class T>
1507415074
friend shared_ptr<T> B::Create();
15075-
};
15075+
};
1507615076

1507715077
shared_ptr<D> p = D::Create<D>(); // creating a D object
1507815078

0 commit comments

Comments
 (0)