minor cleanup

This commit is contained in:
Bjarne Stroustrup 2017-02-01 17:05:22 -05:00
parent 14f67ae8dd
commit f2dfcfc438

View File

@ -1,6 +1,6 @@
# <a name="main"></a>C++ Core Guidelines
December 12, 2016
February 1, 2017
Editors:
@ -6388,7 +6388,7 @@ A trivial getter or setter adds no semantic value; the data item could just as w
##### Example
class Point {
class Point { // Bad: verbose
int x;
int y;
public:
@ -6403,10 +6403,12 @@ A trivial getter or setter adds no semantic value; the data item could just as w
Consider making such a class a `struct` -- that is, a behaviorless bunch of variables, all public data and no member functions.
struct Point {
int x = 0;
int y = 0;
int x {0};
int y {0};
};
Note that we can put default initializers on member variables: [C.49: Prefer initialization to assignment in constructors](#Rc-initialize).
##### Note
A getter or a setter that converts from an internal type to an interface type is not trivial (it provides a form of information hiding).
@ -9316,7 +9318,7 @@ Assuming that there is a logical connection between `i` and `j`, that connection
Obviously, what we really would like is a construct that initialized n variables from a `tuple`. For example:
auto {i, j} = make_related_widgets(cond); // Not C++14
auto [i,j] = make_related_widgets(cond); // C++17, not C++14
Today, we might approximate that using `tie()`:
@ -13782,7 +13784,28 @@ This gives a more precise statement of design intent, better readability, more e
##### Note
[Do not cast away `const`](#Res-casts-const).
It is not inherently bad to pass a pointer or reference to non-const,
but that should be done only when the called function is supposed to modify the object.
A reader of code must assume that a funtion that takes a "plain" `T*` or `T&` will modify the object referred to.
If it doesn't now, it might do so later without forcing recompilation.
##### Note
There are code/libraries that are offer functions that declare a`T*` even though
those function do not modify that `T`.
This is a problem for people modernizing code.
You can
* update the library to be `const`-correct; preferred long-term solution
* "cast away `const`"; [best avoided](#Res-casts-const).
* provide a wrapper function; for example
void f(int* p); // old code: f() does not mpdify `*p`
void f(const int* p) { f(const_cast<int*>(p); } // wrapper
Note that this wrapper solution is a patch that should be used only when the declaration of `f()` cannot be be modified,
e.g. because it is in a library that you cannot modify.
##### Enforcement
@ -19152,10 +19175,11 @@ A relatively informal definition of terms used in the guidelines
This is our to-do list.
Eventually, the entries will become rules or parts of rules.
Alternatively, we will decide that no change is needed and delete the entry.
* No long-distance friendship
* Should physical design (what's in a file) and large-scale design (libraries, groups of libraries) be addressed?
* Namespaces
* Don't place using directives in headers
* Avoid using directives in the global scope (except for std, and other "fundamental" namespaces (e.g. experimental))
* 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?
* Should there be inline namespaces (à la `std::literals::*_literals`)?
* Avoid implicit conversions