Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame^] | 1 | # Modern C++ use in Chromium |
| 2 | |
| 3 | _This document is part of the more general |
| 4 | [Chromium C++ style guide](https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++.md). |
| 5 | It summarizes the supported state of new and updated language and library |
| 6 | features in recent C++ standards and the [Abseil](https://abseil.io/about/) |
| 7 | library. This guide applies to both Chromium and its subprojects, though |
| 8 | subprojects can choose to be more restrictive if necessary for toolchain |
| 9 | support._ |
| 10 | |
| 11 | The C++ language has in recent years received an updated standard every three |
| 12 | years (C++11, C++14, C++17). For various reasons, Chromium does not immediately |
| 13 | allow new features on the publication of such a standard. Instead, once |
| 14 | toolchain support is sufficient, a standard is declared "initially supported", |
| 15 | with new language/library features banned pending discussion. |
| 16 | |
| 17 | You can propose changing the status of a feature by sending an email to |
| 18 | [[email protected]](https://groups.google.com/a/chromium.org/forum/#!forum/cxx). |
| 19 | Include a short blurb on what the feature is and why you think it should or |
| 20 | should not be allowed, along with links to any relevant previous discussion. If |
| 21 | the list arrives at some consensus, send a codereview to change this file |
| 22 | accordingly, linking to your discussion thread. |
| 23 | |
| 24 | If an item remains on the TBD list two years after initial support is added, |
| 25 | style arbiters should explicitly move it to an appropriate allowlist or |
| 26 | blocklist, allowing it if there are no obvious reasons to ban. |
| 27 | |
| 28 | The current status of existing standards and Abseil features is: |
| 29 | |
| 30 | * **C++11:** _Default allowed; see banned features below_ |
| 31 | * **C++14:** _Default allowed; see banned features below_ |
| 32 | * **C++17:** _Not yet supported in Chromium, unlikely before mid-2021; |
| 33 | [tracking bug](https://crbug.com/752720)_ |
| 34 | * **C++20:** _Not yet standardized_ |
| 35 | * **Abseil:** Initially supported July 31, 2020; see allowed/banned/TBD |
| 36 | features below |
| 37 | * absl::StatusOr: Initially supported September 3, 2020 |
| 38 | * absl::Cleanup: Initially supported February 4, 2021 |
| 39 | |
| 40 | [TOC] |
| 41 | |
| 42 | ## C++11 Banned Language Features {#core-blocklist} |
| 43 | |
| 44 | The following C++11 language features are not allowed in the Chromium codebase. |
| 45 | |
| 46 | ### Inline Namespaces |
| 47 | |
| 48 | ```c++ |
| 49 | inline namespace foo { ... } |
| 50 | ``` |
| 51 | |
| 52 | **Description:** Allows better versioning of namespaces. |
| 53 | |
| 54 | **Documentation:** |
| 55 | [Inline namespaces](https://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces) |
| 56 | |
| 57 | **Notes:** |
| 58 | *** promo |
| 59 | Banned in the |
| 60 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Namespaces). |
| 61 | Unclear how it will work with components. |
| 62 | *** |
| 63 | |
| 64 | ### long long Type |
| 65 | |
| 66 | ```c++ |
| 67 | long long var = value; |
| 68 | ``` |
| 69 | |
| 70 | **Description:** An integer of at least 64 bits. |
| 71 | |
| 72 | **Documentation:** |
| 73 | [Fundamental types](https://en.cppreference.com/w/cpp/language/types) |
| 74 | |
| 75 | **Notes:** |
| 76 | *** promo |
| 77 | Use a stdint.h type if you need a 64-bit number. |
| 78 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk) |
| 79 | *** |
| 80 | |
| 81 | ### User-Defined Literals |
| 82 | |
| 83 | ```c++ |
| 84 | type var = literal_value_type; |
| 85 | ``` |
| 86 | |
| 87 | **Description:** Allows user-defined literal expressions. |
| 88 | |
| 89 | **Documentation:** |
| 90 | [User-defined literals](https://en.cppreference.com/w/cpp/language/user_literal) |
| 91 | |
| 92 | **Notes:** |
| 93 | *** promo |
| 94 | Banned in the |
| 95 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Operator_Overloading). |
| 96 | *** |
| 97 | |
| 98 | ### thread_local Storage Class |
| 99 | |
| 100 | ```c++ |
| 101 | thread_local int foo = 1; |
| 102 | ``` |
| 103 | |
| 104 | **Description:** Puts variables into thread local storage. |
| 105 | |
| 106 | **Documentation:** |
| 107 | [Storage duration](https://en.cppreference.com/w/cpp/language/storage_duration) |
| 108 | |
| 109 | **Notes:** |
| 110 | *** promo |
| 111 | Some surprising effects on Mac |
| 112 | ([discussion](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2msN8k3Xzgs), |
| 113 | [fork](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/h7O5BdtWCZw)). |
| 114 | Use `base::SequenceLocalStorageSlot` for sequence support, and |
| 115 | `base::ThreadLocal`/`base::ThreadLocalStorage` otherwise. |
| 116 | *** |
| 117 | |
| 118 | ## C++11 Banned Library Features {#library-blocklist} |
| 119 | |
| 120 | The following C++11 library features are not allowed in the Chromium codebase. |
| 121 | |
| 122 | ### Bind Operations |
| 123 | |
| 124 | ```c++ |
| 125 | std::bind(function, args, ...) |
| 126 | ``` |
| 127 | |
| 128 | **Description:** Declares a function object bound to certain arguments |
| 129 | |
| 130 | **Documentation:** |
| 131 | [std::bind](https://en.cppreference.com/w/cpp/utility/functional/bind) |
| 132 | |
| 133 | **Notes:** |
| 134 | *** promo |
| 135 | Use `base::Bind` instead. Compared to `std::bind`, `base::Bind` helps prevent |
| 136 | lifetime issues by preventing binding of capturing lambdas and by forcing |
| 137 | callers to declare raw pointers as `Unretained`. |
| 138 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
| 139 | *** |
| 140 | |
| 141 | ### C Floating-Point Environment |
| 142 | |
| 143 | ```c++ |
| 144 | #include <cfenv> |
| 145 | #include <fenv.h> |
| 146 | ``` |
| 147 | |
| 148 | **Description:** Provides floating point status flags and control modes for |
| 149 | C-compatible code |
| 150 | |
| 151 | **Documentation:** |
| 152 | [Standard library header "cfenv"](https://en.cppreference.com/w/cpp/header/cfenv) |
| 153 | |
| 154 | **Notes:** |
| 155 | *** promo |
| 156 | Banned by the |
| 157 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 158 | due to concerns about compiler support. |
| 159 | *** |
| 160 | |
| 161 | ### Date and time utilities |
| 162 | |
| 163 | ```c++ |
| 164 | #include <chrono> |
| 165 | ``` |
| 166 | |
| 167 | **Description:** A standard date and time library |
| 168 | |
| 169 | **Documentation:** |
| 170 | [Date and time utilities](https://en.cppreference.com/w/cpp/chrono) |
| 171 | |
| 172 | **Notes:** |
| 173 | *** promo |
| 174 | Overlaps with `Time` APIs in `base/`. Keep using the `base/` classes. |
| 175 | *** |
| 176 | |
| 177 | ### Exceptions |
| 178 | |
| 179 | ```c++ |
| 180 | #include <exception> |
| 181 | ``` |
| 182 | |
| 183 | **Description:** Enhancements to exception throwing and handling |
| 184 | |
| 185 | **Documentation:** |
| 186 | [Standard library header "exception"](https://en.cppreference.com/w/cpp/header/exception) |
| 187 | |
| 188 | **Notes:** |
| 189 | *** promo |
| 190 | Exceptions are banned by the |
| 191 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Exceptions) |
| 192 | and disabled in Chromium compiles. However, the `noexcept` specifier is |
| 193 | explicitly allowed. |
| 194 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg) |
| 195 | *** |
| 196 | |
| 197 | ### Function Objects |
| 198 | |
| 199 | ```c++ |
| 200 | std::function |
| 201 | ``` |
| 202 | |
| 203 | **Description:** Wraps a standard polymorphic function |
| 204 | |
| 205 | **Documentation:** |
| 206 | [std::function](https://en.cppreference.com/w/cpp/utility/functional/function) |
| 207 | |
| 208 | **Notes:** |
| 209 | *** promo |
| 210 | Use `base::{Once,Repeating}Callback` instead. Compared to `std::function`, |
| 211 | `base::{Once,Repeating}Callback` directly supports Chromium's refcounting |
| 212 | classes and weak pointers and deals with additional thread safety concerns. |
| 213 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
| 214 | *** |
| 215 | |
| 216 | ### Random Number Engines |
| 217 | |
| 218 | *** aside |
| 219 | The random number engines defined in `<random>` (see separate item for random |
| 220 | number distributions), e.g.: `linear_congruential_engine`, |
| 221 | `mersenne_twister_engine`, `minstd_rand0`, `mt19937`, `ranlinux48`, |
| 222 | `random_device` |
| 223 | *** |
| 224 | |
| 225 | **Description:** Random number generation algorithms and utilities. |
| 226 | |
| 227 | **Documentation:** |
| 228 | [Pseudo-random number generation](https://en.cppreference.com/w/cpp/numeric/random) |
| 229 | |
| 230 | **Notes:** |
| 231 | *** promo |
| 232 | Do not use any random number engines from `<random>`. Instead, use |
| 233 | `base::RandomBitGenerator`. |
| 234 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16Xmw05C-Y0) |
| 235 | *** |
| 236 | |
| 237 | ### Ratio Template Class |
| 238 | |
| 239 | ```c++ |
| 240 | std::ratio<numerator, denominator> |
| 241 | ``` |
| 242 | |
| 243 | **Description:** Provides compile-time rational numbers |
| 244 | |
| 245 | **Documentation:** |
| 246 | [std::ratio](https://en.cppreference.com/w/cpp/numeric/ratio/ratio) |
| 247 | |
| 248 | **Notes:** |
| 249 | *** promo |
| 250 | Banned by the |
| 251 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 252 | due to concerns that this is tied to a more template-heavy interface style. |
| 253 | *** |
| 254 | |
| 255 | ### Regular Expressions |
| 256 | |
| 257 | ```c++ |
| 258 | #include <regex> |
| 259 | ``` |
| 260 | |
| 261 | **Description:** A standard regular expressions library |
| 262 | |
| 263 | **Documentation:** |
| 264 | [Regular expressions library](https://en.cppreference.com/w/cpp/regex) |
| 265 | |
| 266 | **Notes:** |
| 267 | *** promo |
| 268 | Overlaps with many regular expression libraries in Chromium. When in doubt, use |
| 269 | `re2`. |
| 270 | *** |
| 271 | |
| 272 | ### Shared Pointers |
| 273 | |
| 274 | ```c++ |
| 275 | std::shared_ptr |
| 276 | ``` |
| 277 | |
| 278 | **Description:** Allows shared ownership of a pointer through reference counts |
| 279 | |
| 280 | **Documentation:** |
| 281 | [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr) |
| 282 | |
| 283 | **Notes:** |
| 284 | *** promo |
| 285 | Needs a lot more evaluation for Chromium, and there isn't enough of a push for |
| 286 | this feature. |
| 287 | |
| 288 | * [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers). |
| 289 | * [Discussion Thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/aT2wsBLKvzI) |
| 290 | *** |
| 291 | |
| 292 | ### String-Number Conversion Functions |
| 293 | |
| 294 | ```c++ |
| 295 | std::stoi() |
| 296 | std::stol() |
| 297 | std::stoul() |
| 298 | std::stoll |
| 299 | std::stoull() |
| 300 | std::stof() |
| 301 | std::stod() |
| 302 | std::stold() |
| 303 | std::to_string() |
| 304 | ``` |
| 305 | |
| 306 | **Description:** Converts strings to/from numbers |
| 307 | |
| 308 | **Documentation:** |
| 309 | * [std::stoi, std::stol, std::stoll](https://en.cppreference.com/w/cpp/string/basic_string/stol), |
| 310 | * [std::stoul, std::stoull](https://en.cppreference.com/w/cpp/string/basic_string/stoul), |
| 311 | * [std::stof, std::stod, std::stold](https://en.cppreference.com/w/cpp/string/basic_string/stof), |
| 312 | * [std::to_string](https://en.cppreference.com/w/cpp/string/basic_string/to_string) |
| 313 | |
| 314 | **Notes:** |
| 315 | *** promo |
| 316 | The string-to-number conversions rely on exceptions to communicate failure, |
| 317 | while the number-to-string conversions have performance concerns and depend on |
| 318 | the locale. Use the routines in `base/strings/string_number_conversions.h` |
| 319 | instead. |
| 320 | *** |
| 321 | |
| 322 | ### Thread Library |
| 323 | |
| 324 | *** aside |
| 325 | `<thread>` and related headers, including `<future>`, `<mutex>`, |
| 326 | `<condition_variable>` |
| 327 | *** |
| 328 | |
| 329 | **Description:** Provides a standard multithreading library using `std::thread` |
| 330 | and associates |
| 331 | |
| 332 | **Documentation:** |
| 333 | [Thread support library](https://en.cppreference.com/w/cpp/thread) |
| 334 | |
| 335 | **Notes:** |
| 336 | *** promo |
| 337 | Overlaps with many classes in `base/`. Keep using the `base/` classes for now. |
| 338 | `base::Thread` is tightly coupled to `MessageLoop` which would make it hard to |
| 339 | replace. We should investigate using standard mutexes, or unique_lock, etc. to |
| 340 | replace our locking/synchronization classes. |
| 341 | *** |
| 342 | |
| 343 | ### Weak Pointers |
| 344 | |
| 345 | ```c++ |
| 346 | std::weak_ptr |
| 347 | ``` |
| 348 | |
| 349 | **Description:** Allows a weak reference to a `std::shared_ptr` |
| 350 | |
| 351 | **Documentation:** |
| 352 | [std::weak_ptr](https://en.cppreference.com/w/cpp/memory/weak_ptr) |
| 353 | |
| 354 | **Notes:** |
| 355 | *** promo |
| 356 | Banned because `std::shared_ptr` is banned. Use `base::WeakPtr` instead. |
| 357 | *** |
| 358 | |
| 359 | ## C++14 Banned Library Features {#library-blocklist-14} |
| 360 | |
| 361 | The following C++14 library features are not allowed in the Chromium codebase. |
| 362 | |
| 363 | ### std::chrono literals |
| 364 | |
| 365 | ```c++ |
| 366 | using namespace std::chrono_literals; |
| 367 | auto timeout = 30s; |
| 368 | ``` |
| 369 | |
| 370 | **Description:** Allows `std::chrono` types to be more easily constructed. |
| 371 | |
| 372 | **Documentation:** |
| 373 | [std::literals::chrono_literals::operator""s](https://en.cppreference.com/w/cpp/chrono/operator%22%22s) |
| 374 | |
| 375 | **Notes:** |
| 376 | *** promo |
| 377 | Banned because `<chrono>` is banned. |
| 378 | *** |
| 379 | |
| 380 | ## Abseil Allowed Library Features {#absl-allowlist} |
| 381 | |
| 382 | The following Abseil library features are allowed in the Chromium codebase. |
| 383 | |
| 384 | ### Optional |
| 385 | |
| 386 | ```c++ |
| 387 | absl::optional |
| 388 | ``` |
| 389 | |
| 390 | **Description:** Early adaptation of C++17 `std::optional`. |
| 391 | |
| 392 | **Documentation:** |
| 393 | [std::optional](https://en.cppreference.com/w/cpp/utility/optional) |
| 394 | |
| 395 | **Notes:** |
| 396 | *** promo |
| 397 | Replaces `base::Optional`. |
| 398 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/zUGqagX1NFU) |
| 399 | *** |
| 400 | |
| 401 | ### Status |
| 402 | |
| 403 | ```c++ |
| 404 | absl::Status |
| 405 | ``` |
| 406 | |
| 407 | **Description:** Type for returning detailed errors. |
| 408 | |
| 409 | **Documentation:** |
| 410 | [status.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/status.h) |
| 411 | |
| 412 | **Notes:** |
| 413 | *** promo |
| 414 | Approved for use inside a wrapper type. Use |
| 415 | [abseil_string_conversions.h](https://source.chromium.org/chromium/chromium/src/+/main:base/strings/abseil_string_conversions.h) |
| 416 | to convert to and from |
| 417 | [absl::string_view](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/strings/string_view.h) |
| 418 | so the wrapper can expose |
| 419 | [base::StringPiece](https://source.chromium.org/chromium/chromium/src/+/main:base/strings/string_piece.h). |
| 420 | Use |
| 421 | [absl::Cord](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/strings/cord.h) |
| 422 | directly as minimally necessary to interface; do not expose in the wrapper type |
| 423 | API. |
| 424 | |
| 425 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ImdFCSZ-NMA) |
| 426 | *** |
| 427 | |
| 428 | ### Variant |
| 429 | |
| 430 | ```c++ |
| 431 | absl::variant |
| 432 | ``` |
| 433 | |
| 434 | **Description:** Early adaptation of C++17 `std::variant`. |
| 435 | |
| 436 | **Documentation:** |
| 437 | [std::variant](https://en.cppreference.com/w/cpp/utility/variant) |
| 438 | |
| 439 | **Notes:** |
| 440 | *** promo |
| 441 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/DqvG-TpvMyU) |
| 442 | *** |
| 443 | |
| 444 | ## Abseil Banned Library Features {#absl-blocklist} |
| 445 | |
| 446 | The following Abseil library features are not allowed in the Chromium codebase. |
| 447 | |
| 448 | ### Any |
| 449 | |
| 450 | ```c++ |
| 451 | absl::any a = int{5}; |
| 452 | EXPECT_THAT(absl::any_cast<int>(&a), Pointee(5)); |
| 453 | EXPECT_EQ(absl::any_cast<size_t>(&a), nullptr); |
| 454 | ``` |
| 455 | |
| 456 | **Description:** Early adaptation of C++17 `std::any`. |
| 457 | |
| 458 | **Documentation:** [std::any](https://en.cppreference.com/w/cpp/utility/any) |
| 459 | |
| 460 | **Notes:** |
| 461 | *** promo |
| 462 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 463 | build. ([Bug](https://crbug.com/1096380)) |
| 464 | *** |
| 465 | |
| 466 | ### Command line flags |
| 467 | |
| 468 | ```c++ |
| 469 | ABSL_FLAG(bool, logs, false, "print logs to stderr"); |
| 470 | app --logs=true; |
| 471 | ``` |
| 472 | |
| 473 | **Description:** Allows programmatic access to flag values passed on the |
| 474 | command-line to binaries. |
| 475 | |
| 476 | **Documentation:** [Flags Library](https://abseil.io/docs/cpp/guides/flags) |
| 477 | |
| 478 | **Notes:** |
| 479 | *** promo |
| 480 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 481 | build. ([Bug](https://crbug.com/1096380)) Use `base::CommandLine` instead. |
| 482 | *** |
| 483 | |
| 484 | ### Span |
| 485 | |
| 486 | ```c++ |
| 487 | absl::Span |
| 488 | ``` |
| 489 | |
| 490 | **Description:** Early adaptation of C++20 `std::span`. |
| 491 | |
| 492 | **Documentation:** [Using absl::Span](https://abseil.io/tips/93) |
| 493 | |
| 494 | **Notes:** |
| 495 | *** promo |
| 496 | Banned due to being less std::-compliant than `base::span`. Keep using |
| 497 | `base::span`. |
| 498 | *** |
| 499 | |
| 500 | ### string_view |
| 501 | |
| 502 | ```c++ |
| 503 | absl::string_view |
| 504 | ``` |
| 505 | |
| 506 | **Description:** Early adaptation of C++17 `std::string_view`. |
| 507 | |
| 508 | **Documentation:** [absl::string_view](https://abseil.io/tips/1) |
| 509 | |
| 510 | **Notes:** |
| 511 | *** promo |
| 512 | Banned due to only working with 8-bit characters. Keep using |
| 513 | `base::StringPiece` from `base/strings/`. |
| 514 | *** |
| 515 | |
| 516 | ## Abseil TBD Features {#absl-review} |
| 517 | |
| 518 | The following Abseil library features are not allowed in the Chromium codebase. |
| 519 | See the top of this page on how to propose moving a feature from this list into |
| 520 | the allowed or banned sections. |
| 521 | |
| 522 | ### 128bit integer |
| 523 | |
| 524 | ```c++ |
| 525 | uint64_t a; |
| 526 | absl::uint128 v = a; |
| 527 | ``` |
| 528 | |
| 529 | **Description:** Signed and unsigned 128-bit integer types meant to mimic |
| 530 | intrinsic types as closely as possible. |
| 531 | |
| 532 | **Documentation:** |
| 533 | [Numerics](https://abseil.io/docs/cpp/guides/numeric) |
| 534 | |
| 535 | **Notes:** |
| 536 | *** promo |
| 537 | None |
| 538 | *** |
| 539 | |
| 540 | ### bind_front |
| 541 | |
| 542 | ```c++ |
| 543 | absl::bind_front |
| 544 | ``` |
| 545 | |
| 546 | **Description:** Binds the first N arguments of an invocable object and stores them by value. |
| 547 | |
| 548 | **Documentation:** |
| 549 | * [bind_front.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/bind_front.h) |
| 550 | * [Avoid std::bind](https://abseil.io/tips/108) |
| 551 | |
| 552 | **Notes:** |
| 553 | *** promo |
| 554 | Overlaps with `base::Bind`. |
| 555 | *** |
| 556 | |
| 557 | ### Cleanup |
| 558 | |
| 559 | ```c++ |
| 560 | FILE* sink_file = fopen(sink_path, "w"); |
| 561 | auto sink_closer = absl::MakeCleanup([sink_file] { fclose(sink_file); }); |
| 562 | ``` |
| 563 | |
| 564 | **Description:** Implements the scope guard idiom, invoking the contained |
| 565 | callback's `operator()() &&` on scope exit. |
| 566 | |
| 567 | **Documentation:** |
| 568 | [cleanup.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/cleanup/cleanup.h) |
| 569 | |
| 570 | **Notes:** |
| 571 | *** promo |
| 572 | Similar to `defer` in Golang. |
| 573 | *** |
| 574 | |
| 575 | ### Containers |
| 576 | |
| 577 | ```c++ |
| 578 | absl::flat_hash_map |
| 579 | absl::flat_hash_set |
| 580 | absl::node_hash_map |
| 581 | absl::node_hash_set |
| 582 | absl::btree_map |
| 583 | absl::btree_set |
| 584 | absl::btree_multimap |
| 585 | absl::btree_multiset |
| 586 | absl::InlinedVector |
| 587 | absl::FixedArray |
| 588 | ``` |
| 589 | |
| 590 | **Description:** Alternatives to STL containers designed to be more efficient |
| 591 | in the general case. |
| 592 | |
| 593 | **Documentation:** |
| 594 | * [Containers](https://abseil.io/docs/cpp/guides/container) |
| 595 | * [Hash](https://abseil.io/docs/cpp/guides/hash) |
| 596 | |
| 597 | **Notes:** |
| 598 | *** promo |
| 599 | Supplements `base/containers/`. |
| 600 | *** |
| 601 | |
| 602 | ### Container utilities |
| 603 | |
| 604 | ```c++ |
| 605 | auto it = absl::c_find(container, value); |
| 606 | ``` |
| 607 | |
| 608 | **Description:** Container-based versions of algorithmic functions within C++ |
| 609 | standard library. |
| 610 | |
| 611 | **Documentation:** |
| 612 | [container.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/algorithm/container.h) |
| 613 | |
| 614 | **Notes:** |
| 615 | *** promo |
| 616 | Overlaps with `base/ranges/algorithm.h`. |
| 617 | *** |
| 618 | |
| 619 | ### FunctionRef |
| 620 | |
| 621 | ```c++ |
| 622 | absl::FunctionRef |
| 623 | ``` |
| 624 | |
| 625 | **Description:** Type for holding a non-owning reference to an object of any |
| 626 | invocable type. |
| 627 | |
| 628 | **Documentation:** |
| 629 | [function_ref.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/function_ref.h) |
| 630 | |
| 631 | **Notes:** |
| 632 | *** promo |
| 633 | None |
| 634 | *** |
| 635 | |
| 636 | ### Random |
| 637 | |
| 638 | ```c++ |
| 639 | absl::BitGen bitgen; |
| 640 | size_t index = absl::Uniform(bitgen, 0u, elems.size()); |
| 641 | ``` |
| 642 | |
| 643 | **Description:** Functions and utilities for generating pseudorandom data. |
| 644 | |
| 645 | **Documentation:** [Random library](https://abseil.io/docs/cpp/guides/random) |
| 646 | |
| 647 | **Notes:** |
| 648 | *** promo |
| 649 | Overlaps with `base/rand_util.h`. |
| 650 | *** |
| 651 | |
| 652 | ### StatusOr |
| 653 | |
| 654 | ```c++ |
| 655 | absl::StatusOr<T> |
| 656 | ``` |
| 657 | |
| 658 | **Description:** An object that is either a usable value, or an error Status |
| 659 | explaining why such a value is not present. |
| 660 | |
| 661 | **Documentation:** |
| 662 | [statusor.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/statusor.h) |
| 663 | |
| 664 | **Notes:** |
| 665 | *** promo |
| 666 | None |
| 667 | *** |
| 668 | |
| 669 | ### String Formatting |
| 670 | |
| 671 | ```c++ |
| 672 | absl::StrFormat |
| 673 | ``` |
| 674 | |
| 675 | **Description:** A typesafe replacement for the family of printf() string |
| 676 | formatting routines. |
| 677 | |
| 678 | **Documentation:** |
| 679 | [String Formatting](https://abseil.io/docs/cpp/guides/format) |
| 680 | |
| 681 | **Notes:** |
| 682 | *** promo |
| 683 | None |
| 684 | *** |
| 685 | |
| 686 | ### Strings Library |
| 687 | |
| 688 | ```c++ |
| 689 | absl::StrSplit |
| 690 | absl::StrJoin |
| 691 | absl::StrCat |
| 692 | absl::StrAppend |
| 693 | absl::Substitute |
| 694 | absl::StrContains |
| 695 | ``` |
| 696 | |
| 697 | **Description:** Classes and utility functions for manipulating and comparing |
| 698 | strings. |
| 699 | |
| 700 | **Documentation:** |
| 701 | [String Utilities](https://abseil.io/docs/cpp/guides/strings) |
| 702 | |
| 703 | **Notes:** |
| 704 | *** promo |
| 705 | Overlaps with `base/strings`. |
| 706 | *** |
| 707 | |
| 708 | ### Synchronization |
| 709 | |
| 710 | ```c++ |
| 711 | absl::Mutex |
| 712 | ``` |
| 713 | |
| 714 | **Description:** Primitives for managing tasks across different threads. |
| 715 | |
| 716 | **Documentation:** |
| 717 | [Synchronization](https://abseil.io/docs/cpp/guides/synchronization) |
| 718 | |
| 719 | **Notes:** |
| 720 | *** promo |
| 721 | Overlaps with `Lock` in `base/synchronization/`. |
| 722 | *** |
| 723 | |
| 724 | ### Time library |
| 725 | |
| 726 | ```c++ |
| 727 | absl::Duration |
| 728 | absl::Time |
| 729 | absl::TimeZone |
| 730 | absl::CivilDay |
| 731 | ``` |
| 732 | |
| 733 | **Description:** Abstractions for holding time values, both in terms of |
| 734 | absolute time and civil time. |
| 735 | |
| 736 | **Documentation:** [Time](https://abseil.io/docs/cpp/guides/time) |
| 737 | |
| 738 | **Notes:** |
| 739 | *** promo |
| 740 | Overlaps with `Time` APIs in `base/`. |
| 741 | *** |