0

Remove Dos-And-Dont's guidance on preferring structs over pairs/tuples.

This is now effectively the guidance of the public Google C++ styleguide, and
thus unnecessary.

Bug: none
Change-Id: I5896ec95822cc586d8f30427083108c34ac1206c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1785747
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693729}
This commit is contained in:
Peter Kasting
2019-09-05 15:03:24 +00:00
committed by Commit Bot
parent 81d399b4b0
commit 99728616ce

@ -125,38 +125,6 @@ Note that it's possible to call functions or pass `this` and other expressions
in initializers, so even some complex initializations can be done in the
declaration.
## Prefer structs over pairs/tuples when used repeatedly
The Google style guide
[recommends using return values over outparams](http://google.github.io/styleguide/cppguide.html#Output_Parameters).
For functions which return multiple values, a convenient way to do this is to
return a pair or tuple:
```cpp
std::pair<int, int> GetPaddingValues() {
...
return {1, 2}; // Shorter and more readable than std::make_pair(), works with tuples also.
}
```
However, this return type can be cumbersome, opaque, and error-prone. An
alternative is to define a struct with named fields:
```cpp
struct PaddingValues {
int header;
int footer;
};
PaddingValues GetPaddingValues() {
...
return {1, 2}; // This abbreviated syntax still works!
}
```
A good rule of thumb for when to prefer a struct is whenever you'd find
declaring a type alias for the pair or tuple beneficial, which is usually
whenever it's used more than just as a local one-off.
## Use `std::make_unique` and `base::MakeRefCounted` instead of bare `new`
When possible, avoid bare `new` by using