mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 20:54:41 +03:00
Fix whitespace around operator
This commit is contained in:
@@ -2239,8 +2239,13 @@ Passing a shared smart pointer (e.g., `std::shared_ptr`) implies a run-time cost
|
|||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
void f(int*); // accepts any int*
|
// accepts any int*
|
||||||
|
void f(int*);
|
||||||
|
|
||||||
|
// can only accept ints for which you want to transfer ownership
|
||||||
void g(unique_ptr<int>); // accepts ints to transfer ownership
|
void g(unique_ptr<int>); // accepts ints to transfer ownership
|
||||||
|
|
||||||
|
// can only accept ints for which you are willing to share ownership
|
||||||
void g(shared_ptr<int>); // accepts ints to share ownership
|
void g(shared_ptr<int>); // accepts ints to share ownership
|
||||||
|
|
||||||
// doesn’t change ownership, but requires a particular ownership of the caller
|
// doesn’t change ownership, but requires a particular ownership of the caller
|
||||||
@@ -2683,10 +2688,13 @@ A `span` represents a range of elements, but how do we manipulate elements of th
|
|||||||
{
|
{
|
||||||
// range traversal (guaranteed correct)
|
// range traversal (guaranteed correct)
|
||||||
for (int x : s) cout << x << '\n';
|
for (int x : s) cout << x << '\n';
|
||||||
|
|
||||||
// C-style traversal (potentially checked)
|
// C-style traversal (potentially checked)
|
||||||
for (int i = 0; i < s.size(); ++i) cout << x << '\n';
|
for (int i = 0; i < s.size(); ++i) cout << x << '\n';
|
||||||
|
|
||||||
// random access (potentially checked)
|
// random access (potentially checked)
|
||||||
s[7] = 9;
|
s[7] = 9;
|
||||||
|
|
||||||
// extract pointers (potentially checked)
|
// extract pointers (potentially checked)
|
||||||
std::sort(&s[0], &s[s.size() / 2]);
|
std::sort(&s[0], &s[s.size() / 2]);
|
||||||
}
|
}
|
||||||
@@ -4064,7 +4072,9 @@ If the `Handle` owns the object referred to by `s` it must have a destructor.
|
|||||||
|
|
||||||
Independently of whether `Handle` owns its `Shape`, we must consider the default copy operations suspect:
|
Independently of whether `Handle` owns its `Shape`, we must consider the default copy operations suspect:
|
||||||
|
|
||||||
Handle x {*new Circle{p1, 17}}; // causes a leak if the Handle is not a Circle
|
// the Handle had better own the Circle or we have a leak
|
||||||
|
Handle x {*new Circle{p1, 17}};
|
||||||
|
|
||||||
Handle y {*new Triangle{p1, p2, p3}};
|
Handle y {*new Triangle{p1, p2, p3}};
|
||||||
x = y; // the default assignment will try *x.s = *y.s
|
x = y; // the default assignment will try *x.s = *y.s
|
||||||
|
|
||||||
@@ -12113,8 +12123,8 @@ In general, passing function objects gives better performance than passing point
|
|||||||
|
|
||||||
You can, of course, generalize those functions using `auto` or (when and where available) concepts. For example:
|
You can, of course, generalize those functions using `auto` or (when and where available) concepts. For example:
|
||||||
|
|
||||||
auto y1 = find_if(v, [](Ordered x) { return x>7; }); // require an ordered type
|
auto y1 = find_if(v, [](Ordered x) { return x > 7; }); // require an ordered type
|
||||||
auto z1 = find_if(v, [](auto x) { return x>7; }); // hope that the type has a >
|
auto z1 = find_if(v, [](auto x) { return x > 7; }); // hope that the type has a >
|
||||||
|
|
||||||
##### Note
|
##### Note
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user