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