blob: e17e90153153ac775cf4d4a082ac720dd2cf3461 [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_
Peter Kasting4f35bfc2022-10-18 18:39:1237* **Abseil:** _Default allowed; see banned/TBD
38 features below_
Joe Masonfe4f2562021-09-15 15:23:1339 * absl::Cleanup: Initially supported February 4, 2021
Danil Chapovalova9f27032022-06-20 16:56:1440 * absl::AnyInvocable: Initially supported June 20, 2022
Danil Chapovalov6719fb12022-08-31 13:52:4941 * Log library: Initially supported Aug 31, 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
Peter Kastingd51bed72022-09-09 19:40:00686### std::apply <sup>[allowed]</sup>
687
688```c++
689static_assert(std::apply(std::plus<>(), std::make_tuple(1, 2)) == 3);
690```
691
692**Description:** Invokes a `Callable` object with a tuple of arguments.
693
694**Documentation:**
695[std::apply](https://en.cppreference.com/w/cpp/utility/apply)
696
697**Notes:**
698*** promo
699[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/cNZm_g39fyM)
700***
701
Lei Zhangaaf6fc22022-10-06 23:12:42702### std::as_const <sup>[allowed]</sup>
703
704```c++
705auto&& const_ref = std::as_const(mutable_obj);
706```
707
708**Description:** Forms reference to const T.
709
710**Documentation:**
711[std::as_const](https://en.cppreference.com/w/cpp/utility/as_const)
712
713**Notes:**
714*** promo
715[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/5Uo4iJK6Mf4)
716***
717
Daniel Cheng4ddc9202022-02-24 20:19:26718### Non-member std::size/std::empty/std::data <sup>[allowed]</sup>
719
720```c++
721char buffer[260];
722memcpy(std::data(buffer), source_str.data(), std::size(buffer));
723
724if (!std::empty(container)) { ... }
725```
726
727**Description:** Non-member versions of what are often member functions on STL
728containers. Primarily useful when:
729- using `std::size()` as a replacement for the old `arraysize()` macro.
730- writing code that needs to generically operate across things like
731 `std::vector` and `std::list` (which provide `size()`, `empty()`, and `data()
732 member functions), `std::array` and `std::initialize_list` (which only provide
733 a subset of the aforementioned member functions), and regular arrays (which
734 have no member functions at all).
735
736**Documentation:**
737[std::size](https://en.cppreference.com/w/cpp/iterator/size),
738[std::empty](https://en.cppreference.com/w/cpp/iterator/empty),
739[std::data](https://en.cppreference.com/w/cpp/iterator/data)
740
741**Notes:**
742*** promo
743[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/58qlA3zk5ZI/m/7kKok65xAAAJ)
744
745Prefer range-based for loops over `std::size()`: range-based for loops work even
746for regular arrays.
747***
748
Avi Drissman67c3b1e2022-04-27 20:42:49749### std::is_invocable <sup>[allowed]</sup>
750
751```c++
752std::is_invocable_v<Fn, 1, "Hello">
753```
754
755**Description:** Checks whether a function may be invoked with the given
756argument types. The `_r` variant also evaluates whether the result is
757convertible to a given type.
758
759**Documentation:**
760[std::is_invocable](https://en.cppreference.com/w/cpp/types/is_invocable)
761
762**Notes:**
763*** promo
764[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/YhlF_sTDSc0/m/QMzf42BtAAAJ)
765***
766
Avi Drissmanc109efd2022-04-27 22:03:35767### std::conjunction/std::disjunction/std::negation <sup>[allowed]</sup>
768
769```c++
770template<typename T, typename... Ts>
771std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>
772func(T, Ts...) { ...
773```
774
775**Description:** Performs logical operations on type traits.
776
777**Documentation:**
778[std::conjunction](https://en.cppreference.com/w/cpp/types/conjunction),
779[std::disjunction](https://en.cppreference.com/w/cpp/types/disjunction),
780[std::negation](https://en.cppreference.com/w/cpp/types/negation)
781
782**Notes:**
783*** promo
784[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/YhlF_sTDSc0/m/QMzf42BtAAAJ)
785***
786
Anton Bikineevc6a022582022-10-10 19:08:58787### std::hardware_{constructive|destructive}_interference_size <sup>[allowed]</sup>
788
789```c++
790struct SharedData {
791 ReadOnlyFrequentlyUsed data;
792 alignas(std::hardware_destructive_interference_size) std::atomic<size_t> counter;
793};
794```
795
796**Description:** The `std::hardware_destructive_interference_size` constant is
797useful to avoid false sharing (destructive interference) between variables that
798would otherwise occupy the same cacheline. In contrast,
799`std::hardware_constructive_interference_size` is helpful to promote true
800sharing (constructive interference), e.g. to support better locality for
801non-contended data.
802
803**Documentation:**
804[std::hardware_destructive_interference_size](https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size),
805[std::hardware_constructive_interference_size](https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size)
806
807**Notes:**
808*** promo
809[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/cwktrFxxUY4/m/sP-J-s61AQAJ)
810***
811
Peter Kasting1865f2772021-12-23 21:23:58812## C++17 Banned Library Features {#library-blocklist-17}
813
814The following C++17 library features are not allowed in the Chromium codebase.
815
Daniel Chengc05fcc62022-01-12 16:54:29816### std::any <sup>[banned]</sup>
817
818```c++
819std::any x = 5;
820```
821
822**Description:** A type-safe container for single values of any type.
823
824**Documentation:**
825[std::any](https://en.cppreference.com/w/cpp/utility/any)
826
827**Notes:**
828*** promo
829[Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/KEa-0AOGRNY/m/IV_S3_pvAAAJ)
830
831Banned since workaround for lack of RTTI isn't compatible with the component
832build ([Bug](https://crbug.com/1096380)). Also see `absl::any`.
833***
834
Peter Kasting1865f2772021-12-23 21:23:58835### std::filesystem <sup>[banned]</sup>
836
837```c++
838#include <filesystem>
839```
840
841**Description:** A standard way to manipulate files, directories, and paths in a
842filesystem.
843
844**Documentation:**
845[Filesystem library](https://en.cppreference.com/w/cpp/filesystem)
846
847**Notes:**
848*** promo
849Banned by the [Google Style Guide](https://google.github.io/styleguide/cppguide.html#Other_Features).
850***
851
852### weak_from_this <sup>[banned]</sup>
853
854```c++
855auto weak_ptr = weak_from_this();
856```
857
858**Description:** Returns a `std::weak_ptr<T>` that tracks ownership of `*this`
859by all existing `std::shared_ptr`s that refer to `*this`.
860
861**Documentation:**
862[std::enable_shared_from_this<T>::weak_from_this](https://en.cppreference.com/w/cpp/memory/enable_shared_from_this/weak_from_this)
863
864**Notes:**
865*** promo
866Banned since `std::shared_ptr` and `std::weak_ptr` are banned.
867***
868
869### Transparent std::owner_less <sup>[banned]</sup>
870
871```c++
872std::map<std::weak_ptr<T>, U, std::owner_less<>>
873```
874
875**Description:** Function object providing mixed-type owner-based ordering of
876shared and weak pointers, regardless of the type of the pointee.
877
878**Documentation:**
879[std::owner_less](https://en.cppreference.com/w/cpp/memory/owner_less)
880
881**Notes:**
882*** promo
883Banned since `std::shared_ptr` and `std::weak_ptr` are banned.
884***
885
886### Array support for std::shared_ptr <sup>[banned]</sup>
887
888```c++
889std::shared_ptr<int[]> p(new int[10]{0,1,2,3,4,5,6,7,8,9});
890std::cout << p[3]; // "3"
891```
892
893**Description:** Supports memory management of arrays via `std::shared_ptr`.
894
895**Documentation:**
896[std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr)
897
898**Notes:**
899*** promo
900Banned since `std::shared_ptr` is banned.
901***
902
903### std::uncaught_exceptions <sup>[banned]</sup>
904
905```c++
906int count = std::uncaught_exceptions();
907```
908
909**Description:** Determines whether there are live exception objects.
910
911**Documentation:**
912[std::uncaught_exceptions](https://en.cppreference.com/w/cpp/error/uncaught_exception)
913
914**Notes:**
915*** promo
916Banned because exceptions are banned.
917***
918
919### Rounding functions for duration and time_point <sup>[banned]</sup>
920
921```c++
922std::chrono::ceil<std::chrono::seconds>(dur);
923std::chrono::ceil<std::chrono::seconds>(time_pt);
924std::chrono::floor<std::chrono::seconds>(dur);
925std::chrono::floor<std::chrono::seconds>(time_pt);
926std::chrono::round<std::chrono::seconds>(dur);
927std::chrono::round<std::chrono::seconds>(time_pt);
928```
929
930**Description:** Converts durations and time_points by rounding.
931
932**Documentation:**
933[std::chrono::duration](https://en.cppreference.com/w/cpp/chrono/duration),
934[std::chrono::time_point](https://en.cppreference.com/w/cpp/chrono/time_point)
935
936**Notes:**
937*** promo
938Banned since `std::chrono` is banned.
939***
940
Avi Drissman37b7d512022-04-01 22:01:40941### std::variant <sup>[banned]</sup>
942
943```c++
944std::variant<int, double> v = 12;
945```
946
947**Description:** The class template `std::variant` represents a type-safe
948`union`. An instance of `std::variant` at any given time holds a value of one of
949its alternative types (it's also possible for it to be valueless).
950
951**Documentation:**
952[std::variant](https://en.cppreference.com/w/cpp/utility/variant)
953
954**Notes:**
955*** promo
956Banned for now because it does not provide safety guarantees in the case of
957misuse. The Chromium C++ team is investigating the possibility of hardening the
958C++ library so that the standard version can be used. In the meanwhile, use
959`absl::variant` instead.
960***
961
962### std::optional <sup>[banned]</sup>
963
964```c++
965std::optional<std::string> s;
966```
967
968**Description:** The class template `std::optional` manages an optional
969contained value, i.e. a value that may or may not be present. A common use case
970for optional is the return value of a function that may fail.
971
972**Documentation:**
973[std::optional](https://en.cppreference.com/w/cpp/utility/optional)
974
975**Notes:**
976*** promo
977Banned for now because it does not provide safety guarantees in the case of
978misuse. The Chromium C++ team is investigating the possibility of hardening the
979C++ library so that the standard version can be used. In the meanwhile, use
980`absl::optional` instead.
981***
982
Avi Drissmanbc6545f42022-05-03 17:47:38983### std::in_place/in_place_type/in_place_index/in_place_t/in_place_type_t/in_place_index_t <sup>[banned]</sup>
984
985```c++
986std::optional<std::complex<double>> opt{std::in_place, 0, 1};
987std::variant<int, float> v{std::in_place_type<int>, 1.4};
988```
989
990**Description:** The `std::in_place` are disambiguation tags for
991`std::optional`, `std::variant`, and `std::any` to indicate that the object
992should be constructed in-place.
993
994**Documentation:**
995[std::in_place](https://en.cppreference.com/w/cpp/utility/in_place)
996
997**Notes:**
998*** promo
999Banned for now because `std::optional`, `std::variant`, and `std::any` are all
1000banned for now. Because `absl::optional` and `absl::variant` are used instead,
1001and they require `absl::in_place`, use `absl::in_place` for non-Abseil Chromium
1002code. See the
1003[discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/ZspmuJPpv6s/m/wYYTCiRwAAAJ).
1004***
1005
Avi Drissman37b7d512022-04-01 22:01:401006### std::clamp <sup>[banned]</sup>
1007
1008```c++
1009int x = std::clamp(inp, 0, 100);
1010```
1011
1012**Description:** Clamps a value between a minimum and a maximum.
1013
1014**Documentation:**
1015[std::clamp](https://en.cppreference.com/w/cpp/algorithm/clamp)
1016
1017**Notes:**
1018*** promo
1019Banned for now because it does not provide safety guarantees in the case of
1020misuse. The Chromium C++ team is investigating the possibility of hardening the
1021C++ library so that the standard version can be used. In the meanwhile, use
1022`base::clamp` instead.
1023***
1024
Peter Kasting1865f2772021-12-23 21:23:581025## C++17 TBD Language Features {#core-review-17}
1026
1027The following C++17 language features are not allowed in the Chromium codebase.
1028See the top of this page on how to propose moving a feature from this list into
1029the allowed or banned sections.
1030
1031### Declaring non-type template parameters with auto <sup>[tbd]</sup>
1032
1033```c++
1034template <auto... seq>
1035struct my_integer_sequence {
1036 // ...
1037};
1038auto seq = my_integer_sequence<0, 1, 2>(); // Type deduced to be `int`.
1039```
1040
1041**Description:** Following the deduction rules of `auto`, while respecting the
1042non-type template parameter list of allowable types, template arguments can be
1043deduced from the types of its arguments.
1044
1045**Documentation:**
1046[Template parameters](https://en.cppreference.com/w/cpp/language/template_parameters)
1047
1048**Notes:**
1049*** promo
1050None
1051***
1052
Peter Kasting1865f2772021-12-23 21:23:581053### constexpr lambda <sup>[tbd]</sup>
1054
1055```c++
1056auto identity = [](int n) constexpr { return n; };
1057static_assert(identity(123) == 123);
1058```
1059
1060**Description:** Compile-time lambdas using constexpr.
1061
1062**Documentation:**
1063[Lambda expressions](https://en.cppreference.com/w/cpp/language/lambda)
1064
1065**Notes:**
1066*** promo
1067None
1068***
1069
1070### Lambda capture this by value <sup>[tbd]</sup>
1071
1072```c++
1073const auto l = [*this] { return member_; }
1074```
1075
1076**Description:** `*this` captures the current object by copy, while `this`
1077continues to capture by reference.
1078
1079**Documentation:**
1080[Lambda capture](https://en.cppreference.com/w/cpp/language/lambda#Lambda_capture)
1081
1082**Notes:**
1083*** promo
1084None
1085***
1086
Peter Kasting1865f2772021-12-23 21:23:581087### UTF-8 character literals <sup>[tbd]</sup>
1088
1089```c++
1090char x = u8'x';
1091```
1092
1093**Description:** A character literal that begins with `u8` is a character
1094literal of type `char`. The value of a UTF-8 character literal is equal to its
1095ISO 10646 code point value.
1096
1097**Documentation:**
1098[Character literal](https://en.cppreference.com/w/cpp/language/character_literal)
1099
1100**Notes:**
1101*** promo
1102C++20 changes the type to `char8_t`, causing migration hazards for code using
1103this.
1104***
1105
Peter Kasting1865f2772021-12-23 21:23:581106### using declaration for attributes <sup>[tbd]</sup>
1107
1108```c++
1109[[using CC: opt(1), debug]] // same as [[CC:opt(1), CC::debug]]
1110```
1111
1112**Description:** Specifies a common namespace for a list of attributes.
1113
1114**Documentation:**
1115[Attribute specifier sequence](https://en.cppreference.com/w/cpp/language/attributes)
1116
1117**Notes:**
1118*** promo
1119See similar attribute macros in base/compiler_specific.h.
1120***
1121
1122### __has_include <sup>[tbd]</sup>
1123
1124```c++
1125#if __has_include(<optional>) ...
1126```
1127
1128**Description:** Checks whether a file is available for inclusion, i.e. the file
1129exists.
1130
1131**Documentation:**
1132[Source file inclusion](https://en.cppreference.com/w/cpp/preprocessor/include)
1133
1134**Notes:**
1135*** promo
1136None
1137***
1138
1139## C++17 TBD Library Features {#library-review-17}
1140
1141The following C++17 library features are not allowed in the Chromium codebase.
1142See the top of this page on how to propose moving a feature from this list into
1143the allowed or banned sections.
1144
Peter Kasting1865f2772021-12-23 21:23:581145### std::string_view <sup>[tbd]</sup>
1146
1147```c++
1148std::string_view str = "foo";
1149```
1150
1151**Description:** A non-owning reference to a string. Useful for providing an
1152abstraction on top of strings (e.g. for parsing).
1153
1154**Documentation:**
1155[std::basic_string_view](https://en.cppreference.com/w/cpp/string/basic_string_view)
1156
1157**Notes:**
1158*** promo
1159See also `absl::string_view` and `base::StringPiece`.
1160***
1161
1162### std::invoke <sup>[tbd]</sup>
1163
1164```c++
1165static_assert(std::invoke(std::plus<>(), 1, 2) == 3);
1166```
1167
1168**Description:** Invokes a `Callable` object with parameters. An example of a
1169`Callable` object is `base::Callback` where an object can be called similarly to
1170a regular function.
1171
1172**Documentation:**
1173[std::invoke](https://en.cppreference.com/w/cpp/utility/functional/invoke)
1174
1175**Notes:**
1176*** promo
1177See also `base::invoke`.
1178***
1179
Peter Kasting1865f2772021-12-23 21:23:581180### std::byte <sup>[tbd]</sup>
1181
1182```c++
1183std::byte b = 0xFF;
1184int i = std::to_integer<int>(b); // 0xFF
1185```
1186
1187**Description:** A standard way of representing data as a byte. `std::byte` is
1188neither a character type nor an arithmetic type, and the only operator overloads
1189available are bitwise operations.
1190
1191**Documentation:**
1192[std::byte](https://en.cppreference.com/w/cpp/types/byte)
1193
1194**Notes:**
1195*** promo
1196None
1197***
1198
1199### Splicing for maps and sets <sup>[tbd]</sup>
1200
1201```c++
1202std::map<...>::extract
1203std::map<...>::merge
1204std::set<...>::extract
1205std::set<...>::merge
1206```
1207
1208**Description:** Moving nodes and merging containers without the overhead of
1209expensive copies, moves, or heap allocations/deallocations.
1210
1211**Documentation:**
1212[std::map::extract](https://en.cppreference.com/w/cpp/container/map/extract),
1213[std::map::merge](https://en.cppreference.com/w/cpp/container/map/merge)
1214
1215**Notes:**
1216*** promo
1217None
1218***
1219
1220### Parallel algorithms <sup>[tbd]</sup>
1221
1222```c++
1223auto it = std::find(std::execution::par, std::begin(vec), std::end(vec), 2);
1224```
1225
1226**Description:** Many of the STL algorithms, such as the `copy`, `find` and
1227`sort` methods, now support the parallel execution policies: `seq`, `par`, and
1228`par_unseq` which translate to "sequentially", "parallel" and
1229"parallel unsequenced".
1230
1231**Documentation:**
1232[execution_policy_tag_t](https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t)
1233
1234**Notes:**
1235*** promo
1236None
1237***
1238
1239### std::make_from_tuple <sup>[tbd]</sup>
1240
1241```c++
1242// Calls Foo(int, double):
1243auto foo = std::make_from_tuple<Foo>(std::make_tuple(1, 3.5));
1244```
1245
1246**Description:** Constructs an object from a tuple of arguments.
1247
1248**Documentation:**
1249[std::make_from_tuple](https://en.cppreference.com/w/cpp/utility/make_from_tuple)
1250
1251**Notes:**
1252*** promo
1253See also `absl::make_from_tuple`.
1254***
1255
1256### Searchers <sup>[tbd]</sup>
1257
1258```c++
1259auto it = std::search(haystack.begin(), haystack.end(),
1260 std::boyer_moore_searcher(needle.begin(), needle.end()));
1261```
1262
1263**Description:** Alternate string searching algorithms.
1264
1265**Documentation:**
1266[Searchers](https://en.cppreference.com/w/cpp/utility/functional#Searchers)
1267
1268**Notes:**
1269*** promo
1270None
1271***
1272
Peter Kasting1865f2772021-12-23 21:23:581273### std::not_fn <sup>[tbd]</sup>
1274
1275```c++
1276auto nonwhite = std::find_if(str.begin(), str.end(), std::not_fn(IsWhitespace));
1277```
1278
1279**Description:** Creates a forwarding call wrapper that returns the negation of
1280the callable object it holds.
1281
1282**Documentation:**
1283[std::not_fn](https://en.cppreference.com/w/cpp/utility/functional/not_fn)
1284
1285**Notes:**
1286*** promo
1287See also `base::not_fn`.
1288***
1289
1290### Uninitialized memory algorithms <sup>[tbd]</sup>
1291
1292```c++
1293std::destroy_at(ptr);
1294std::destroy(ptr, ptr + 8);
1295std::destroy_n(ptr, 8);
1296std::uninitialized_move(src.begin(), src.end(), dest.begin());
1297std::uninitialized_value_construct(std::begin(storage), std::end(storage));
1298```
1299
1300**Description:** Replaces direct constructor and destructor calls when manually
1301managing memory.
1302
1303**Documentation:**
1304[std::destroy_at](https://en.cppreference.com/w/cpp/memory/destroy_at),
1305[std::destroy](https://en.cppreference.com/w/cpp/memory/destroy),
1306[std::destroy_n](https://en.cppreference.com/w/cpp/memory/destroy_n),
1307[std::uninitialized_move](https://en.cppreference.com/w/cpp/memory/uninitialized_move),
1308[std::uninitialized_value_construct](https://en.cppreference.com/w/cpp/memory/uninitialized_value_construct)
1309
1310**Notes:**
1311*** promo
1312None
1313***
1314
1315### std::pmr::memory_resource and std::polymorphic_allocator <sup>[tbd]</sup>
1316
1317```c++
1318#include <memory_resource>
1319```
1320
1321**Description:** Manages memory allocations using runtime polymorphism.
1322
1323**Documentation:**
1324[std::pmr::memory_resource](https://en.cppreference.com/w/cpp/memory/memory_resource),
1325[std::pmr::polymorphic_allocator](https://en.cppreference.com/w/cpp/memory/polymorphic_allocator),
1326
1327**Notes:**
1328*** promo
1329May not be supported in libc++, according to the
1330[library features table](https://en.cppreference.com/w/cpp/17)
1331***
1332
1333### std::aligned_alloc <sup>[tbd]</sup>
1334
1335```c++
1336int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024));
1337```
1338
1339**Description:** Allocates uninitialized storage with the specified alignment.
1340
1341**Documentation:**
1342[std::aligned_alloc](https://en.cppreference.com/w/cpp/memory/c/aligned_alloc)
1343
1344**Notes:**
1345*** promo
1346None
1347***
1348
Peter Kasting1865f2772021-12-23 21:23:581349### std::is_swappable <sup>[tbd]</sup>
1350
1351```c++
1352std::is_swappable<T>
1353std::is_swappable_with_v<T, U>
1354```
1355
1356**Description:** Checks whether classes may be swapped.
1357
1358**Documentation:**
1359[std::is_swappable](https://en.cppreference.com/w/cpp/types/is_swappable)
1360
1361**Notes:**
1362*** promo
1363None
1364***
1365
Peter Kasting1865f2772021-12-23 21:23:581366### std::is_aggregate <sup>[tbd]</sup>
1367
1368```c++
1369if constexpr(std::is_aggregate_v<T>) { ...
1370```
1371
1372**Description:** Checks wither the given type is an aggregate type.
1373
1374**Documentation:**
1375[std::is_aggregate](https://en.cppreference.com/w/cpp/types/is_aggregate)
1376
1377**Notes:**
1378*** promo
1379None
1380***
1381
1382### std::has_unique_object_representations <sup>[tbd]</sup>
1383
1384```c++
1385std::has_unique_object_representations_v<foo>
1386```
1387
1388**Description:** Checks wither the given type is trivially copyable and any two
1389objects with the same value have the same object representation.
1390
1391**Documentation:**
1392[std::has_unique_object_representations](https://en.cppreference.com/w/cpp/types/has_unique_object_representations)
1393
1394**Notes:**
1395*** promo
1396None
1397***
1398
Peter Kasting1865f2772021-12-23 21:23:581399### std::reduce <sup>[tbd]</sup>
1400
1401```c++
1402std::reduce(std::execution::par, v.cbegin(), v.cend());
1403```
1404
1405**Description:** Like `std::accumulate` except the elements of the range may be
1406grouped and rearranged in arbitrary order.
1407
1408**Documentation:**
1409[std::reduce](https://en.cppreference.com/w/cpp/algorithm/reduce)
1410
1411**Notes:**
1412*** promo
1413Makes the most sense in conjunction with `std::execution::par`.
1414***
1415
1416### std::inclusive_scan <sup>[tbd]</sup>
1417
1418```c++
1419std::inclusive_scan(data.begin(), data.end(), output.begin());
1420```
1421
1422**Description:** Like `std::accumulate` but writes the result at each step into
1423the output range.
1424
1425**Documentation:**
1426[std::inclusive_scan](https://en.cppreference.com/w/cpp/algorithm/inclusive_scan)
1427
1428**Notes:**
1429*** promo
1430None
1431***
1432
1433### std::exclusive_scan <sup>[tbd]</sup>
1434
1435```c++
1436std::exclusive_scan(data.begin(), data.end(), output.begin());
1437```
1438
1439**Description:** Like `std::inclusive_scan` but omits the current element from
1440the written output at each step; that is, results are "one value behind" those
1441of `std::inclusive_scan`.
1442
1443**Documentation:**
1444[std::exclusive_scan](https://en.cppreference.com/w/cpp/algorithm/exclusive_scan)
1445
1446**Notes:**
1447*** promo
1448None
1449***
1450
1451### std::gcd <sup>[tbd]</sup>
1452
1453```c++
1454static_assert(std::gcd(12, 18) == 6);
1455```
1456
1457**Description:** Computes the greatest common divisor of its arguments.
1458
1459**Documentation:**
1460[std::gcd](https://en.cppreference.com/w/cpp/numeric/gcd)
1461
1462**Notes:**
1463*** promo
1464None
1465***
1466
1467### std::lcm <sup>[tbd]</sup>
1468
1469```c++
1470static_assert(std::lcm(12, 18) == 36);
1471```
1472
1473**Description:** Computes the least common multiple of its arguments.
1474
1475**Documentation:**
1476[std::lcm](https://en.cppreference.com/w/cpp/numeric/lcm)
1477
1478**Notes:**
1479*** promo
1480None
1481***
1482
Peter Kasting1865f2772021-12-23 21:23:581483### Mathematical special functions <sup>[tbd]</sup>
1484
1485```c++
1486std::assoc_laguerre()
1487std::assoc_legendre()
1488std::beta()
1489std::comp_ellint_1()
1490std::comp_ellint_2()
1491std::comp_ellint_3()
1492std::cyl_bessel_i()
1493std::cyl_bessel_j()
1494std::cyl_bessel_k()
1495std::cyl_neumann()
1496std::ellint_1()
1497std::ellint_2()
1498std::ellint_3()
1499std::expint()
1500std::hermite()
1501std::legendre()
1502std::laguerre()
1503std::riemann_zeta()
1504std::sph_bessel()
1505std::sph_legendre()
1506std::sph_neumann()
1507```
1508
1509**Description:** A variety of mathematical functions.
1510
1511**Documentation:**
1512[Mathematical special functions](https://en.cppreference.com/w/cpp/numeric/special_functions)
1513
1514**Notes:**
1515*** promo
1516May not be supported in libc++, according to the
1517[library features table](https://en.cppreference.com/w/cpp/17)
1518***
1519
1520### 3D std::hypot <sup>[tbd]</sup>
1521
1522```c++
1523double dist = std::hypot(1.0, 2.5, 3.7);
1524```
1525
1526**Description:** Computes the distance from the origin in 3D space.
1527
1528**Documentation:**
1529[std::hypot](https://en.cppreference.com/w/cpp/numeric/math/hypot)
1530
1531**Notes:**
1532*** promo
1533None
1534***
1535
Peter Kasting1865f2772021-12-23 21:23:581536### std::launder <sup>[tbd]</sup>
1537
1538```c++
1539struct Y { int z; };
1540alignas(Y) std::byte s[sizeof(Y)];
1541Y* q = new(&s) Y{2};
1542const int h = std::launder(reinterpret_cast<Y*>(&s))->z;
1543```
1544
1545**Description:** When used to wrap a pointer, makes it valid to access the
1546resulting object in cases it otherwise wouldn't have been, in a very limited set
1547of circumstances.
1548
1549**Documentation:**
1550[std::launder](https://en.cppreference.com/w/cpp/utility/launder)
1551
1552**Notes:**
1553*** promo
1554None
1555***
1556
1557### std::to_chars/std::from_chars <sup>[tbd]</sup>
1558
1559```c++
1560std::to_chars(str.data(), str.data() + str.size(), 42);
1561std::from_chars(str.data(), str.data() + str.size(), result);
1562```
1563
1564**Description:** Locale-independent, non-allocating, non-throwing functions to
1565convert values to/from character strings, designed for use in high-throughput
1566contexts.
1567
1568**Documentation:**
1569[std::to_chars](https://en.cppreference.com/w/cpp/utility/to_chars),
1570[std::from_chars](https://en.cppreference.com/w/cpp/utility/from_chars)
1571
1572**Notes:**
1573*** promo
1574None
1575***
1576
1577### std::atomic<T>::is_always_lock_free <sup>[tbd]</sup>
1578
1579```c++
1580template <typename T>
1581struct is_lock_free_impl
1582: std::integral_constant<bool, std::atomic<T>::is_always_lock_free> {};
1583```
1584
1585**Description:** True when the given atomic type is always lock-free.
1586
1587**Documentation:**
1588[std::atomic<T>::is_always_lock_free](https://en.cppreference.com/w/cpp/atomic/atomic/is_always_lock_free)
1589
1590**Notes:**
1591*** promo
1592None
1593***
1594
1595### std::scoped_lock <sup>[tbd]</sup>
1596
1597```c++
1598std::scoped_lock lock(e1.m, e2.m);
1599```
1600
1601**Description:** Provides an RAII-style mechanism for owning one or more mutexes
1602for the duration of a scoped block.
1603
1604**Documentation:**
1605[std::scoped_lock](https://en.cppreference.com/w/cpp/thread/scoped_lock)
1606
1607**Notes:**
1608*** promo
1609See also `base::AutoLock`.
1610***
1611
1612### std::timespec_get <sup>[tbd]</sup>
1613
1614```c++
1615std::timespec ts;
1616std::timespec_get(&ts, TIME_UTC);
1617```
1618
1619**Description:** Gets the current calendar time in the given time base.
1620
1621**Documentation:**
1622[std::timespec_get](https://en.cppreference.com/w/cpp/chrono/c/timespec_get)
1623
1624**Notes:**
1625*** promo
1626None
1627***
1628
Joe Masonfe4f2562021-09-15 15:23:131629## Abseil Banned Library Features {#absl-blocklist}
1630
1631The following Abseil library features are not allowed in the Chromium codebase.
1632
danakja6f71cb12021-12-15 21:04:491633### Any <sup>[banned]</sup>
Joe Masonfe4f2562021-09-15 15:23:131634
1635```c++
1636absl::any a = int{5};
1637EXPECT_THAT(absl::any_cast<int>(&a), Pointee(5));
1638EXPECT_EQ(absl::any_cast<size_t>(&a), nullptr);
1639```
1640
1641**Description:** Early adaptation of C++17 `std::any`.
1642
1643**Documentation:** [std::any](https://en.cppreference.com/w/cpp/utility/any)
1644
1645**Notes:**
1646*** promo
1647Banned since workaround for lack of RTTI isn't compatible with the component
Daniel Chengc05fcc62022-01-12 16:54:291648build ([Bug](https://crbug.com/1096380)). Also see `std::any`.
Joe Masonfe4f2562021-09-15 15:23:131649***
1650
Peter Kasting4f35bfc2022-10-18 18:39:121651### bind_front <sup>[banned]</sup>
1652
1653```c++
1654absl::bind_front
1655```
1656
1657**Description:** Binds the first N arguments of an invocable object and stores them by value.
1658
1659**Documentation:**
1660* [bind_front.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/bind_front.h)
1661* [Avoid std::bind](https://abseil.io/tips/108)
1662
1663**Notes:**
1664*** promo
1665Banned due to overlap with `base::Bind`. Use `base::Bind` instead.
1666***
1667
danakja6f71cb12021-12-15 21:04:491668### Command line flags <sup>[banned]</sup>
Joe Masonfe4f2562021-09-15 15:23:131669
1670```c++
1671ABSL_FLAG(bool, logs, false, "print logs to stderr");
1672app --logs=true;
1673```
1674
1675**Description:** Allows programmatic access to flag values passed on the
1676command-line to binaries.
1677
1678**Documentation:** [Flags Library](https://abseil.io/docs/cpp/guides/flags)
1679
1680**Notes:**
1681*** promo
1682Banned since workaround for lack of RTTI isn't compatible with the component
1683build. ([Bug](https://crbug.com/1096380)) Use `base::CommandLine` instead.
1684***
1685
Peter Kasting4f35bfc2022-10-18 18:39:121686### Container utilities <sup>[banned]</sup>
Joe Masonfe4f2562021-09-15 15:23:131687
1688```c++
Peter Kasting4f35bfc2022-10-18 18:39:121689auto it = absl::c_find(container, value);
Joe Masonfe4f2562021-09-15 15:23:131690```
1691
Peter Kasting4f35bfc2022-10-18 18:39:121692**Description:** Container-based versions of algorithmic functions within C++
1693standard library.
Joe Masonfe4f2562021-09-15 15:23:131694
Peter Kasting4f35bfc2022-10-18 18:39:121695**Documentation:**
1696[container.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/algorithm/container.h)
Joe Masonfe4f2562021-09-15 15:23:131697
1698**Notes:**
1699*** promo
Peter Kasting4f35bfc2022-10-18 18:39:121700Banned due to overlap with `base/ranges/algorithm.h`. Use the `base/ranges/`
1701facilities instead.
Joe Masonfe4f2562021-09-15 15:23:131702***
1703
Daniel Cheng2248b332022-07-27 06:16:591704### FunctionRef <sup>[banned]</sup>
1705
1706```c++
1707absl::FunctionRef
1708```
1709
1710**Description:** Type for holding a non-owning reference to an object of any
1711invocable type.
1712
1713**Documentation:**
1714[function_ref.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/function_ref.h)
1715
1716**Notes:**
1717*** promo
1718- `absl::FunctionRef` is banned due to allowing implicit conversions between
1719 function signatures in potentially surprising ways. For example, a callable
1720 with the signature `int()` will bind to `absl::FunctionRef<void()>`: the
1721 return value from the callable will be silently discarded.
1722- In Chromium, use `base::FunctionRef` instead.
1723- Unlike `base::OnceCallback` and `base::RepeatingCallback`, `base::FunctionRef`
1724 supports capturing lambdas.
1725- Useful when passing an invocable object to a function that synchronously calls
1726 the invocable object, e.g. `ForEachFrame(base::FunctionRef<void(Frame&)>)`.
1727 This can often result in clearer code than code that is templated to accept
1728 lambdas, e.g. with `template <typename Invocable> void
1729 ForEachFrame(Invocable invocable)`, it is much less obvious what arguments
1730 will be passed to `invocable`.
1731- For now, `base::OnceCallback` and `base::RepeatingCallback` intentionally
1732 disallow conversions to `base::FunctionRef`, under the theory that the
1733 callback should be a capturing lambda instead. Attempting to use this
1734 conversion will trigger a `static_assert` requesting additional feedback for
1735 use cases where this conversion would be valuable.
1736- *Important:* `base::FunctionRef` must not outlive the function call. Like
1737 `base::StringPiece`, `base::FunctionRef` is a *non-owning* reference. Using a
1738 `base::FunctionRef` as a return value or class field is dangerous and likely
1739 to result in lifetime bugs.
1740- [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JVN4E4IIYA0/m/V0EVUVLiBwAJ)
1741***
1742
Peter Kasting4f35bfc2022-10-18 18:39:121743### Random <sup>[banned]</sup>
1744
1745```c++
1746absl::BitGen bitgen;
1747size_t index = absl::Uniform(bitgen, 0u, elems.size());
1748```
1749
1750**Description:** Functions and utilities for generating pseudorandom data.
1751
1752**Documentation:** [Random library](https://abseil.io/docs/cpp/guides/random)
1753
1754**Notes:**
1755*** promo
1756Banned because most uses of random values in Chromium should be using a
1757cryptographically secure generator. Use `base/rand_util.h` instead.
1758***
1759
1760### Span <sup>[banned]</sup>
1761
1762```c++
1763absl::Span
1764```
1765
1766**Description:** Early adaptation of C++20 `std::span`.
1767
1768**Documentation:** [Using absl::Span](https://abseil.io/tips/93)
1769
1770**Notes:**
1771*** promo
1772Banned due to being less std::-compliant than `base::span`. Keep using
1773`base::span`.
1774***
1775
1776### StatusOr <sup>[banned]</sup>
1777
1778```c++
1779absl::StatusOr<T>
1780```
1781
1782**Description:** An object that is either a usable value, or an error Status
1783explaining why such a value is not present.
1784
1785**Documentation:**
1786[statusor.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/status/statusor.h)
1787
1788**Notes:**
1789*** promo
1790Banned due to overlap with `base::expected`. Use `base::expected` instead.
1791***
1792
1793### String Formatting <sup>[banned]</sup>
1794
1795```c++
1796absl::StrFormat
1797```
1798
1799**Description:** A typesafe replacement for the family of printf() string
1800formatting routines.
1801
1802**Documentation:**
1803[String Formatting](https://abseil.io/docs/cpp/guides/format)
1804
1805**Notes:**
1806*** promo
1807Banned for now due to overlap with `base::StringPrintf()`. See
1808[migration bug](https://bugs.chromium.org/p/chromium/issues/detail?id=1371963).
1809***
1810
1811### string_view <sup>[banned]</sup>
1812
1813```c++
1814absl::string_view
1815```
1816
1817**Description:** Early adaptation of C++17 `std::string_view`.
1818
1819**Documentation:** [absl::string_view](https://abseil.io/tips/1)
1820
1821**Notes:**
1822*** promo
1823Banned due to only working with 8-bit characters. Keep using
1824`base::StringPiece` from `base/strings/`.
1825***
1826
1827### Strings Library <sup>[banned]</sup>
1828
1829```c++
1830absl::StrSplit
1831absl::StrJoin
1832absl::StrCat
1833absl::StrAppend
1834absl::Substitute
1835absl::StrContains
1836```
1837
1838**Description:** Classes and utility functions for manipulating and comparing
1839strings.
1840
1841**Documentation:**
1842[String Utilities](https://abseil.io/docs/cpp/guides/strings)
1843
1844**Notes:**
1845*** promo
1846Banned for now due to overlap with `base/strings`. We
1847[should re-evalute](https://bugs.chromium.org/p/chromium/issues/detail?id=1371966)
1848when we've
1849[migrated](https://bugs.chromium.org/p/chromium/issues/detail?id=691162) from
1850`base::StringPiece` to `std::string_view`.
1851***
1852
1853### Synchronization <sup>[banned]</sup>
1854
1855```c++
1856absl::Mutex
1857```
1858
1859**Description:** Primitives for managing tasks across different threads.
1860
1861**Documentation:**
1862[Synchronization](https://abseil.io/docs/cpp/guides/synchronization)
1863
1864**Notes:**
1865*** promo
1866Banned due to overlap with `base/synchronization/`. We would love
1867[more testing](https://bugs.chromium.org/p/chromium/issues/detail?id=1371969) on
1868whether there are compelling reasons to prefer base, absl, or std
1869synchronization primitives; for now, use `base/synchronization/`.
1870***
1871
1872### Time library <sup>[banned]</sup>
1873
1874```c++
1875absl::Duration
1876absl::Time
1877absl::TimeZone
1878absl::CivilDay
1879```
1880
1881**Description:** Abstractions for holding time values, both in terms of
1882absolute time and civil time.
1883
1884**Documentation:** [Time](https://abseil.io/docs/cpp/guides/time)
1885
1886**Notes:**
1887*** promo
1888Banned due to overlap with `base/time/`. Use `base/time/` instead.
1889***
1890
Joe Masonfe4f2562021-09-15 15:23:131891## Abseil TBD Features {#absl-review}
1892
1893The following Abseil library features are not allowed in the Chromium codebase.
1894See the top of this page on how to propose moving a feature from this list into
1895the allowed or banned sections.
1896
Danil Chapovalova9f27032022-06-20 16:56:141897### AnyInvocable <sup>[tbd]</sup>
1898
1899```c++
1900absl::AnyInvocable
1901```
1902
1903**Description:** An equivalent of the C++23 std::move_only_function.
1904
1905**Documentation:**
1906* [any_invocable.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/functional/any_invocable.h)
1907* [std::move_only_function](https://en.cppreference.com/w/cpp/utility/functional/move_only_function/move_only_function)
1908
1909**Notes:**
1910*** promo
1911Overlaps with `base::RepeatingCallback`, `base::OnceCallback`.
1912***
1913
danakja6f71cb12021-12-15 21:04:491914### Cleanup <sup>[tbd]</sup>
Joe Masonfe4f2562021-09-15 15:23:131915
1916```c++
1917FILE* sink_file = fopen(sink_path, "w");
1918auto sink_closer = absl::MakeCleanup([sink_file] { fclose(sink_file); });
1919```
1920
1921**Description:** Implements the scope guard idiom, invoking the contained
1922callback's `operator()() &&` on scope exit.
1923
1924**Documentation:**
1925[cleanup.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/cleanup/cleanup.h)
1926
1927**Notes:**
1928*** promo
1929Similar to `defer` in Golang.
1930***
1931
danakja6f71cb12021-12-15 21:04:491932### Containers <sup>[tbd]</sup>
Joe Masonfe4f2562021-09-15 15:23:131933
1934```c++
1935absl::flat_hash_map
1936absl::flat_hash_set
1937absl::node_hash_map
1938absl::node_hash_set
1939absl::btree_map
1940absl::btree_set
1941absl::btree_multimap
1942absl::btree_multiset
1943absl::InlinedVector
1944absl::FixedArray
1945```
1946
1947**Description:** Alternatives to STL containers designed to be more efficient
1948in the general case.
1949
1950**Documentation:**
1951* [Containers](https://abseil.io/docs/cpp/guides/container)
1952* [Hash](https://abseil.io/docs/cpp/guides/hash)
1953
1954**Notes:**
1955*** promo
1956Supplements `base/containers/`.
1957***
1958
Peter Kasting4f35bfc2022-10-18 18:39:121959### Log macros and related classes <sup>[tbd]</sup>
Danil Chapovalov6719fb12022-08-31 13:52:491960
1961```c++
1962LOG(INFO) << message;
1963CHECK(condition);
1964absl::AddLogSink(&custom_sink_to_capture_absl_logs);
1965```
1966
1967**Description:** Macros and related classes to perform debug loggings
1968
1969**Documentation:**
1970[log.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/log.h)
1971[check.h](https://source.chromium.org/chromium/chromium/src/+/main:third_party/abseil-cpp/absl/check.h)
1972
1973**Notes:**
1974*** promo
1975Overlaps and uses same macros names as `base/logging.h`.
1976***