blob: d09ff1dc4286e8d5b4e79ddb8353f74823852cab [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`
15* `absl::make_unique` and `absl::WrapUnique`
16* `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
25 `absl/algorithm/container.h`
Danil Chapovalov47cf5ea2019-02-19 19:20:1626* The macros in `absl/base/attributes.h` and `absl/base/config.h`
Karl Wibergc3af97d2018-08-27 02:26:1827
28## **Disallowed**
29
30### `absl::Mutex`
31
32*Use `rtc::CriticalSection` instead.*
33
34Chromium has a ban on new static initializers, and `absl::Mutex` uses
35one. To make `absl::Mutex` available, we would need to nicely ask the
36Abseil team to remove that initializer (like they already did for a
37spinlock initializer). Additionally, `absl::Mutex` handles time in a
38way that may not be compaible with the rest of WebRTC.
39
40### `absl::Span`
41
42*Use `rtc::ArrayView` instead.*
43
44`absl::Span` differs from `rtc::ArrayView` on several points, and both
45of them differ from the `std::span` that was voted into
46C++20—and `std::span` is likely to undergo further changes
47before C++20 is finalized. We should just keep using `rtc::ArrayView`
48and avoid `absl::Span` until C++20 is finalized and the Abseil team
49has decided if they will change `absl::Span` to match.
50[Bug](https://bugs.webrtc.org/9214).
51
Karl Wibergbd0deca2019-02-26 00:42:2652### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit`
Karl Wibergc3af97d2018-08-27 02:26:1853
Karl Wibergbd0deca2019-02-26 00:42:2654*Use `rtc::SimpleStringBuilder` to build strings.*
Karl Wibergc3af97d2018-08-27 02:26:1855
56These are optimized for speed, not binary size. Even `StrCat` calls
57with a modest number of arguments can easily add several hundred bytes
58to the binary.