mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Merge pull request #287 from tkruse/space-4
Code indent 4 spaces instead of tabs
This commit is contained in:
commit
130989e3aa
@ -397,7 +397,7 @@ A better approach is to be explicit about the meaning of the double (new speed o
|
||||
change_speed(Speed s); // better: the meaning of s is specified
|
||||
// ...
|
||||
change_speed(2.3); // error: no unit
|
||||
change_speed(23m/10s); // meters per second
|
||||
change_speed(23m / 10s); // meters per second
|
||||
|
||||
We could have accepted a plain (unit-less) `double` as a delta, but that would have been error-prone.
|
||||
If we wanted both absolute speed and deltas, we would have defined a `Delta` type.
|
||||
@ -744,6 +744,7 @@ Excess checking can be costly.
|
||||
There are cases where checking early is dumb because you may not ever need the value, or may only need part of the value that is more easily checked than the whole.
|
||||
|
||||
class Jet { // Physics says: e*e < x*x + y*y + z*z
|
||||
|
||||
float fx, fy, fz, fe;
|
||||
public:
|
||||
Jet(float x, float y, float z, float e)
|
||||
@ -1006,7 +1007,8 @@ Singletons are basically complicated global objects in disguise.
|
||||
##### Example
|
||||
|
||||
class Singleton {
|
||||
// ... lots of stuff to ensure that only one Singleton object is created, that it is initialized properly, etc.
|
||||
// ... lots of stuff to ensure that only one Singleton object is created,
|
||||
// that it is initialized properly, etc.
|
||||
};
|
||||
|
||||
There are many variants of the singleton idea.
|
||||
@ -1906,7 +1908,6 @@ We can refactor:
|
||||
double simpleFunc(double val, int flag1, int flag2)
|
||||
// simpleFunc: takes a value and calculates the expected ASIC output, given the two mode flags.
|
||||
{
|
||||
|
||||
if (flag1 > 0)
|
||||
return func1_muon(val, flag2);
|
||||
if (flag1 == -1)
|
||||
@ -2672,7 +2673,6 @@ After the return from a function its local objects no longer exist:
|
||||
int* p = f();
|
||||
int z = *p; // read from abandoned stack frame (bad)
|
||||
g(p); // pass pointer to abandoned stack frame to function (bad)
|
||||
|
||||
}
|
||||
|
||||
Here on one popular implementation I got the output:
|
||||
@ -2860,7 +2860,7 @@ Flag all uses of default arguments in virtual functions.
|
||||
|
||||
##### Reason
|
||||
|
||||
For efficiency and correctness, you nearly always want to capture by reference when using the lambda locally. This includes when writing or calling parallel algorithms that are local because they join before returning.
|
||||
For efficiency and correctness, you nearly always want to capture by reference when using the lambda locally. This includes when writing or calling parallel algorithms that are local because they join before returning.
|
||||
|
||||
##### Example
|
||||
|
||||
@ -4357,12 +4357,12 @@ But what if you can get significant better performance by not making a temporary
|
||||
|
||||
Vector& Vector::operator=(const Vector& a)
|
||||
{
|
||||
if (a.sz>sz) {
|
||||
if (a.sz > sz) {
|
||||
// ... use the swap technique, it can't be bettered ...
|
||||
return *this
|
||||
}
|
||||
// ... copy sz elements from *a.elem to elem ...
|
||||
if (a.sz<sz) {
|
||||
if (a.sz < sz) {
|
||||
// ... destroy the surplus elements in *this* and adjust size ...
|
||||
}
|
||||
return *this;
|
||||
@ -6006,7 +6006,7 @@ Here, we ignore such cases.
|
||||
* [R.33: Take a `unique_ptr<widget>&` parameter to express that a function reseats the`widget`](#Rr-reseat)
|
||||
* [R.34: Take a `shared_ptr<widget>` parameter to express that a function is part owner](#Rr-sharedptrparam-owner)
|
||||
* [R.35: Take a `shared_ptr<widget>&` parameter to express that a function might reseat the shared pointer](#Rr-sharedptrparam)
|
||||
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const&)
|
||||
* [R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const)
|
||||
* [R.37: Do not pass a pointer or reference obtained from an aliased smart pointer](#Rr-smartptrget)
|
||||
|
||||
### <a name="Rr-raii"></a> Rule R.1: Manage resources automatically using resource handles and RAII (resource acquisition is initialization)
|
||||
@ -6730,7 +6730,7 @@ This makes the function's reseating explicit.
|
||||
* (Simple) ((Foundation)) Warn if a function takes a `Shared_ptr<T>` by value or by reference to `const` and does not copy or move it to another `Shared_ptr` on at least one code path. Suggest taking a `T*` or `T&` instead.
|
||||
* (Simple) ((Foundation)) Warn if a function takes a `Shared_ptr<T>` by rvalue reference. Suggesting taking it by value instead.
|
||||
|
||||
### <a name="Rr-sharedptrparam-const&"></a> R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???
|
||||
### <a name="Rr-sharedptrparam-const"></a> R.36: Take a `const shared_ptr<widget>&` parameter to express that it might retain a reference count to the object ???
|
||||
|
||||
##### Reason
|
||||
|
||||
@ -7591,7 +7591,7 @@ It nicely encapsulates local initialization, including cleaning up scratch varia
|
||||
const widget x = [&]{
|
||||
widget val; // assume that widget has a default constructor
|
||||
for (auto i = 2; i <= N; ++i) { // this could be some
|
||||
val += some_obj.do_something_with(i);// arbitrarily long code
|
||||
val += some_obj.do_something_with(i); // arbitrarily long code
|
||||
} // needed to initialize x
|
||||
return val;
|
||||
}();
|
||||
@ -9138,7 +9138,7 @@ That would be a leak.
|
||||
void leak(int x) // don't: may leak
|
||||
{
|
||||
auto p = new int{7};
|
||||
if (x < 0) throw Get_me_out_of_here{}; // may leak *p
|
||||
if (x < 0) throw Get_me_out_of_here{} // may leak *p
|
||||
// ...
|
||||
delete p; // we may never get here
|
||||
}
|
||||
@ -9990,7 +9990,7 @@ Specifying semantics is a powerful design tool.
|
||||
{a - b} -> T;
|
||||
{a * b} -> T;
|
||||
{a / b} -> T;
|
||||
};
|
||||
}
|
||||
|
||||
##### Note
|
||||
|
||||
@ -11742,7 +11742,7 @@ Use of these casts can violate type safety and cause the program to access a var
|
||||
|
||||
##### Example, bad
|
||||
|
||||
class base { public: virtual ~base() =0; };
|
||||
class base { public: virtual ~base() = 0; };
|
||||
|
||||
class derived1 : public base { };
|
||||
|
||||
@ -12240,7 +12240,7 @@ Use `not_null<zstring>` for C-style strings that cannot be `nullptr`. ??? Do we
|
||||
* `narrow` // `narrow<T>(x)` is `static_cast<T>(x)` if `static_cast<T>(x) == x` or it throws `narrowing_error`
|
||||
* `implicit` // "Marker" to put on single-argument constructors to explicitly make them non-explicit
|
||||
(I don't know how to do that except with a macro: `#define implicit`).
|
||||
* `move_owner` // `p=move_owner(q)` means `p=q` but ???
|
||||
* `move_owner` // `p = move_owner(q)` means `p = q` but ???
|
||||
|
||||
## <a name="SS-concepts"></a> GSL.concept: Concepts
|
||||
|
||||
@ -13056,7 +13056,6 @@ If you define a destructor, you should not use the compiler-generated copy or mo
|
||||
HANDLE hnd;
|
||||
// ...
|
||||
public:
|
||||
|
||||
~X() { /* custom stuff, such as closing hnd */ }
|
||||
// suspicious: no mention of copying or moving -- what happens to hnd?
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user