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 |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 12 | years (C++11, C++14, etc.). For various reasons, Chromium does not immediately |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 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_ |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 32 | * **C++17:** Initially supported December 23, 2021; see allowed/banned/TBD |
| 33 | features below |
| 34 | * **C++20:** _Not yet supported in Chromium_ |
| 35 | * **C++23:** _Not yet standardized_ |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 36 | * **Abseil:** Initially supported July 31, 2020; see allowed/banned/TBD |
| 37 | features below |
| 38 | * absl::StatusOr: Initially supported September 3, 2020 |
| 39 | * absl::Cleanup: Initially supported February 4, 2021 |
| 40 | |
| 41 | [TOC] |
| 42 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 43 | ## C++11 Banned Language Features {#core-blocklist-11} |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 44 | |
| 45 | The following C++11 language features are not allowed in the Chromium codebase. |
| 46 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 47 | ### Inline Namespaces <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 48 | |
| 49 | ```c++ |
| 50 | inline namespace foo { ... } |
| 51 | ``` |
| 52 | |
| 53 | **Description:** Allows better versioning of namespaces. |
| 54 | |
| 55 | **Documentation:** |
| 56 | [Inline namespaces](https://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces) |
| 57 | |
| 58 | **Notes:** |
| 59 | *** promo |
| 60 | Banned in the |
| 61 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Namespaces). |
| 62 | Unclear how it will work with components. |
| 63 | *** |
| 64 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 65 | ### long long Type <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 66 | |
| 67 | ```c++ |
| 68 | long long var = value; |
| 69 | ``` |
| 70 | |
| 71 | **Description:** An integer of at least 64 bits. |
| 72 | |
| 73 | **Documentation:** |
| 74 | [Fundamental types](https://en.cppreference.com/w/cpp/language/types) |
| 75 | |
| 76 | **Notes:** |
| 77 | *** promo |
| 78 | Use a stdint.h type if you need a 64-bit number. |
| 79 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk) |
| 80 | *** |
| 81 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 82 | ### User-Defined Literals <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 83 | |
| 84 | ```c++ |
| 85 | type var = literal_value_type; |
| 86 | ``` |
| 87 | |
| 88 | **Description:** Allows user-defined literal expressions. |
| 89 | |
| 90 | **Documentation:** |
| 91 | [User-defined literals](https://en.cppreference.com/w/cpp/language/user_literal) |
| 92 | |
| 93 | **Notes:** |
| 94 | *** promo |
| 95 | Banned in the |
| 96 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Operator_Overloading). |
| 97 | *** |
| 98 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 99 | ### thread_local Storage Class <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 100 | |
| 101 | ```c++ |
| 102 | thread_local int foo = 1; |
| 103 | ``` |
| 104 | |
| 105 | **Description:** Puts variables into thread local storage. |
| 106 | |
| 107 | **Documentation:** |
| 108 | [Storage duration](https://en.cppreference.com/w/cpp/language/storage_duration) |
| 109 | |
| 110 | **Notes:** |
| 111 | *** promo |
| 112 | Some surprising effects on Mac |
| 113 | ([discussion](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2msN8k3Xzgs), |
| 114 | [fork](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/h7O5BdtWCZw)). |
| 115 | Use `base::SequenceLocalStorageSlot` for sequence support, and |
| 116 | `base::ThreadLocal`/`base::ThreadLocalStorage` otherwise. |
| 117 | *** |
| 118 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 119 | ## C++11 Banned Library Features {#library-blocklist-11} |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 120 | |
| 121 | The following C++11 library features are not allowed in the Chromium codebase. |
| 122 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 123 | ### Bind Operations <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 124 | |
| 125 | ```c++ |
| 126 | std::bind(function, args, ...) |
| 127 | ``` |
| 128 | |
| 129 | **Description:** Declares a function object bound to certain arguments |
| 130 | |
| 131 | **Documentation:** |
| 132 | [std::bind](https://en.cppreference.com/w/cpp/utility/functional/bind) |
| 133 | |
| 134 | **Notes:** |
| 135 | *** promo |
| 136 | Use `base::Bind` instead. Compared to `std::bind`, `base::Bind` helps prevent |
| 137 | lifetime issues by preventing binding of capturing lambdas and by forcing |
| 138 | callers to declare raw pointers as `Unretained`. |
| 139 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
| 140 | *** |
| 141 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 142 | ### C Floating-Point Environment <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 143 | |
| 144 | ```c++ |
| 145 | #include <cfenv> |
| 146 | #include <fenv.h> |
| 147 | ``` |
| 148 | |
| 149 | **Description:** Provides floating point status flags and control modes for |
| 150 | C-compatible code |
| 151 | |
| 152 | **Documentation:** |
| 153 | [Standard library header "cfenv"](https://en.cppreference.com/w/cpp/header/cfenv) |
| 154 | |
| 155 | **Notes:** |
| 156 | *** promo |
| 157 | Banned by the |
| 158 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 159 | due to concerns about compiler support. |
| 160 | *** |
| 161 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 162 | ### Date and time utilities <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 163 | |
| 164 | ```c++ |
| 165 | #include <chrono> |
| 166 | ``` |
| 167 | |
| 168 | **Description:** A standard date and time library |
| 169 | |
| 170 | **Documentation:** |
| 171 | [Date and time utilities](https://en.cppreference.com/w/cpp/chrono) |
| 172 | |
| 173 | **Notes:** |
| 174 | *** promo |
| 175 | Overlaps with `Time` APIs in `base/`. Keep using the `base/` classes. |
| 176 | *** |
| 177 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 178 | ### Exceptions <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 179 | |
| 180 | ```c++ |
| 181 | #include <exception> |
| 182 | ``` |
| 183 | |
| 184 | **Description:** Enhancements to exception throwing and handling |
| 185 | |
| 186 | **Documentation:** |
| 187 | [Standard library header "exception"](https://en.cppreference.com/w/cpp/header/exception) |
| 188 | |
| 189 | **Notes:** |
| 190 | *** promo |
| 191 | Exceptions are banned by the |
| 192 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Exceptions) |
| 193 | and disabled in Chromium compiles. However, the `noexcept` specifier is |
| 194 | explicitly allowed. |
| 195 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg) |
| 196 | *** |
| 197 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 198 | ### Function Objects <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 199 | |
| 200 | ```c++ |
| 201 | std::function |
| 202 | ``` |
| 203 | |
| 204 | **Description:** Wraps a standard polymorphic function |
| 205 | |
| 206 | **Documentation:** |
| 207 | [std::function](https://en.cppreference.com/w/cpp/utility/functional/function) |
| 208 | |
| 209 | **Notes:** |
| 210 | *** promo |
| 211 | Use `base::{Once,Repeating}Callback` instead. Compared to `std::function`, |
| 212 | `base::{Once,Repeating}Callback` directly supports Chromium's refcounting |
| 213 | classes and weak pointers and deals with additional thread safety concerns. |
| 214 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA) |
| 215 | *** |
| 216 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 217 | ### Random Number Engines <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 218 | |
| 219 | *** aside |
| 220 | The random number engines defined in `<random>` (see separate item for random |
| 221 | number distributions), e.g.: `linear_congruential_engine`, |
| 222 | `mersenne_twister_engine`, `minstd_rand0`, `mt19937`, `ranlinux48`, |
| 223 | `random_device` |
| 224 | *** |
| 225 | |
| 226 | **Description:** Random number generation algorithms and utilities. |
| 227 | |
| 228 | **Documentation:** |
| 229 | [Pseudo-random number generation](https://en.cppreference.com/w/cpp/numeric/random) |
| 230 | |
| 231 | **Notes:** |
| 232 | *** promo |
| 233 | Do not use any random number engines from `<random>`. Instead, use |
| 234 | `base::RandomBitGenerator`. |
| 235 | [Discussion thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16Xmw05C-Y0) |
| 236 | *** |
| 237 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 238 | ### Ratio Template Class <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 239 | |
| 240 | ```c++ |
| 241 | std::ratio<numerator, denominator> |
| 242 | ``` |
| 243 | |
| 244 | **Description:** Provides compile-time rational numbers |
| 245 | |
| 246 | **Documentation:** |
| 247 | [std::ratio](https://en.cppreference.com/w/cpp/numeric/ratio/ratio) |
| 248 | |
| 249 | **Notes:** |
| 250 | *** promo |
| 251 | Banned by the |
| 252 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#C++11) |
| 253 | due to concerns that this is tied to a more template-heavy interface style. |
| 254 | *** |
| 255 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 256 | ### Regular Expressions <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 257 | |
| 258 | ```c++ |
| 259 | #include <regex> |
| 260 | ``` |
| 261 | |
| 262 | **Description:** A standard regular expressions library |
| 263 | |
| 264 | **Documentation:** |
| 265 | [Regular expressions library](https://en.cppreference.com/w/cpp/regex) |
| 266 | |
| 267 | **Notes:** |
| 268 | *** promo |
| 269 | Overlaps with many regular expression libraries in Chromium. When in doubt, use |
| 270 | `re2`. |
| 271 | *** |
| 272 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 273 | ### Shared Pointers <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 274 | |
| 275 | ```c++ |
| 276 | std::shared_ptr |
| 277 | ``` |
| 278 | |
| 279 | **Description:** Allows shared ownership of a pointer through reference counts |
| 280 | |
| 281 | **Documentation:** |
| 282 | [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr) |
| 283 | |
| 284 | **Notes:** |
| 285 | *** promo |
| 286 | Needs a lot more evaluation for Chromium, and there isn't enough of a push for |
| 287 | this feature. |
| 288 | |
| 289 | * [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers). |
| 290 | * [Discussion Thread](https://groups.google.com/a/chromium.org/forum/#!topic/cxx/aT2wsBLKvzI) |
| 291 | *** |
| 292 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 293 | ### String-Number Conversion Functions <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 294 | |
| 295 | ```c++ |
| 296 | std::stoi() |
| 297 | std::stol() |
| 298 | std::stoul() |
| 299 | std::stoll |
| 300 | std::stoull() |
| 301 | std::stof() |
| 302 | std::stod() |
| 303 | std::stold() |
| 304 | std::to_string() |
| 305 | ``` |
| 306 | |
| 307 | **Description:** Converts strings to/from numbers |
| 308 | |
| 309 | **Documentation:** |
| 310 | * [std::stoi, std::stol, std::stoll](https://en.cppreference.com/w/cpp/string/basic_string/stol), |
| 311 | * [std::stoul, std::stoull](https://en.cppreference.com/w/cpp/string/basic_string/stoul), |
| 312 | * [std::stof, std::stod, std::stold](https://en.cppreference.com/w/cpp/string/basic_string/stof), |
| 313 | * [std::to_string](https://en.cppreference.com/w/cpp/string/basic_string/to_string) |
| 314 | |
| 315 | **Notes:** |
| 316 | *** promo |
| 317 | The string-to-number conversions rely on exceptions to communicate failure, |
| 318 | while the number-to-string conversions have performance concerns and depend on |
| 319 | the locale. Use the routines in `base/strings/string_number_conversions.h` |
| 320 | instead. |
| 321 | *** |
| 322 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 323 | ### Thread Library <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 324 | |
| 325 | *** aside |
| 326 | `<thread>` and related headers, including `<future>`, `<mutex>`, |
| 327 | `<condition_variable>` |
| 328 | *** |
| 329 | |
| 330 | **Description:** Provides a standard multithreading library using `std::thread` |
| 331 | and associates |
| 332 | |
| 333 | **Documentation:** |
| 334 | [Thread support library](https://en.cppreference.com/w/cpp/thread) |
| 335 | |
| 336 | **Notes:** |
| 337 | *** promo |
| 338 | Overlaps with many classes in `base/`. Keep using the `base/` classes for now. |
| 339 | `base::Thread` is tightly coupled to `MessageLoop` which would make it hard to |
| 340 | replace. We should investigate using standard mutexes, or unique_lock, etc. to |
| 341 | replace our locking/synchronization classes. |
| 342 | *** |
| 343 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 344 | ### Weak Pointers <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 345 | |
| 346 | ```c++ |
| 347 | std::weak_ptr |
| 348 | ``` |
| 349 | |
| 350 | **Description:** Allows a weak reference to a `std::shared_ptr` |
| 351 | |
| 352 | **Documentation:** |
| 353 | [std::weak_ptr](https://en.cppreference.com/w/cpp/memory/weak_ptr) |
| 354 | |
| 355 | **Notes:** |
| 356 | *** promo |
| 357 | Banned because `std::shared_ptr` is banned. Use `base::WeakPtr` instead. |
| 358 | *** |
| 359 | |
| 360 | ## C++14 Banned Library Features {#library-blocklist-14} |
| 361 | |
| 362 | The following C++14 library features are not allowed in the Chromium codebase. |
| 363 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 364 | ### std::chrono literals <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 365 | |
| 366 | ```c++ |
| 367 | using namespace std::chrono_literals; |
| 368 | auto timeout = 30s; |
| 369 | ``` |
| 370 | |
| 371 | **Description:** Allows `std::chrono` types to be more easily constructed. |
| 372 | |
| 373 | **Documentation:** |
| 374 | [std::literals::chrono_literals::operator""s](https://en.cppreference.com/w/cpp/chrono/operator%22%22s) |
| 375 | |
| 376 | **Notes:** |
| 377 | *** promo |
| 378 | Banned because `<chrono>` is banned. |
| 379 | *** |
| 380 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 381 | ## C++17 Allowed Language Features {#core-allowlist-17} |
| 382 | |
| 383 | The following C++17 language features are allowed in the Chromium codebase. |
| 384 | |
Avi Drissman | efca412 | 2022-01-05 23:59:36 | [diff] [blame] | 385 | ### Nested namespaces <sup>[allowed]</sup> |
| 386 | |
| 387 | ```c++ |
| 388 | namespace A::B::C { ... |
| 389 | ``` |
| 390 | |
| 391 | **Description:** Using the namespace resolution operator to create nested |
| 392 | namespace definitions. |
| 393 | |
| 394 | **Documentation:** |
| 395 | [Namespaces](https://en.cppreference.com/w/cpp/language/namespace) |
| 396 | |
| 397 | **Notes:** |
| 398 | *** promo |
| 399 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/gLdR3apDSmg/) |
| 400 | *** |
| 401 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 402 | ### Template argument deduction for class templates <sup>[allowed]</sup> |
| 403 | |
| 404 | ```c++ |
| 405 | template <typename T> |
| 406 | struct MyContainer { |
| 407 | MyContainer(T val) : val{val} {} |
| 408 | // ... |
| 409 | }; |
| 410 | MyContainer c1(1); // Type deduced to be `int`. |
| 411 | ``` |
| 412 | |
| 413 | **Description:** Automatic template argument deduction much like how it's done |
| 414 | for functions, but now including class constructors. |
| 415 | |
| 416 | **Documentation:** |
| 417 | [Class template argument deduction](https://en.cppreference.com/w/cpp/language/class_template_argument_deduction) |
| 418 | |
| 419 | **Notes:** |
| 420 | *** promo |
| 421 | Usage is governed by the |
| 422 | [Google Style Guide](https://google.github.io/styleguide/cppguide.html#CTAD). |
| 423 | *** |
| 424 | |
Andrew Rayskiy | 6ce944d | 2022-01-04 18:13:33 | [diff] [blame] | 425 | ### Selection statements with initializer <sup>[allowed]</sup> |
| 426 | |
| 427 | ```c++ |
| 428 | if (int a = Func(); a < 3) { ... |
| 429 | switch (int a = Func(); a) { ... |
| 430 | ``` |
| 431 | |
| 432 | **Description:** New versions of the if and switch statements which simplify |
| 433 | common code patterns and help users keep scopes tight. |
| 434 | |
| 435 | **Documentation:** |
| 436 | [if statement](https://en.cppreference.com/w/cpp/language/if), |
| 437 | [switch statement](https://en.cppreference.com/w/cpp/language/switch) |
| 438 | |
| 439 | **Notes:** |
| 440 | *** promo |
| 441 | [@cxx discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/4GP43nftePE) |
| 442 | *** |
| 443 | |
Roland Bock | f5242fb | 2022-01-05 17:54:38 | [diff] [blame] | 444 | ### fallthrough attribute <sup>[allowed]</sup> |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 445 | |
| 446 | ```c++ |
| 447 | case 1: |
| 448 | DoSomething(); |
| 449 | [[fallthrough]]; |
| 450 | case 2: |
| 451 | break; |
| 452 | ``` |
| 453 | |
| 454 | **Description:** |
| 455 | The `[[fallthrough]]` attribute can be used in switch statements to indicate |
| 456 | when intentionally falling through to the next case. |
| 457 | |
| 458 | **Documentation:** |
| 459 | [C++ attribute: fallthrough](https://en.cppreference.com/w/cpp/language/attributes/fallthrough) |
| 460 | |
| 461 | **Notes:** |
| 462 | *** promo |
| 463 | See [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JrvyFd243QI). |
| 464 | |
| 465 | See [migration task](https://bugs.chromium.org/p/chromium/issues/detail?id=1283907). |
| 466 | *** |
| 467 | |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 468 | ### constexpr if <sup>[allowed]</sup> |
| 469 | |
| 470 | ```c++ |
| 471 | if constexpr (cond) { ... |
| 472 | ``` |
| 473 | |
| 474 | **Description:** Write code that is instantiated depending on a compile-time |
| 475 | condition. |
| 476 | |
| 477 | **Documentation:** |
| 478 | [if statement](https://en.cppreference.com/w/cpp/language/if) |
| 479 | |
| 480 | **Notes:** |
| 481 | *** promo |
| 482 | See [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/op2ePZnjP0w). |
Avi Drissman | c2558ba | 2022-01-13 19:49:01 | [diff] [blame] | 483 | *** |
Victor Costan | dcddd26 | 2022-01-12 19:20:39 | [diff] [blame] | 484 | |
Avi Drissman | 7ba88aa6 | 2022-01-13 14:15:48 | [diff] [blame] | 485 | ### maybe_unused attribute <sup>[allowed]</sup> |
| 486 | |
| 487 | ```c++ |
| 488 | struct [[maybe_unused]] MyUnusedThing; |
| 489 | [[maybe_unused]] int x; |
| 490 | ``` |
| 491 | |
| 492 | **Description:** |
| 493 | The `[[maybe_unused]]` attribute can be used to indicate that individual |
| 494 | variables, functions, or fields of a class/struct/enum can be left unused. |
| 495 | |
| 496 | **Documentation:** |
| 497 | [C++ attribute: maybe_unused](https://en.cppreference.com/w/cpp/language/attributes/maybe_unused) |
| 498 | |
| 499 | **Notes:** |
| 500 | *** promo |
| 501 | See [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/jPLfU5eRg8M/). |
| 502 | *** |
| 503 | |
Victor Costan | dcddd26 | 2022-01-12 19:20:39 | [diff] [blame] | 504 | ### Structured bindings <sup>[allowed]</sup> |
| 505 | |
| 506 | ```c++ |
| 507 | const auto [x, y] = FuncReturningStdPair(); |
| 508 | ``` |
| 509 | |
| 510 | **Description:** Allows writing `auto [x, y, z] = expr;` where the type of |
| 511 | `expr` is a tuple-like object, whose elements are bound to the variables `x`, |
| 512 | `y`, and `z` (which this construct declares). Tuple-like objects include |
| 513 | `std::tuple`, `std::pair`, `std::array`, and aggregate structures. |
| 514 | |
| 515 | **Documentation:** |
| 516 | [Structured binding declaration](https://en.cppreference.com/w/cpp/language/structured_binding) |
| 517 | [Explanation of structured binding types](https://jguegant.github.io/blogs/tech/structured-bindings.html) |
| 518 | |
| 519 | **Notes:** |
| 520 | *** promo |
| 521 | In C++17, structured bindings don't work with lambda captures. |
| 522 | [C++20 will allow capturing structured bindings by value](https://wg21.link/p1091r3). |
| 523 | |
| 524 | This feature forces omitting type names. Its use should follow |
| 525 | [the guidance around `auto` in Google C++ Style guide](https://google.github.io/styleguide/cppguide.html#Type_deduction). |
| 526 | |
| 527 | See [discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ExfSorNLNf4). |
Jayson Adams | 62f16c0 | 2022-01-11 15:03:35 | [diff] [blame] | 528 | *** |
| 529 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 530 | ## C++17 Allowed Library Features {#library-allowlist-17} |
| 531 | |
| 532 | The following C++17 language features are allowed in the Chromium codebase. |
| 533 | |
| 534 | ### Allocation functions with explicit alignment <sup>[allowed]</sup> |
| 535 | |
| 536 | ```c++ |
| 537 | class alignas(32) Vec3d { |
| 538 | double x, y, z; |
| 539 | }; |
| 540 | auto p_vec = new Vec3d[10]; // 32-byte aligned in C++17, maybe not previously |
| 541 | ``` |
| 542 | |
| 543 | **Description:** Performs heap allocation of objects whose alignment |
| 544 | requirements exceed `__STDCPP_DEFAULT_NEW_ALIGNMENT__`. |
| 545 | |
| 546 | **Documentation:** |
| 547 | [operator new](https://en.cppreference.com/w/cpp/memory/new/operator_new) |
| 548 | |
| 549 | **Notes:** |
| 550 | *** promo |
| 551 | None |
| 552 | *** |
| 553 | |
Daniel Cheng | 6f510fa | 2022-01-12 19:36:03 | [diff] [blame] | 554 | ### Type trait variable templates <sup>[tbd]</sup> |
| 555 | |
| 556 | ```c++ |
| 557 | bool b = std::is_same_v<int, std::int32_t>; |
| 558 | ``` |
| 559 | |
| 560 | **Description:** Syntactic sugar to provide convenient access to `::value` |
| 561 | members by simply adding `_v`. |
| 562 | |
| 563 | **Documentation:** |
| 564 | [Type support](https://en.cppreference.com/w/cpp/types) |
| 565 | |
| 566 | **Notes:** |
| 567 | *** promo |
| 568 | [Discussion thread](Non://groups.google.com/a/chromium.org/g/cxx/c/KEa-0AOGRNY/m/IV_S3_pvAAAJ) |
| 569 | *** |
| 570 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 571 | ## C++17 Banned Library Features {#library-blocklist-17} |
| 572 | |
| 573 | The following C++17 library features are not allowed in the Chromium codebase. |
| 574 | |
Daniel Cheng | c05fcc6 | 2022-01-12 16:54:29 | [diff] [blame] | 575 | ### std::any <sup>[banned]</sup> |
| 576 | |
| 577 | ```c++ |
| 578 | std::any x = 5; |
| 579 | ``` |
| 580 | |
| 581 | **Description:** A type-safe container for single values of any type. |
| 582 | |
| 583 | **Documentation:** |
| 584 | [std::any](https://en.cppreference.com/w/cpp/utility/any) |
| 585 | |
| 586 | **Notes:** |
| 587 | *** promo |
| 588 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/KEa-0AOGRNY/m/IV_S3_pvAAAJ) |
| 589 | |
| 590 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 591 | build ([Bug](https://crbug.com/1096380)). Also see `absl::any`. |
| 592 | *** |
| 593 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 594 | ### std::filesystem <sup>[banned]</sup> |
| 595 | |
| 596 | ```c++ |
| 597 | #include <filesystem> |
| 598 | ``` |
| 599 | |
| 600 | **Description:** A standard way to manipulate files, directories, and paths in a |
| 601 | filesystem. |
| 602 | |
| 603 | **Documentation:** |
| 604 | [Filesystem library](https://en.cppreference.com/w/cpp/filesystem) |
| 605 | |
| 606 | **Notes:** |
| 607 | *** promo |
| 608 | Banned by the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Other_Features). |
| 609 | *** |
| 610 | |
| 611 | ### weak_from_this <sup>[banned]</sup> |
| 612 | |
| 613 | ```c++ |
| 614 | auto weak_ptr = weak_from_this(); |
| 615 | ``` |
| 616 | |
| 617 | **Description:** Returns a `std::weak_ptr<T>` that tracks ownership of `*this` |
| 618 | by all existing `std::shared_ptr`s that refer to `*this`. |
| 619 | |
| 620 | **Documentation:** |
| 621 | [std::enable_shared_from_this<T>::weak_from_this](https://en.cppreference.com/w/cpp/memory/enable_shared_from_this/weak_from_this) |
| 622 | |
| 623 | **Notes:** |
| 624 | *** promo |
| 625 | Banned since `std::shared_ptr` and `std::weak_ptr` are banned. |
| 626 | *** |
| 627 | |
| 628 | ### Transparent std::owner_less <sup>[banned]</sup> |
| 629 | |
| 630 | ```c++ |
| 631 | std::map<std::weak_ptr<T>, U, std::owner_less<>> |
| 632 | ``` |
| 633 | |
| 634 | **Description:** Function object providing mixed-type owner-based ordering of |
| 635 | shared and weak pointers, regardless of the type of the pointee. |
| 636 | |
| 637 | **Documentation:** |
| 638 | [std::owner_less](https://en.cppreference.com/w/cpp/memory/owner_less) |
| 639 | |
| 640 | **Notes:** |
| 641 | *** promo |
| 642 | Banned since `std::shared_ptr` and `std::weak_ptr` are banned. |
| 643 | *** |
| 644 | |
| 645 | ### Array support for std::shared_ptr <sup>[banned]</sup> |
| 646 | |
| 647 | ```c++ |
| 648 | std::shared_ptr<int[]> p(new int[10]{0,1,2,3,4,5,6,7,8,9}); |
| 649 | std::cout << p[3]; // "3" |
| 650 | ``` |
| 651 | |
| 652 | **Description:** Supports memory management of arrays via `std::shared_ptr`. |
| 653 | |
| 654 | **Documentation:** |
| 655 | [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr) |
| 656 | |
| 657 | **Notes:** |
| 658 | *** promo |
| 659 | Banned since `std::shared_ptr` is banned. |
| 660 | *** |
| 661 | |
| 662 | ### std::uncaught_exceptions <sup>[banned]</sup> |
| 663 | |
| 664 | ```c++ |
| 665 | int count = std::uncaught_exceptions(); |
| 666 | ``` |
| 667 | |
| 668 | **Description:** Determines whether there are live exception objects. |
| 669 | |
| 670 | **Documentation:** |
| 671 | [std::uncaught_exceptions](https://en.cppreference.com/w/cpp/error/uncaught_exception) |
| 672 | |
| 673 | **Notes:** |
| 674 | *** promo |
| 675 | Banned because exceptions are banned. |
| 676 | *** |
| 677 | |
| 678 | ### Rounding functions for duration and time_point <sup>[banned]</sup> |
| 679 | |
| 680 | ```c++ |
| 681 | std::chrono::ceil<std::chrono::seconds>(dur); |
| 682 | std::chrono::ceil<std::chrono::seconds>(time_pt); |
| 683 | std::chrono::floor<std::chrono::seconds>(dur); |
| 684 | std::chrono::floor<std::chrono::seconds>(time_pt); |
| 685 | std::chrono::round<std::chrono::seconds>(dur); |
| 686 | std::chrono::round<std::chrono::seconds>(time_pt); |
| 687 | ``` |
| 688 | |
| 689 | **Description:** Converts durations and time_points by rounding. |
| 690 | |
| 691 | **Documentation:** |
| 692 | [std::chrono::duration](https://en.cppreference.com/w/cpp/chrono/duration), |
| 693 | [std::chrono::time_point](https://en.cppreference.com/w/cpp/chrono/time_point) |
| 694 | |
| 695 | **Notes:** |
| 696 | *** promo |
| 697 | Banned since `std::chrono` is banned. |
| 698 | *** |
| 699 | |
| 700 | ## C++17 TBD Language Features {#core-review-17} |
| 701 | |
| 702 | The following C++17 language features are not allowed in the Chromium codebase. |
| 703 | See the top of this page on how to propose moving a feature from this list into |
| 704 | the allowed or banned sections. |
| 705 | |
| 706 | ### Declaring non-type template parameters with auto <sup>[tbd]</sup> |
| 707 | |
| 708 | ```c++ |
| 709 | template <auto... seq> |
| 710 | struct my_integer_sequence { |
| 711 | // ... |
| 712 | }; |
| 713 | auto seq = my_integer_sequence<0, 1, 2>(); // Type deduced to be `int`. |
| 714 | ``` |
| 715 | |
| 716 | **Description:** Following the deduction rules of `auto`, while respecting the |
| 717 | non-type template parameter list of allowable types, template arguments can be |
| 718 | deduced from the types of its arguments. |
| 719 | |
| 720 | **Documentation:** |
| 721 | [Template parameters](https://en.cppreference.com/w/cpp/language/template_parameters) |
| 722 | |
| 723 | **Notes:** |
| 724 | *** promo |
| 725 | None |
| 726 | *** |
| 727 | |
| 728 | ### Fold expressions <sup>[tbd]</sup> |
| 729 | |
| 730 | ```c++ |
| 731 | template <typename... Args> |
| 732 | auto sum(Args... args) { |
| 733 | return (... + args); |
| 734 | } |
| 735 | ``` |
| 736 | |
| 737 | **Description:** A fold expression performs a fold of a template parameter pack |
| 738 | over a binary operator. |
| 739 | |
| 740 | **Documentation:** |
| 741 | [Fold expression](https://en.cppreference.com/w/cpp/language/fold) |
| 742 | |
| 743 | **Notes:** |
| 744 | *** promo |
| 745 | None |
| 746 | *** |
| 747 | |
| 748 | ### constexpr lambda <sup>[tbd]</sup> |
| 749 | |
| 750 | ```c++ |
| 751 | auto identity = [](int n) constexpr { return n; }; |
| 752 | static_assert(identity(123) == 123); |
| 753 | ``` |
| 754 | |
| 755 | **Description:** Compile-time lambdas using constexpr. |
| 756 | |
| 757 | **Documentation:** |
| 758 | [Lambda expressions](https://en.cppreference.com/w/cpp/language/lambda) |
| 759 | |
| 760 | **Notes:** |
| 761 | *** promo |
| 762 | None |
| 763 | *** |
| 764 | |
| 765 | ### Lambda capture this by value <sup>[tbd]</sup> |
| 766 | |
| 767 | ```c++ |
| 768 | const auto l = [*this] { return member_; } |
| 769 | ``` |
| 770 | |
| 771 | **Description:** `*this` captures the current object by copy, while `this` |
| 772 | continues to capture by reference. |
| 773 | |
| 774 | **Documentation:** |
| 775 | [Lambda capture](https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture) |
| 776 | |
| 777 | **Notes:** |
| 778 | *** promo |
| 779 | None |
| 780 | *** |
| 781 | |
| 782 | ### Inline variables <sup>[tbd]</sup> |
| 783 | |
| 784 | ```c++ |
| 785 | struct S { |
| 786 | static constexpr int kZero = 0; // constexpr implies inline here |
| 787 | }; |
| 788 | ``` |
| 789 | |
| 790 | **Description:** The `inline` specifier can be applied to variables as well as |
| 791 | to functions. A variable declared inline has the same semantics as a function |
| 792 | declared inline. It can also be used to declare and define a static member |
| 793 | variable, such that it does not need to be initialized in the source file. |
| 794 | |
| 795 | **Documentation:** |
| 796 | [inline specifier](https://en.cppreference.com/w/cpp/language/inline) |
| 797 | |
| 798 | **Notes:** |
| 799 | *** promo |
| 800 | None |
| 801 | *** |
| 802 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 803 | ### UTF-8 character literals <sup>[tbd]</sup> |
| 804 | |
| 805 | ```c++ |
| 806 | char x = u8'x'; |
| 807 | ``` |
| 808 | |
| 809 | **Description:** A character literal that begins with `u8` is a character |
| 810 | literal of type `char`. The value of a UTF-8 character literal is equal to its |
| 811 | ISO 10646 code point value. |
| 812 | |
| 813 | **Documentation:** |
| 814 | [Character literal](https://en.cppreference.com/w/cpp/language/character_literal) |
| 815 | |
| 816 | **Notes:** |
| 817 | *** promo |
| 818 | C++20 changes the type to `char8_t`, causing migration hazards for code using |
| 819 | this. |
| 820 | *** |
| 821 | |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 822 | ### nodiscard attribute <sup>[tbd]</sup> |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 823 | |
| 824 | ```c++ |
Roland Bock | f5242fb | 2022-01-05 17:54:38 | [diff] [blame] | 825 | struct [[nodiscard]] ErrorOrValue; |
| 826 | [[nodiscard]] bool DoSomething(); |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 827 | ``` |
| 828 | |
Roland Bock | f5242fb | 2022-01-05 17:54:38 | [diff] [blame] | 829 | **Description:** |
| 830 | The `[[nodiscard]]` attribute can be used to indicate that |
| 831 | |
| 832 | - the return value of a function should not be ignored |
| 833 | - values of annotated classes/structs/enums returned from functions should not |
| 834 | be ignored |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 835 | |
| 836 | **Documentation:** |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 837 | [C++ attribute: nodiscard](https://en.cppreference.com/w/cpp/language/attributes/nodiscard) |
| 838 | |
| 839 | **Notes:** |
| 840 | *** promo |
Roland Bock | f5242fb | 2022-01-05 17:54:38 | [diff] [blame] | 841 | See `WARN_UNUSED_RESULT` macro in base/compiler_specific.h. |
Roland Bock | 767858e | 2022-01-04 20:25:21 | [diff] [blame] | 842 | *** |
| 843 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 844 | ### using declaration for attributes <sup>[tbd]</sup> |
| 845 | |
| 846 | ```c++ |
| 847 | [[using CC: opt(1), debug]] // same as [[CC:opt(1), CC::debug]] |
| 848 | ``` |
| 849 | |
| 850 | **Description:** Specifies a common namespace for a list of attributes. |
| 851 | |
| 852 | **Documentation:** |
| 853 | [Attribute specifier sequence](https://en.cppreference.com/w/cpp/language/attributes) |
| 854 | |
| 855 | **Notes:** |
| 856 | *** promo |
| 857 | See similar attribute macros in base/compiler_specific.h. |
| 858 | *** |
| 859 | |
| 860 | ### __has_include <sup>[tbd]</sup> |
| 861 | |
| 862 | ```c++ |
| 863 | #if __has_include(<optional>) ... |
| 864 | ``` |
| 865 | |
| 866 | **Description:** Checks whether a file is available for inclusion, i.e. the file |
| 867 | exists. |
| 868 | |
| 869 | **Documentation:** |
| 870 | [Source file inclusion](https://en.cppreference.com/w/cpp/preprocessor/include) |
| 871 | |
| 872 | **Notes:** |
| 873 | *** promo |
| 874 | None |
| 875 | *** |
| 876 | |
| 877 | ## C++17 TBD Library Features {#library-review-17} |
| 878 | |
| 879 | The following C++17 library features are not allowed in the Chromium codebase. |
| 880 | See the top of this page on how to propose moving a feature from this list into |
| 881 | the allowed or banned sections. |
| 882 | |
| 883 | ### std::variant <sup>[tbd]</sup> |
| 884 | |
| 885 | ```c++ |
| 886 | std::variant<int, double> v = 12; |
| 887 | ``` |
| 888 | |
| 889 | **Description:** The class template `std::variant` represents a type-safe |
| 890 | `union`. An instance of `std::variant` at any given time holds a value of one of |
| 891 | its alternative types (it's also possible for it to be valueless). |
| 892 | |
| 893 | **Documentation:** |
| 894 | [std::variant](https://en.cppreference.com/w/cpp/utility/variant) |
| 895 | |
| 896 | **Notes:** |
| 897 | *** promo |
| 898 | See also `absl::variant`. |
| 899 | *** |
| 900 | |
| 901 | ### std::optional <sup>[tbd]</sup> |
| 902 | |
| 903 | ```c++ |
| 904 | std::optional<std::string> s; |
| 905 | ``` |
| 906 | |
| 907 | **Description:** The class template `std::optional` manages an optional |
| 908 | contained value, i.e. a value that may or may not be present. A common use case |
| 909 | for optional is the return value of a function that may fail. |
| 910 | |
| 911 | **Documentation:** |
| 912 | [std::optional](https://en.cppreference.com/w/cpp/utility/optional) |
| 913 | |
| 914 | **Notes:** |
| 915 | *** promo |
| 916 | See also `absl::optional`. |
| 917 | *** |
| 918 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 919 | ### std::string_view <sup>[tbd]</sup> |
| 920 | |
| 921 | ```c++ |
| 922 | std::string_view str = "foo"; |
| 923 | ``` |
| 924 | |
| 925 | **Description:** A non-owning reference to a string. Useful for providing an |
| 926 | abstraction on top of strings (e.g. for parsing). |
| 927 | |
| 928 | **Documentation:** |
| 929 | [std::basic_string_view](https://en.cppreference.com/w/cpp/string/basic_string_view) |
| 930 | |
| 931 | **Notes:** |
| 932 | *** promo |
| 933 | See also `absl::string_view` and `base::StringPiece`. |
| 934 | *** |
| 935 | |
| 936 | ### std::invoke <sup>[tbd]</sup> |
| 937 | |
| 938 | ```c++ |
| 939 | static_assert(std::invoke(std::plus<>(), 1, 2) == 3); |
| 940 | ``` |
| 941 | |
| 942 | **Description:** Invokes a `Callable` object with parameters. An example of a |
| 943 | `Callable` object is `base::Callback` where an object can be called similarly to |
| 944 | a regular function. |
| 945 | |
| 946 | **Documentation:** |
| 947 | [std::invoke](https://en.cppreference.com/w/cpp/utility/functional/invoke) |
| 948 | |
| 949 | **Notes:** |
| 950 | *** promo |
| 951 | See also `base::invoke`. |
| 952 | *** |
| 953 | |
| 954 | ### std::apply <sup>[tbd]</sup> |
| 955 | |
| 956 | ```c++ |
| 957 | static_assert(std::apply(std::plus<>(), std::make_tuple(1, 2)) == 3); |
| 958 | ``` |
| 959 | |
| 960 | **Description:** Invokes a `Callable` object with a tuple of arguments. |
| 961 | |
| 962 | **Documentation:** |
| 963 | [std::apply](https://en.cppreference.com/w/cpp/utility/apply) |
| 964 | |
| 965 | **Notes:** |
| 966 | *** promo |
| 967 | See also `absl::apply` and `base::apply`. |
| 968 | *** |
| 969 | |
| 970 | ### std::byte <sup>[tbd]</sup> |
| 971 | |
| 972 | ```c++ |
| 973 | std::byte b = 0xFF; |
| 974 | int i = std::to_integer<int>(b); // 0xFF |
| 975 | ``` |
| 976 | |
| 977 | **Description:** A standard way of representing data as a byte. `std::byte` is |
| 978 | neither a character type nor an arithmetic type, and the only operator overloads |
| 979 | available are bitwise operations. |
| 980 | |
| 981 | **Documentation:** |
| 982 | [std::byte](https://en.cppreference.com/w/cpp/types/byte) |
| 983 | |
| 984 | **Notes:** |
| 985 | *** promo |
| 986 | None |
| 987 | *** |
| 988 | |
| 989 | ### Splicing for maps and sets <sup>[tbd]</sup> |
| 990 | |
| 991 | ```c++ |
| 992 | std::map<...>::extract |
| 993 | std::map<...>::merge |
| 994 | std::set<...>::extract |
| 995 | std::set<...>::merge |
| 996 | ``` |
| 997 | |
| 998 | **Description:** Moving nodes and merging containers without the overhead of |
| 999 | expensive copies, moves, or heap allocations/deallocations. |
| 1000 | |
| 1001 | **Documentation:** |
| 1002 | [std::map::extract](https://en.cppreference.com/w/cpp/container/map/extract), |
| 1003 | [std::map::merge](https://en.cppreference.com/w/cpp/container/map/merge) |
| 1004 | |
| 1005 | **Notes:** |
| 1006 | *** promo |
| 1007 | None |
| 1008 | *** |
| 1009 | |
| 1010 | ### Parallel algorithms <sup>[tbd]</sup> |
| 1011 | |
| 1012 | ```c++ |
| 1013 | auto it = std::find(std::execution::par, std::begin(vec), std::end(vec), 2); |
| 1014 | ``` |
| 1015 | |
| 1016 | **Description:** Many of the STL algorithms, such as the `copy`, `find` and |
| 1017 | `sort` methods, now support the parallel execution policies: `seq`, `par`, and |
| 1018 | `par_unseq` which translate to "sequentially", "parallel" and |
| 1019 | "parallel unsequenced". |
| 1020 | |
| 1021 | **Documentation:** |
| 1022 | [execution_policy_tag_t](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t) |
| 1023 | |
| 1024 | **Notes:** |
| 1025 | *** promo |
| 1026 | None |
| 1027 | *** |
| 1028 | |
| 1029 | ### std::make_from_tuple <sup>[tbd]</sup> |
| 1030 | |
| 1031 | ```c++ |
| 1032 | // Calls Foo(int, double): |
| 1033 | auto foo = std::make_from_tuple<Foo>(std::make_tuple(1, 3.5)); |
| 1034 | ``` |
| 1035 | |
| 1036 | **Description:** Constructs an object from a tuple of arguments. |
| 1037 | |
| 1038 | **Documentation:** |
| 1039 | [std::make_from_tuple](https://en.cppreference.com/w/cpp/utility/make_from_tuple) |
| 1040 | |
| 1041 | **Notes:** |
| 1042 | *** promo |
| 1043 | See also `absl::make_from_tuple`. |
| 1044 | *** |
| 1045 | |
| 1046 | ### Searchers <sup>[tbd]</sup> |
| 1047 | |
| 1048 | ```c++ |
| 1049 | auto it = std::search(haystack.begin(), haystack.end(), |
| 1050 | std::boyer_moore_searcher(needle.begin(), needle.end())); |
| 1051 | ``` |
| 1052 | |
| 1053 | **Description:** Alternate string searching algorithms. |
| 1054 | |
| 1055 | **Documentation:** |
| 1056 | [Searchers](https://en.cppreference.com/w/cpp/utility/functional#Searchers) |
| 1057 | |
| 1058 | **Notes:** |
| 1059 | *** promo |
| 1060 | None |
| 1061 | *** |
| 1062 | |
| 1063 | ### std::as_const <sup>[tbd]</sup> |
| 1064 | |
| 1065 | ```c++ |
| 1066 | auto&& const_ref = std::as_const(mutable_obj); |
| 1067 | ``` |
| 1068 | |
| 1069 | **Description:** Forms reference to const T. |
| 1070 | |
| 1071 | **Documentation:** |
| 1072 | [std::as_const](https://en.cppreference.com/w/cpp/utility/as_const) |
| 1073 | |
| 1074 | **Notes:** |
| 1075 | *** promo |
| 1076 | See also `base::as_const`. |
| 1077 | *** |
| 1078 | |
| 1079 | ### std::not_fn <sup>[tbd]</sup> |
| 1080 | |
| 1081 | ```c++ |
| 1082 | auto nonwhite = std::find_if(str.begin(), str.end(), std::not_fn(IsWhitespace)); |
| 1083 | ``` |
| 1084 | |
| 1085 | **Description:** Creates a forwarding call wrapper that returns the negation of |
| 1086 | the callable object it holds. |
| 1087 | |
| 1088 | **Documentation:** |
| 1089 | [std::not_fn](https://en.cppreference.com/w/cpp/utility/functional/not_fn) |
| 1090 | |
| 1091 | **Notes:** |
| 1092 | *** promo |
| 1093 | See also `base::not_fn`. |
| 1094 | *** |
| 1095 | |
| 1096 | ### Uninitialized memory algorithms <sup>[tbd]</sup> |
| 1097 | |
| 1098 | ```c++ |
| 1099 | std::destroy_at(ptr); |
| 1100 | std::destroy(ptr, ptr + 8); |
| 1101 | std::destroy_n(ptr, 8); |
| 1102 | std::uninitialized_move(src.begin(), src.end(), dest.begin()); |
| 1103 | std::uninitialized_value_construct(std::begin(storage), std::end(storage)); |
| 1104 | ``` |
| 1105 | |
| 1106 | **Description:** Replaces direct constructor and destructor calls when manually |
| 1107 | managing memory. |
| 1108 | |
| 1109 | **Documentation:** |
| 1110 | [std::destroy_at](https://en.cppreference.com/w/cpp/memory/destroy_at), |
| 1111 | [std::destroy](https://en.cppreference.com/w/cpp/memory/destroy), |
| 1112 | [std::destroy_n](https://en.cppreference.com/w/cpp/memory/destroy_n), |
| 1113 | [std::uninitialized_move](https://en.cppreference.com/w/cpp/memory/uninitialized_move), |
| 1114 | [std::uninitialized_value_construct](https://en.cppreference.com/w/cpp/memory/uninitialized_value_construct) |
| 1115 | |
| 1116 | **Notes:** |
| 1117 | *** promo |
| 1118 | None |
| 1119 | *** |
| 1120 | |
| 1121 | ### std::pmr::memory_resource and std::polymorphic_allocator <sup>[tbd]</sup> |
| 1122 | |
| 1123 | ```c++ |
| 1124 | #include <memory_resource> |
| 1125 | ``` |
| 1126 | |
| 1127 | **Description:** Manages memory allocations using runtime polymorphism. |
| 1128 | |
| 1129 | **Documentation:** |
| 1130 | [std::pmr::memory_resource](https://en.cppreference.com/w/cpp/memory/memory_resource), |
| 1131 | [std::pmr::polymorphic_allocator](https://en.cppreference.com/w/cpp/memory/polymorphic_allocator), |
| 1132 | |
| 1133 | **Notes:** |
| 1134 | *** promo |
| 1135 | May not be supported in libc++, according to the |
| 1136 | [library features table](https://en.cppreference.com/w/cpp/17) |
| 1137 | *** |
| 1138 | |
| 1139 | ### std::aligned_alloc <sup>[tbd]</sup> |
| 1140 | |
| 1141 | ```c++ |
| 1142 | int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024)); |
| 1143 | ``` |
| 1144 | |
| 1145 | **Description:** Allocates uninitialized storage with the specified alignment. |
| 1146 | |
| 1147 | **Documentation:** |
| 1148 | [std::aligned_alloc](https://en.cppreference.com/w/cpp/memory/c/aligned_alloc) |
| 1149 | |
| 1150 | **Notes:** |
| 1151 | *** promo |
| 1152 | None |
| 1153 | *** |
| 1154 | |
| 1155 | ### std::conjunction/std::disjunction/std::negation <sup>[tbd]</sup> |
| 1156 | |
| 1157 | ```c++ |
| 1158 | template<typename T, typename... Ts> |
| 1159 | std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>> |
| 1160 | func(T, Ts...) { ... |
| 1161 | ``` |
| 1162 | |
| 1163 | **Description:** Performs logical operations on type traits. |
| 1164 | |
| 1165 | **Documentation:** |
| 1166 | [std::conjunction](https://en.cppreference.com/w/cpp/types/conjunction), |
| 1167 | [std::disjunction](https://en.cppreference.com/w/cpp/types/disjunction), |
| 1168 | [std::negation](https://en.cppreference.com/w/cpp/types/negation) |
| 1169 | |
| 1170 | **Notes:** |
| 1171 | *** promo |
| 1172 | None |
| 1173 | *** |
| 1174 | |
Peter Kasting | 1865f277 | 2021-12-23 21:23:58 | [diff] [blame] | 1175 | ### std::is_swappable <sup>[tbd]</sup> |
| 1176 | |
| 1177 | ```c++ |
| 1178 | std::is_swappable<T> |
| 1179 | std::is_swappable_with_v<T, U> |
| 1180 | ``` |
| 1181 | |
| 1182 | **Description:** Checks whether classes may be swapped. |
| 1183 | |
| 1184 | **Documentation:** |
| 1185 | [std::is_swappable](https://en.cppreference.com/w/cpp/types/is_swappable) |
| 1186 | |
| 1187 | **Notes:** |
| 1188 | *** promo |
| 1189 | None |
| 1190 | *** |
| 1191 | |
| 1192 | ### std::is_invocable <sup>[tbd]</sup> |
| 1193 | |
| 1194 | ```c++ |
| 1195 | std::is_invocable_v<Fn, 1, "Hello"> |
| 1196 | ``` |
| 1197 | |
| 1198 | **Description:** Checks whether a function may be invoked with the given |
| 1199 | argument types. The `_r` variant also evaluates whether the result is |
| 1200 | convertible to a given type. |
| 1201 | |
| 1202 | **Documentation:** |
| 1203 | [std::is_invocable](https://en.cppreference.com/w/cpp/types/is_invocable) |
| 1204 | |
| 1205 | **Notes:** |
| 1206 | *** promo |
| 1207 | None |
| 1208 | *** |
| 1209 | |
| 1210 | ### std::is_aggregate <sup>[tbd]</sup> |
| 1211 | |
| 1212 | ```c++ |
| 1213 | if constexpr(std::is_aggregate_v<T>) { ... |
| 1214 | ``` |
| 1215 | |
| 1216 | **Description:** Checks wither the given type is an aggregate type. |
| 1217 | |
| 1218 | **Documentation:** |
| 1219 | [std::is_aggregate](https://en.cppreference.com/w/cpp/types/is_aggregate) |
| 1220 | |
| 1221 | **Notes:** |
| 1222 | *** promo |
| 1223 | None |
| 1224 | *** |
| 1225 | |
| 1226 | ### std::has_unique_object_representations <sup>[tbd]</sup> |
| 1227 | |
| 1228 | ```c++ |
| 1229 | std::has_unique_object_representations_v<foo> |
| 1230 | ``` |
| 1231 | |
| 1232 | **Description:** Checks wither the given type is trivially copyable and any two |
| 1233 | objects with the same value have the same object representation. |
| 1234 | |
| 1235 | **Documentation:** |
| 1236 | [std::has_unique_object_representations](https://en.cppreference.com/w/cpp/types/has_unique_object_representations) |
| 1237 | |
| 1238 | **Notes:** |
| 1239 | *** promo |
| 1240 | None |
| 1241 | *** |
| 1242 | |
| 1243 | ### std::clamp <sup>[tbd]</sup> |
| 1244 | |
| 1245 | ```c++ |
| 1246 | int x = base::clamp(inp, 0, 100); |
| 1247 | ``` |
| 1248 | |
| 1249 | **Description:** Clamps a value between a minimum and a maximum. |
| 1250 | |
| 1251 | **Documentation:** |
| 1252 | [std::clamp](https://en.cppreference.com/w/cpp/algorithm/clamp) |
| 1253 | |
| 1254 | **Notes:** |
| 1255 | *** promo |
| 1256 | See also `base::clamp`. |
| 1257 | *** |
| 1258 | |
| 1259 | ### std::reduce <sup>[tbd]</sup> |
| 1260 | |
| 1261 | ```c++ |
| 1262 | std::reduce(std::execution::par, v.cbegin(), v.cend()); |
| 1263 | ``` |
| 1264 | |
| 1265 | **Description:** Like `std::accumulate` except the elements of the range may be |
| 1266 | grouped and rearranged in arbitrary order. |
| 1267 | |
| 1268 | **Documentation:** |
| 1269 | [std::reduce](https://en.cppreference.com/w/cpp/algorithm/reduce) |
| 1270 | |
| 1271 | **Notes:** |
| 1272 | *** promo |
| 1273 | Makes the most sense in conjunction with `std::execution::par`. |
| 1274 | *** |
| 1275 | |
| 1276 | ### std::inclusive_scan <sup>[tbd]</sup> |
| 1277 | |
| 1278 | ```c++ |
| 1279 | std::inclusive_scan(data.begin(), data.end(), output.begin()); |
| 1280 | ``` |
| 1281 | |
| 1282 | **Description:** Like `std::accumulate` but writes the result at each step into |
| 1283 | the output range. |
| 1284 | |
| 1285 | **Documentation:** |
| 1286 | [std::inclusive_scan](https://en.cppreference.com/w/cpp/algorithm/inclusive_scan) |
| 1287 | |
| 1288 | **Notes:** |
| 1289 | *** promo |
| 1290 | None |
| 1291 | *** |
| 1292 | |
| 1293 | ### std::exclusive_scan <sup>[tbd]</sup> |
| 1294 | |
| 1295 | ```c++ |
| 1296 | std::exclusive_scan(data.begin(), data.end(), output.begin()); |
| 1297 | ``` |
| 1298 | |
| 1299 | **Description:** Like `std::inclusive_scan` but omits the current element from |
| 1300 | the written output at each step; that is, results are "one value behind" those |
| 1301 | of `std::inclusive_scan`. |
| 1302 | |
| 1303 | **Documentation:** |
| 1304 | [std::exclusive_scan](https://en.cppreference.com/w/cpp/algorithm/exclusive_scan) |
| 1305 | |
| 1306 | **Notes:** |
| 1307 | *** promo |
| 1308 | None |
| 1309 | *** |
| 1310 | |
| 1311 | ### std::gcd <sup>[tbd]</sup> |
| 1312 | |
| 1313 | ```c++ |
| 1314 | static_assert(std::gcd(12, 18) == 6); |
| 1315 | ``` |
| 1316 | |
| 1317 | **Description:** Computes the greatest common divisor of its arguments. |
| 1318 | |
| 1319 | **Documentation:** |
| 1320 | [std::gcd](https://en.cppreference.com/w/cpp/numeric/gcd) |
| 1321 | |
| 1322 | **Notes:** |
| 1323 | *** promo |
| 1324 | None |
| 1325 | *** |
| 1326 | |
| 1327 | ### std::lcm <sup>[tbd]</sup> |
| 1328 | |
| 1329 | ```c++ |
| 1330 | static_assert(std::lcm(12, 18) == 36); |
| 1331 | ``` |
| 1332 | |
| 1333 | **Description:** Computes the least common multiple of its arguments. |
| 1334 | |
| 1335 | **Documentation:** |
| 1336 | [std::lcm](https://en.cppreference.com/w/cpp/numeric/lcm) |
| 1337 | |
| 1338 | **Notes:** |
| 1339 | *** promo |
| 1340 | None |
| 1341 | *** |
| 1342 | |
| 1343 | ### std::map::try_emplace <sup>[tbd]</sup> |
| 1344 | |
| 1345 | ```c++ |
| 1346 | std::map<std::string, std::string> m; |
| 1347 | m.try_emplace("c", 10, 'c'); |
| 1348 | m.try_emplace("c", "Won't be inserted"); |
| 1349 | ``` |
| 1350 | |
| 1351 | **Description:** Like `emplace`, but does not move from rvalue arguments if the |
| 1352 | insertion does not happen. |
| 1353 | |
| 1354 | **Documentation:** |
| 1355 | [std::map::try_emplace](https://en.cppreference.com/w/cpp/container/map/try_emplace), |
| 1356 | |
| 1357 | **Notes:** |
| 1358 | *** promo |
| 1359 | Already available on `base::flat_map`. |
| 1360 | *** |
| 1361 | |
| 1362 | ### std::map::insert_or_assign <sup>[tbd]</sup> |
| 1363 | |
| 1364 | ```c++ |
| 1365 | std::map<std::string, std::string> m; |
| 1366 | m.insert_or_assign("c", "cherry"); |
| 1367 | m.insert_or_assign("c", "clementine"); |
| 1368 | ``` |
| 1369 | |
| 1370 | **Description:** Like `operator[]`, but returns more information and does not |
| 1371 | require default-constructibility of the mapped type. |
| 1372 | |
| 1373 | **Documentation:** |
| 1374 | [std::map::insert_or_assign](https://en.cppreference.com/w/cpp/container/map/insert_or_assign) |
| 1375 | |
| 1376 | **Notes:** |
| 1377 | *** promo |
| 1378 | Already available on `base::flat_map`. |
| 1379 | *** |
| 1380 | |
| 1381 | ### Non-member std::size/std::empty/std::data <sup>[tbd]</sup> |
| 1382 | |
| 1383 | ```c++ |
| 1384 | for (std::size_t i = 0; i < std::size(c); ++i) { ... |
| 1385 | if (!std::empty(c)) { ... |
| 1386 | std::strcpy(arr, std::data(str)); |
| 1387 | ``` |
| 1388 | |
| 1389 | **Description:** Non-member versions of what are normally member functions, for |
| 1390 | symmetrical use with things like arrays and initializer_lists. |
| 1391 | |
| 1392 | **Documentation:** |
| 1393 | [std::size](https://en.cppreference.com/w/cpp/iterator/size), |
| 1394 | [std::empty](https://en.cppreference.com/w/cpp/iterator/empty), |
| 1395 | [std::data](https://en.cppreference.com/w/cpp/iterator/data) |
| 1396 | |
| 1397 | **Notes:** |
| 1398 | *** promo |
| 1399 | See `base::size`, `base::empty`, and `base::data`. |
| 1400 | *** |
| 1401 | |
| 1402 | ### Mathematical special functions <sup>[tbd]</sup> |
| 1403 | |
| 1404 | ```c++ |
| 1405 | std::assoc_laguerre() |
| 1406 | std::assoc_legendre() |
| 1407 | std::beta() |
| 1408 | std::comp_ellint_1() |
| 1409 | std::comp_ellint_2() |
| 1410 | std::comp_ellint_3() |
| 1411 | std::cyl_bessel_i() |
| 1412 | std::cyl_bessel_j() |
| 1413 | std::cyl_bessel_k() |
| 1414 | std::cyl_neumann() |
| 1415 | std::ellint_1() |
| 1416 | std::ellint_2() |
| 1417 | std::ellint_3() |
| 1418 | std::expint() |
| 1419 | std::hermite() |
| 1420 | std::legendre() |
| 1421 | std::laguerre() |
| 1422 | std::riemann_zeta() |
| 1423 | std::sph_bessel() |
| 1424 | std::sph_legendre() |
| 1425 | std::sph_neumann() |
| 1426 | ``` |
| 1427 | |
| 1428 | **Description:** A variety of mathematical functions. |
| 1429 | |
| 1430 | **Documentation:** |
| 1431 | [Mathematical special functions](https://en.cppreference.com/w/cpp/numeric/special_functions) |
| 1432 | |
| 1433 | **Notes:** |
| 1434 | *** promo |
| 1435 | May not be supported in libc++, according to the |
| 1436 | [library features table](https://en.cppreference.com/w/cpp/17) |
| 1437 | *** |
| 1438 | |
| 1439 | ### 3D std::hypot <sup>[tbd]</sup> |
| 1440 | |
| 1441 | ```c++ |
| 1442 | double dist = std::hypot(1.0, 2.5, 3.7); |
| 1443 | ``` |
| 1444 | |
| 1445 | **Description:** Computes the distance from the origin in 3D space. |
| 1446 | |
| 1447 | **Documentation:** |
| 1448 | [std::hypot](https://en.cppreference.com/w/cpp/numeric/math/hypot) |
| 1449 | |
| 1450 | **Notes:** |
| 1451 | *** promo |
| 1452 | None |
| 1453 | *** |
| 1454 | |
| 1455 | ### Cache line interface <sup>[tbd]</sup> |
| 1456 | |
| 1457 | ```c++ |
| 1458 | alignas(std::hardware_destructive_interference_size) std::atomic<int> cat; |
| 1459 | static_assert(sizeof(S) <= std::hardware_constructive_interference_size); |
| 1460 | ``` |
| 1461 | |
| 1462 | **Description:** A portable way to access the L1 data cache line size. |
| 1463 | |
| 1464 | **Documentation:** |
| 1465 | [Hardware interference size](https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size) |
| 1466 | |
| 1467 | **Notes:** |
| 1468 | *** promo |
| 1469 | May not be supported in libc++, according to the |
| 1470 | [library features table](https://en.cppreference.com/w/cpp/17) |
| 1471 | *** |
| 1472 | |
| 1473 | ### std::launder <sup>[tbd]</sup> |
| 1474 | |
| 1475 | ```c++ |
| 1476 | struct Y { int z; }; |
| 1477 | alignas(Y) std::byte s[sizeof(Y)]; |
| 1478 | Y* q = new(&s) Y{2}; |
| 1479 | const int h = std::launder(reinterpret_cast<Y*>(&s))->z; |
| 1480 | ``` |
| 1481 | |
| 1482 | **Description:** When used to wrap a pointer, makes it valid to access the |
| 1483 | resulting object in cases it otherwise wouldn't have been, in a very limited set |
| 1484 | of circumstances. |
| 1485 | |
| 1486 | **Documentation:** |
| 1487 | [std::launder](https://en.cppreference.com/w/cpp/utility/launder) |
| 1488 | |
| 1489 | **Notes:** |
| 1490 | *** promo |
| 1491 | None |
| 1492 | *** |
| 1493 | |
| 1494 | ### std::to_chars/std::from_chars <sup>[tbd]</sup> |
| 1495 | |
| 1496 | ```c++ |
| 1497 | std::to_chars(str.data(), str.data() + str.size(), 42); |
| 1498 | std::from_chars(str.data(), str.data() + str.size(), result); |
| 1499 | ``` |
| 1500 | |
| 1501 | **Description:** Locale-independent, non-allocating, non-throwing functions to |
| 1502 | convert values to/from character strings, designed for use in high-throughput |
| 1503 | contexts. |
| 1504 | |
| 1505 | **Documentation:** |
| 1506 | [std::to_chars](https://en.cppreference.com/w/cpp/utility/to_chars), |
| 1507 | [std::from_chars](https://en.cppreference.com/w/cpp/utility/from_chars) |
| 1508 | |
| 1509 | **Notes:** |
| 1510 | *** promo |
| 1511 | None |
| 1512 | *** |
| 1513 | |
| 1514 | ### std::atomic<T>::is_always_lock_free <sup>[tbd]</sup> |
| 1515 | |
| 1516 | ```c++ |
| 1517 | template <typename T> |
| 1518 | struct is_lock_free_impl |
| 1519 | : std::integral_constant<bool, std::atomic<T>::is_always_lock_free> {}; |
| 1520 | ``` |
| 1521 | |
| 1522 | **Description:** True when the given atomic type is always lock-free. |
| 1523 | |
| 1524 | **Documentation:** |
| 1525 | [std::atomic<T>::is_always_lock_free](https://en.cppreference.com/w/cpp/atomic/atomic/is_always_lock_free) |
| 1526 | |
| 1527 | **Notes:** |
| 1528 | *** promo |
| 1529 | None |
| 1530 | *** |
| 1531 | |
| 1532 | ### std::scoped_lock <sup>[tbd]</sup> |
| 1533 | |
| 1534 | ```c++ |
| 1535 | std::scoped_lock lock(e1.m, e2.m); |
| 1536 | ``` |
| 1537 | |
| 1538 | **Description:** Provides an RAII-style mechanism for owning one or more mutexes |
| 1539 | for the duration of a scoped block. |
| 1540 | |
| 1541 | **Documentation:** |
| 1542 | [std::scoped_lock](https://en.cppreference.com/w/cpp/thread/scoped_lock) |
| 1543 | |
| 1544 | **Notes:** |
| 1545 | *** promo |
| 1546 | See also `base::AutoLock`. |
| 1547 | *** |
| 1548 | |
| 1549 | ### std::timespec_get <sup>[tbd]</sup> |
| 1550 | |
| 1551 | ```c++ |
| 1552 | std::timespec ts; |
| 1553 | std::timespec_get(&ts, TIME_UTC); |
| 1554 | ``` |
| 1555 | |
| 1556 | **Description:** Gets the current calendar time in the given time base. |
| 1557 | |
| 1558 | **Documentation:** |
| 1559 | [std::timespec_get](https://en.cppreference.com/w/cpp/chrono/c/timespec_get) |
| 1560 | |
| 1561 | **Notes:** |
| 1562 | *** promo |
| 1563 | None |
| 1564 | *** |
| 1565 | |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1566 | ## Abseil Allowed Library Features {#absl-allowlist} |
| 1567 | |
| 1568 | The following Abseil library features are allowed in the Chromium codebase. |
| 1569 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1570 | ### Optional <sup>[allowed]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1571 | |
| 1572 | ```c++ |
| 1573 | absl::optional |
| 1574 | ``` |
| 1575 | |
| 1576 | **Description:** Early adaptation of C++17 `std::optional`. |
| 1577 | |
| 1578 | **Documentation:** |
| 1579 | [std::optional](https://en.cppreference.com/w/cpp/utility/optional) |
| 1580 | |
| 1581 | **Notes:** |
| 1582 | *** promo |
| 1583 | Replaces `base::Optional`. |
| 1584 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/zUGqagX1NFU) |
| 1585 | *** |
| 1586 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1587 | ### Status <sup>[allowed]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1588 | |
| 1589 | ```c++ |
| 1590 | absl::Status |
| 1591 | ``` |
| 1592 | |
| 1593 | **Description:** Type for returning detailed errors. |
| 1594 | |
| 1595 | **Documentation:** |
| 1596 | [status.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/status.h) |
| 1597 | |
| 1598 | **Notes:** |
| 1599 | *** promo |
| 1600 | Approved for use inside a wrapper type. Use |
| 1601 | [abseil_string_conversions.h](https://source.chromium.org/chromium/chromium/src/+/main:base/strings/abseil_string_conversions.h) |
| 1602 | to convert to and from |
| 1603 | [absl::string_view](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/strings/string_view.h) |
| 1604 | so the wrapper can expose |
| 1605 | [base::StringPiece](https://source.chromium.org/chromium/chromium/src/+/main:base/strings/string_piece.h). |
| 1606 | Use |
| 1607 | [absl::Cord](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/strings/cord.h) |
| 1608 | directly as minimally necessary to interface; do not expose in the wrapper type |
| 1609 | API. |
| 1610 | |
| 1611 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ImdFCSZ-NMA) |
| 1612 | *** |
| 1613 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1614 | ### Variant <sup>[allowed]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1615 | |
| 1616 | ```c++ |
| 1617 | absl::variant |
| 1618 | ``` |
| 1619 | |
| 1620 | **Description:** Early adaptation of C++17 `std::variant`. |
| 1621 | |
| 1622 | **Documentation:** |
| 1623 | [std::variant](https://en.cppreference.com/w/cpp/utility/variant) |
| 1624 | |
| 1625 | **Notes:** |
| 1626 | *** promo |
| 1627 | [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/DqvG-TpvMyU) |
| 1628 | *** |
| 1629 | |
| 1630 | ## Abseil Banned Library Features {#absl-blocklist} |
| 1631 | |
| 1632 | The following Abseil library features are not allowed in the Chromium codebase. |
| 1633 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1634 | ### Any <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1635 | |
| 1636 | ```c++ |
| 1637 | absl::any a = int{5}; |
| 1638 | EXPECT_THAT(absl::any_cast<int>(&a), Pointee(5)); |
| 1639 | EXPECT_EQ(absl::any_cast<size_t>(&a), nullptr); |
| 1640 | ``` |
| 1641 | |
| 1642 | **Description:** Early adaptation of C++17 `std::any`. |
| 1643 | |
| 1644 | **Documentation:** [std::any](https://en.cppreference.com/w/cpp/utility/any) |
| 1645 | |
| 1646 | **Notes:** |
| 1647 | *** promo |
| 1648 | Banned since workaround for lack of RTTI isn't compatible with the component |
Daniel Cheng | c05fcc6 | 2022-01-12 16:54:29 | [diff] [blame] | 1649 | build ([Bug](https://crbug.com/1096380)). Also see `std::any`. |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1650 | *** |
| 1651 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1652 | ### Command line flags <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1653 | |
| 1654 | ```c++ |
| 1655 | ABSL_FLAG(bool, logs, false, "print logs to stderr"); |
| 1656 | app --logs=true; |
| 1657 | ``` |
| 1658 | |
| 1659 | **Description:** Allows programmatic access to flag values passed on the |
| 1660 | command-line to binaries. |
| 1661 | |
| 1662 | **Documentation:** [Flags Library](https://abseil.io/docs/cpp/guides/flags) |
| 1663 | |
| 1664 | **Notes:** |
| 1665 | *** promo |
| 1666 | Banned since workaround for lack of RTTI isn't compatible with the component |
| 1667 | build. ([Bug](https://crbug.com/1096380)) Use `base::CommandLine` instead. |
| 1668 | *** |
| 1669 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1670 | ### Span <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1671 | |
| 1672 | ```c++ |
| 1673 | absl::Span |
| 1674 | ``` |
| 1675 | |
| 1676 | **Description:** Early adaptation of C++20 `std::span`. |
| 1677 | |
| 1678 | **Documentation:** [Using absl::Span](https://abseil.io/tips/93) |
| 1679 | |
| 1680 | **Notes:** |
| 1681 | *** promo |
| 1682 | Banned due to being less std::-compliant than `base::span`. Keep using |
| 1683 | `base::span`. |
| 1684 | *** |
| 1685 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1686 | ### string_view <sup>[banned]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1687 | |
| 1688 | ```c++ |
| 1689 | absl::string_view |
| 1690 | ``` |
| 1691 | |
| 1692 | **Description:** Early adaptation of C++17 `std::string_view`. |
| 1693 | |
| 1694 | **Documentation:** [absl::string_view](https://abseil.io/tips/1) |
| 1695 | |
| 1696 | **Notes:** |
| 1697 | *** promo |
| 1698 | Banned due to only working with 8-bit characters. Keep using |
| 1699 | `base::StringPiece` from `base/strings/`. |
| 1700 | *** |
| 1701 | |
| 1702 | ## Abseil TBD Features {#absl-review} |
| 1703 | |
| 1704 | The following Abseil library features are not allowed in the Chromium codebase. |
| 1705 | See the top of this page on how to propose moving a feature from this list into |
| 1706 | the allowed or banned sections. |
| 1707 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1708 | ### 128bit integer <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1709 | |
| 1710 | ```c++ |
| 1711 | uint64_t a; |
| 1712 | absl::uint128 v = a; |
| 1713 | ``` |
| 1714 | |
| 1715 | **Description:** Signed and unsigned 128-bit integer types meant to mimic |
| 1716 | intrinsic types as closely as possible. |
| 1717 | |
| 1718 | **Documentation:** |
| 1719 | [Numerics](https://abseil.io/docs/cpp/guides/numeric) |
| 1720 | |
| 1721 | **Notes:** |
| 1722 | *** promo |
| 1723 | None |
| 1724 | *** |
| 1725 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1726 | ### bind_front <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1727 | |
| 1728 | ```c++ |
| 1729 | absl::bind_front |
| 1730 | ``` |
| 1731 | |
| 1732 | **Description:** Binds the first N arguments of an invocable object and stores them by value. |
| 1733 | |
| 1734 | **Documentation:** |
| 1735 | * [bind_front.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/bind_front.h) |
| 1736 | * [Avoid std::bind](https://abseil.io/tips/108) |
| 1737 | |
| 1738 | **Notes:** |
| 1739 | *** promo |
| 1740 | Overlaps with `base::Bind`. |
| 1741 | *** |
| 1742 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1743 | ### Cleanup <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1744 | |
| 1745 | ```c++ |
| 1746 | FILE* sink_file = fopen(sink_path, "w"); |
| 1747 | auto sink_closer = absl::MakeCleanup([sink_file] { fclose(sink_file); }); |
| 1748 | ``` |
| 1749 | |
| 1750 | **Description:** Implements the scope guard idiom, invoking the contained |
| 1751 | callback's `operator()() &&` on scope exit. |
| 1752 | |
| 1753 | **Documentation:** |
| 1754 | [cleanup.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/cleanup/cleanup.h) |
| 1755 | |
| 1756 | **Notes:** |
| 1757 | *** promo |
| 1758 | Similar to `defer` in Golang. |
| 1759 | *** |
| 1760 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1761 | ### Containers <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1762 | |
| 1763 | ```c++ |
| 1764 | absl::flat_hash_map |
| 1765 | absl::flat_hash_set |
| 1766 | absl::node_hash_map |
| 1767 | absl::node_hash_set |
| 1768 | absl::btree_map |
| 1769 | absl::btree_set |
| 1770 | absl::btree_multimap |
| 1771 | absl::btree_multiset |
| 1772 | absl::InlinedVector |
| 1773 | absl::FixedArray |
| 1774 | ``` |
| 1775 | |
| 1776 | **Description:** Alternatives to STL containers designed to be more efficient |
| 1777 | in the general case. |
| 1778 | |
| 1779 | **Documentation:** |
| 1780 | * [Containers](https://abseil.io/docs/cpp/guides/container) |
| 1781 | * [Hash](https://abseil.io/docs/cpp/guides/hash) |
| 1782 | |
| 1783 | **Notes:** |
| 1784 | *** promo |
| 1785 | Supplements `base/containers/`. |
| 1786 | *** |
| 1787 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1788 | ### Container utilities <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1789 | |
| 1790 | ```c++ |
| 1791 | auto it = absl::c_find(container, value); |
| 1792 | ``` |
| 1793 | |
| 1794 | **Description:** Container-based versions of algorithmic functions within C++ |
| 1795 | standard library. |
| 1796 | |
| 1797 | **Documentation:** |
| 1798 | [container.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/algorithm/container.h) |
| 1799 | |
| 1800 | **Notes:** |
| 1801 | *** promo |
| 1802 | Overlaps with `base/ranges/algorithm.h`. |
| 1803 | *** |
| 1804 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1805 | ### FunctionRef <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1806 | |
| 1807 | ```c++ |
| 1808 | absl::FunctionRef |
| 1809 | ``` |
| 1810 | |
| 1811 | **Description:** Type for holding a non-owning reference to an object of any |
| 1812 | invocable type. |
| 1813 | |
| 1814 | **Documentation:** |
| 1815 | [function_ref.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/function_ref.h) |
| 1816 | |
| 1817 | **Notes:** |
| 1818 | *** promo |
| 1819 | None |
| 1820 | *** |
| 1821 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1822 | ### Random <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1823 | |
| 1824 | ```c++ |
| 1825 | absl::BitGen bitgen; |
| 1826 | size_t index = absl::Uniform(bitgen, 0u, elems.size()); |
| 1827 | ``` |
| 1828 | |
| 1829 | **Description:** Functions and utilities for generating pseudorandom data. |
| 1830 | |
| 1831 | **Documentation:** [Random library](https://abseil.io/docs/cpp/guides/random) |
| 1832 | |
| 1833 | **Notes:** |
| 1834 | *** promo |
| 1835 | Overlaps with `base/rand_util.h`. |
| 1836 | *** |
| 1837 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1838 | ### StatusOr <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1839 | |
| 1840 | ```c++ |
| 1841 | absl::StatusOr<T> |
| 1842 | ``` |
| 1843 | |
| 1844 | **Description:** An object that is either a usable value, or an error Status |
| 1845 | explaining why such a value is not present. |
| 1846 | |
| 1847 | **Documentation:** |
| 1848 | [statusor.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/statusor.h) |
| 1849 | |
| 1850 | **Notes:** |
| 1851 | *** promo |
| 1852 | None |
| 1853 | *** |
| 1854 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1855 | ### String Formatting <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1856 | |
| 1857 | ```c++ |
| 1858 | absl::StrFormat |
| 1859 | ``` |
| 1860 | |
| 1861 | **Description:** A typesafe replacement for the family of printf() string |
| 1862 | formatting routines. |
| 1863 | |
| 1864 | **Documentation:** |
| 1865 | [String Formatting](https://abseil.io/docs/cpp/guides/format) |
| 1866 | |
| 1867 | **Notes:** |
| 1868 | *** promo |
| 1869 | None |
| 1870 | *** |
| 1871 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1872 | ### Strings Library <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1873 | |
| 1874 | ```c++ |
| 1875 | absl::StrSplit |
| 1876 | absl::StrJoin |
| 1877 | absl::StrCat |
| 1878 | absl::StrAppend |
| 1879 | absl::Substitute |
| 1880 | absl::StrContains |
| 1881 | ``` |
| 1882 | |
| 1883 | **Description:** Classes and utility functions for manipulating and comparing |
| 1884 | strings. |
| 1885 | |
| 1886 | **Documentation:** |
| 1887 | [String Utilities](https://abseil.io/docs/cpp/guides/strings) |
| 1888 | |
| 1889 | **Notes:** |
| 1890 | *** promo |
| 1891 | Overlaps with `base/strings`. |
| 1892 | *** |
| 1893 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1894 | ### Synchronization <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1895 | |
| 1896 | ```c++ |
| 1897 | absl::Mutex |
| 1898 | ``` |
| 1899 | |
| 1900 | **Description:** Primitives for managing tasks across different threads. |
| 1901 | |
| 1902 | **Documentation:** |
| 1903 | [Synchronization](https://abseil.io/docs/cpp/guides/synchronization) |
| 1904 | |
| 1905 | **Notes:** |
| 1906 | *** promo |
| 1907 | Overlaps with `Lock` in `base/synchronization/`. |
| 1908 | *** |
| 1909 | |
danakj | a6f71cb1 | 2021-12-15 21:04:49 | [diff] [blame] | 1910 | ### Time library <sup>[tbd]</sup> |
Joe Mason | fe4f256 | 2021-09-15 15:23:13 | [diff] [blame] | 1911 | |
| 1912 | ```c++ |
| 1913 | absl::Duration |
| 1914 | absl::Time |
| 1915 | absl::TimeZone |
| 1916 | absl::CivilDay |
| 1917 | ``` |
| 1918 | |
| 1919 | **Description:** Abstractions for holding time values, both in terms of |
| 1920 | absolute time and civil time. |
| 1921 | |
| 1922 | **Documentation:** [Time](https://abseil.io/docs/cpp/guides/time) |
| 1923 | |
| 1924 | **Notes:** |
| 1925 | *** promo |
| 1926 | Overlaps with `Time` APIs in `base/`. |
| 1927 | *** |