mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-18 21:24:41 +03:00
testing backticks-cpp
This commit is contained in:
@@ -484,12 +484,14 @@ What is expressed in code has defined semantics and can (in principle) be checke
|
|||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
class Date {
|
```cpp
|
||||||
public:
|
class Date {
|
||||||
Month month() const; // do
|
public:
|
||||||
int month(); // don't
|
Month month() const; // do
|
||||||
// ...
|
int month(); // don't
|
||||||
};
|
// ...
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
The first declaration of `month` is explicit about returning a `Month` and about not modifying the state of the `Date` object.
|
The first declaration of `month` is explicit about returning a `Month` and about not modifying the state of the `Date` object.
|
||||||
The second version leaves the reader guessing and opens more possibilities for uncaught bugs.
|
The second version leaves the reader guessing and opens more possibilities for uncaught bugs.
|
||||||
@@ -498,20 +500,22 @@ The second version leaves the reader guessing and opens more possibilities for u
|
|||||||
|
|
||||||
This loop is a restricted form of `std::find`:
|
This loop is a restricted form of `std::find`:
|
||||||
|
|
||||||
void f(vector<string>& v)
|
```cpp
|
||||||
{
|
void f(vector<string>& v)
|
||||||
string val;
|
{
|
||||||
cin >> val;
|
string val;
|
||||||
// ...
|
cin >> val;
|
||||||
int index = -1; // bad, plus should use gsl::index
|
// ...
|
||||||
for (int i = 0; i < v.size(); ++i) {
|
int index = -1; // bad, plus should use gsl::index
|
||||||
if (v[i] == val) {
|
for (int i = 0; i < v.size(); ++i) {
|
||||||
index = i;
|
if (v[i] == val) {
|
||||||
break;
|
index = i;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
// ...
|
|
||||||
}
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
##### Example, good
|
##### Example, good
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user