Skip to content

Commit c553535

Browse files
fixing typos
adding "concept" markers, hopefully to minimize confusion
1 parent bf5635d commit c553535

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

CppCoreGuidelines.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10694,7 +10694,7 @@ Application concepts are easier to reason about.
1069410694

1069510695
???
1069610696

10697-
###### Note
10697+
##### Note
1069810698

1069910699
With the exception of `async()`, the standard-library facilities are low-level, machine-oriented, threads-and-lock level.
1070010700
This is a necessary foundation, but we have to try to raise the level of abstrcation: for productivity, for reliability, and for performance.
@@ -11117,7 +11117,7 @@ A `thread` that has not been `detach()`ed when it is destroyed terminates the pr
1111711117

1111811118
### <a name="RRconc-pass"></a>CP.30: Do not pass pointers to local variables to non-`raii_thread's
1111911119

11120-
###### Reason
11120+
##### Reason
1112111121

1112211122
In general, you cannot know whether a non-`raii_thread` will outlife your thread (so that those pointers will become invalid.
1112311123

@@ -11264,7 +11264,7 @@ Instead, we could have a set of pre-created worker threads processing the messag
1126411264
raii_thread w4 {worker};
1126511265
}
1126611266

11267-
###### Note
11267+
##### Note
1126811268

1126911269
If you system has a good thread pool, use it.
1127011270
If your system has a good message queue, use it.
@@ -11662,11 +11662,11 @@ For example, reading `clock` twice will often yield two different values, so the
1166211662

1166311663
`clock` is `const` because the program should not try to write to `clock`.
1166411664

11665-
###### Note
11665+
##### Note
1166611666

1166711667
Unless you are writing the lowest level code manipulating hardware directly, consider `volatile` an esoteric feature that is best avoided.
1166811668

11669-
###### Example
11669+
##### Example
1167011670

1167111671
Usually C++ code receives `volatile` memory that is owned Elsewhere (hardware or another language):
1167211672

@@ -12462,7 +12462,7 @@ For example:
1246212462
One reason to prefer a specific return type is to have names for its members, rather than the somewhat cryptic `first` and `second`
1246312463
and to avoid confusion with other uses of `std::pair`.
1246412464

12465-
###### Example
12465+
##### Example
1246612466

1246712467
In general, you must clean up before an error exit.
1246812468
This can be messy:
@@ -13081,18 +13081,18 @@ Flag template type arguments without concepts
1308113081

1308213082
##### Reason
1308313083

