blob: 0541d3c7a5aa73f305afe106a9d2174250fc814b [file] [log] [blame] [view]
Karl Wibergc3af97d2018-08-27 02:26:181# Using Abseil in WebRTC
2
3You may use a subset of the utilities provided by the [Abseil][abseil]
4library when writing WebRTC C++ code. Below, we list the explicitly
5*allowed* and the explicitly *disallowed* subsets of Abseil; if you
6find yourself in need of something that isn’t in either subset,
7please add it to the *allowed* subset in this doc in the same CL that
8adds the first use.
9
10[abseil]: https://abseil.io/about/
11
12## **Allowed**
13
14* `absl::InlinedVector`
Mirko Bonadeic128df12019-09-18 05:59:0715* `absl::WrapUnique`
Karl Wibergc3af97d2018-08-27 02:26:1816* `absl::optional` and related stuff from `absl/types/optional.h`.
17* `absl::string_view`
Steve Anton1c9c9fc2019-02-14 23:13:0918* The functions in `absl/strings/ascii.h`, `absl/strings/match.h`,
19 and `absl/strings/str_replace.h`.
Jiawei Oua6e034a2018-11-25 04:59:4120* `absl::is_trivially_copy_constructible`,
21 `absl::is_trivially_copy_assignable`, and
22 `absl::is_trivially_destructible` from `absl/meta/type_traits.h`.
Karl Wibergc3af97d2018-08-27 02:26:1823* `absl::variant` and related stuff from `absl/types/variant.h`.
Steve Antone76ca612019-01-25 20:49:1424* The functions in `absl/algorithm/algorithm.h` and
Elad Alone86af2c2019-06-03 12:37:5025 `absl/algorithm/container.h`.
26* The macros in `absl/base/attributes.h`, `absl/base/config.h` and
27 `absl/base/macros.h`.
Karl Wibergc3af97d2018-08-27 02:26:1828
29## **Disallowed**
30
Mirko Bonadeic128df12019-09-18 05:59:0731### `absl::make_unique`
32
33*Use `std::make_unique` instead.*
34
Karl Wibergc3af97d2018-08-27 02:26:1835### `absl::Mutex`
36
37*Use `rtc::CriticalSection` instead.*
38
39Chromium has a ban on new static initializers, and `absl::Mutex` uses
40one. To make `absl::Mutex` available, we would need to nicely ask the
41Abseil team to remove that initializer (like they already did for a
42spinlock initializer). Additionally, `absl::Mutex` handles time in a
Rasmus Brandt7ab41e52019-12-18 09:01:5443way that may not be compatible with the rest of WebRTC.
Karl Wibergc3af97d2018-08-27 02:26:1844
45### `absl::Span`
46
47*Use `rtc::ArrayView` instead.*
48
49`absl::Span` differs from `rtc::ArrayView` on several points, and both
50of them differ from the `std::span` that was voted into
51C++20—and `std::span` is likely to undergo further changes
52before C++20 is finalized. We should just keep using `rtc::ArrayView`
53and avoid `absl::Span` until C++20 is finalized and the Abseil team
54has decided if they will change `absl::Span` to match.
55[Bug](https://bugs.webrtc.org/9214).
56
Karl Wibergbd0deca2019-02-26 00:42:2657### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit`
Karl Wibergc3af97d2018-08-27 02:26:1858
Karl Wibergbd0deca2019-02-26 00:42:2659*Use `rtc::SimpleStringBuilder` to build strings.*
Karl Wibergc3af97d2018-08-27 02:26:1860
61These are optimized for speed, not binary size. Even `StrCat` calls
62with a modest number of arguments can easily add several hundred bytes
63to the binary.