diff --git a/style-guide.md b/style-guide.md index 2a35fdc5d1..391c45b644 100644 --- a/style-guide.md +++ b/style-guide.md @@ -77,6 +77,18 @@ instead of | use See [the source](api/array_view.h) for more detailed docs. +### `absl::optional` as function argument + +`absl::optional` is generally a good choice when you want to pass a +possibly missing `T` to a function—provided of course that `T` +is a type that it makes sense to pass by value. + +However, when you want to avoid pass-by-value, generally **do not pass +`const absl::optional&`; use `const T*` instead.** `const +absl::optional&` forces the caller to store the `T` in an +`absl::optional`; `const T*`, on the other hand, makes no +assumptions about how the `T` is stored. + ### sigslot sigslot is a lightweight library that adds a signal/slot language