13084-
"Standard" concepts (as provided by the [GSL]#S-GSL), the ISO concepts TS, [Ranges TS](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4569.pdf), and hopefully soon the ISO standard itself)
13084+
"Standard" concepts (as provided by the [GSL](#S-GSL) and the [Ranges TS](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4569.pdf), and hopefully soon the ISO standard itself)
1308513085
saves us the work of thinking up our own concepts, are better thought out than we can manage to do in a hurry, and improves interoperability.
1308613086

1308713087
##### Note
1308813088

1308913089
Unless you are creating a new generic library, most of the concepts you need will already be defined by the standard library.
1309013090

13091-
##### Example, bad
13091+
##### Example (using TS concepts)
1309213092

13093-
concept<typename T>
13094-
// don't define this: Sortable is in the GSL
13095-
Ordered_container = Sequence<T> && Random_access<Iterator<T>> && Ordered<Value_type<T>>;
13093+
template<typename T>
13094+
// don't define this: Sortable is in the GSL
13095+
concept Ordered_container = Sequence<T> && Random_access<Iterator<T>> && Ordered<Value_type<T>>;
1309613096

1309713097
void sort(Ordered_container& s);
1309813098

@@ -13104,7 +13104,7 @@ It is better and simpler just to use `Sortable`:
1310413104

1310513105
##### Note
1310613106

13107-
The set of "standard" concepts is evolving as we approach real (ISO) standardization.
13107+
The set of "standard" concepts is evolving as we approach an ISO standard including concepts.
1310813108

1310913109
##### Note
1311013110

@@ -13123,11 +13123,11 @@ Hard.
1312313123

1312413124
`auto` is the weakest concept. Concept names convey more meaning than just `auto`.
1312513125

13126-
##### Example
13126+
##### Example (using TS concepts)
1312713127

1312813128
vector<string> v;
1312913129
auto& x = v.front(); // bad
13130-
String& s = v.begin(); // good
13130+
String& s = v.begin(); // good (String is a GSL concept)
1313113131

1313213132
##### Enforcement
1313313133

@@ -13139,7 +13139,7 @@ Hard.
1313913139

1314013140
Readability. Direct expression of an idea.
1314113141

13142-
##### Example
13142+
##### Example (using TS concepts)
1314313143

1314413144
To say "`T` is `Sortable`":
1314513145

@@ -13185,7 +13185,7 @@ Concepts are meant to express semantic notions, such as "a number", "a range" of
1318513185
Simple constraints, such as "has a `+` operator" and "has a `>` operator" cannot be meaningfully specified in isolation
1318613186
and should be used only as building blocks for meaningful concepts, rather than in user code.
1318713187

13188-
##### Example, bad
13188+
##### Example, bad (using TS concepts)
1318913189

1319013190
template<typename T>
1319113191
concept Addable = has_plus<T>; // bad; insufficient
@@ -13256,9 +13256,9 @@ Helps implementers and maintainers.
1325613256

1325713257
This is a specific variant of the gerenral rule that [a concept mist make semantic sense](#Rt-low).
1325813258

13259-
##### Example, bad
13259+
##### Example, bad (using TS concepts)
1326013260

13261-
template<typename T> Subtractable = requires(T a, T, b) { a-b; };
13261+
template<typename T> concept Subtractable = requires(T a, T, b) { a-b; };
1326213262

1326313263
This makes no semantic sense.
1326413264
You need at least `+` to make `-` meaningful and useful.
@@ -13342,7 +13342,7 @@ A meaningful/useful concept has a semantic meaning.
1334213342
Expressing these semantics in an informal, semi-formal, or formal way makes the concept comprehensible to readers and the effort to express it can catch conceptual errors.
1334313343
Specifying semantics is a powerful design tool.
1334413344

13345-
##### Example
13345+
##### Example (using TS concepts)
1334613346

1334713347
template<typename T>
1334813348
// The operators +, -, *, and / for a number are assumed to follow the usual mathematical rules
@@ -13371,7 +13371,7 @@ Once language support is available, the `//` in front of the axiom can be remove
1337113371

1337213372
The GSL concepts have well defined semantics; see the Palo Alto TR and the Ranges TS.
1337313373

13374-
##### Exception
13374+
##### Exception (using TS concepts)
1337513375

1337613376
Early versions of a new "concept" still under development will often just define simple sets of constraints without a well-specified semantics.
1337713377
Finding good semantics can take effort and time.
@@ -13403,7 +13403,7 @@ Each new use case may require such an incomplete concepts to be improved.
1340313403

1340413404
Otherwise they cannot be distinguished automatically by the compiler.
1340513405

13406-
##### Example
13406+
##### Example (using TS concepts)
1340713407

1340813408
template<typename I>
1340913409
concept bool Input_iter = requires (I iter) { ++iter; };
@@ -13426,7 +13426,7 @@ If two concepts have exactly the same requirements, they are logically equivalen
1342613426

1342713427
Two concepts requiring the same syntax but having different semantics leads to ambiguity unless the programmer differentiates them.
1342813428

13429-
##### Example
13429+
##### Example (using TS concepts)
1343013430

1343113431
template<typename I> // iterator providing random access
1343213432
concept bool RA_iter = ...;
@@ -13439,7 +13439,7 @@ The programmer (in a library) must define `is_contiguous` (a trait) appropriatel
1343913439

1344013440
Wrapping a tag class into a concept leads to a simpler expression of this idea:
1344113441

13442-
concept<typename I> Contiguous = is_contiguous<I>::value;
13442+
template<typename I> concept Contiguous = is_contiguous<I>::value;
1344313443

1344413444
template<typename I>
1344513445
concept bool Contiguous_iter = RA_iter<I> && Contiguous<I>;
@@ -13464,7 +13464,7 @@ Prefer the standard-library ones.
1346413464
Clarity. Maintainability.
1346513465
Functions with complementary requirements expressed using negation are brittle.
1346613466

13467-
##### Example
13467+
##### Example (using TS concepts)
1346813468

1346913469
Initially, people will try to define functions with complementary requirements:
1347013470

@@ -13506,7 +13506,7 @@ The compiler will select the overload and emit an appropriate error.
1350613506
The definition is more readable and corresponds directly to what a user has to write.
1350713507
Conversions are taken into account. You don't have to remember the names of all the type traits.
1350813508

13509-
##### Example, bad
13509+
##### Example (using TS concepts)
1351013510

1351113511
You might be tempted to define a concept `Equality` like this:
1351213512

@@ -13539,7 +13539,7 @@ However, the interface to a template is a critical concept - a contract between
1353913539
Function objects can carry more information through an interface than a "plain" pointer to function.
1354013540
In general, passing function objects gives better performance than passing pointers to functions.
1354113541

13542-
##### Example
13542+
##### Example (using TS concepts)
1354313543

1354413544
bool greater(double x, double y) { return x > y; }
1354513545
sort(v, greater); // pointer to function: potentially slow
@@ -13576,7 +13576,7 @@ The performance argument depends on compiler and optimizer technology.
1357613576

1357713577
Keep interfaces simple and stable.
1357813578

13579-
##### Example
13579+
##### Example (using TS concepts)
1358013580

1358113581
Consider, a `sort` instrumented with (oversimplified) simple debug support:
1358213582

@@ -13601,7 +13601,7 @@ Should this be rewritten to:
1360113601
After all, there is nothing in `Sortable` that requires `iostream` support.
1360213602
On the other hand, there is nothing in the fundamental idea of sorting that says anything about debugging.
1360313603

13604-
###### Note
13604+
##### Note
1360513605

1360613606
If we require every operation used to be listed among the requirements, the interface becomes unstable:
1360713607
every time we change the debug facilities, the usage data gathering, testing support, error reporting, etc.
@@ -16387,7 +16387,7 @@ It's verbose and only needed where C compatibility matters.
1638716387

1638816388
void g(); // better
1638916389

16390-
###### Note
16390+
##### Note
1639116391

1639216392
Even Dennis Ritchie deemed `void f(void)` an abomination.
1639316393
You can make an argument for that abomination in C when function prototypes were rare so that banning:

0 commit comments

Comments
 (0)