Modern C++ use in Chromium
Modern C++ use in Chromium
This document is part of the more general Chromium C++ style guide. It summarizes the supported state of new and updated language and library features in recent C++ standards and the Abseil library. This guide applies to both Chromium and its subprojects, though subprojects can choose to be more restrictive if necessary for toolchain support.
The C++ language has in recent years received an updated standard every three years (C++11, C++14, etc.). For various reasons, Chromium does not immediately allow new features on the publication of such a standard. Instead, once toolchain support is sufficient, a standard is declared “initially supported”, with new language/library features banned pending discussion.
You can propose changing the status of a feature by sending an email to cxx@chromium.org. Include a short blurb on what the feature is and why you think it should or should not be allowed, along with links to any relevant previous discussion. If the list arrives at some consensus, send a codereview to change this file accordingly, linking to your discussion thread.
If an item remains on the TBD list two years after initial support is added, style arbiters should explicitly move it to an appropriate allowlist or blocklist, allowing it if there are no obvious reasons to ban.
The current status of existing standards and Abseil features is:
- C++11: Default allowed; see banned features below
- C++14: Default allowed; see banned features below
- C++17: Initially supported December 23, 2021; see allowed/banned/TBD features below
- C++20: Not yet supported in Chromium
- C++23: Not yet standardized
- Abseil: Initially supported July 31, 2020; see allowed/banned/TBD features below
- absl::StatusOr: Initially supported September 3, 2020
- absl::Cleanup: Initially supported February 4, 2021
Contents
- C++11 Banned Language Features
- Inline Namespaces [banned]
- long long Type [banned]
- User-Defined Literals [banned]
- thread_local Storage Class [banned]
- C++11 Banned Library Features
- Bind Operations [banned]
- C Floating-Point Environment [banned]
- Date and time utilities [banned]
- Exceptions [banned]
- Function Objects [banned]
- Random Number Engines [banned]
- Ratio Template Class [banned]
- Regular Expressions [banned]
- Shared Pointers [banned]
- String-Number Conversion Functions [banned]
- Thread Library [banned]
- Weak Pointers [banned]
- C++14 Banned Library Features
- C++17 Allowed Language Features
- Nested namespaces [allowed]
- Template argument deduction for class templates [allowed]
- Selection statements with initializer [allowed]
- fallthrough attribute [allowed]
- constexpr if [allowed]
- nodiscard attribute [allowed]
- maybe_unused attribute [allowed]
- Structured bindings [allowed]
- Inline variables
- C++17 Allowed Library Features
- Allocation functions with explicit alignment [allowed]
- Type trait variable templates [tbd]
- std::map::try_emplace [allowed]
- std::map::insert_or_assign [allowed]
- C++17 Banned Library Features
- std::any [banned]
- std::filesystem [banned]
- weak_from_this [banned]
- Transparent std::owner_less [banned]
- Array support for std::shared_ptr [banned]
- std::uncaught_exceptions [banned]
- Rounding functions for duration and time_point [banned]
- C++17 TBD Language Features
- Declaring non-type template parameters with auto [tbd]
- Fold expressions [tbd]
- constexpr lambda [tbd]
- Lambda capture this by value [tbd]
- UTF-8 character literals [tbd]
- using declaration for attributes [tbd]
- __has_include [tbd]
- C++17 TBD Library Features
- std::variant [tbd]
- std::optional [tbd]
- std::string_view [tbd]
- std::invoke [tbd]
- std::apply [tbd]
- std::byte [tbd]
- Splicing for maps and sets [tbd]
- Parallel algorithms [tbd]
- std::make_from_tuple [tbd]
- Searchers [tbd]
- std::as_const [tbd]
- std::not_fn [tbd]
- Uninitialized memory algorithms [tbd]
- std::pmr::memory_resource and std::polymorphic_allocator [tbd]
- std::aligned_alloc [tbd]
- std::conjunction/std::disjunction/std::negation [tbd]
- std::is_swappable [tbd]
- std::is_invocable [tbd]
- std::is_aggregate [tbd]
- std::has_unique_object_representations [tbd]
- std::clamp [tbd]
- std::reduce [tbd]
- std::inclusive_scan [tbd]
- std::exclusive_scan [tbd]
- std::gcd [tbd]
- std::lcm [tbd]
- Non-member std::size/std::empty/std::data [tbd]
- Mathematical special functions [tbd]
- 3D std::hypot [tbd]
- Cache line interface [tbd]
- std::launder [tbd]
- std::to_chars/std::from_chars [tbd]
- std::atomic::is_always_lock_free [tbd]
- std::scoped_lock [tbd]
- std::timespec_get [tbd]
- Abseil Allowed Library Features
- Abseil Banned Library Features
- Abseil TBD Features
C++11 Banned Language Features
The following C++11 language features are not allowed in the Chromium codebase.
Inline Namespaces [banned]
inline namespace foo { ... }
Description: Allows better versioning of namespaces.
Documentation: Inline namespaces
Notes:
long long Type [banned]
long long var = value;
Description: An integer of at least 64 bits.
Documentation: Fundamental types
Notes:
User-Defined Literals [banned]
type var = literal_value_type;
Description: Allows user-defined literal expressions.
Documentation: User-defined literals
Notes:
thread_local Storage Class [banned]
thread_local int foo = 1;
Description: Puts variables into thread local storage.
Documentation: Storage duration
Notes:
base::SequenceLocalStorageSlot
for sequence support, and base::ThreadLocal
/base::ThreadLocalStorage
otherwise.C++11 Banned Library Features
The following C++11 library features are not allowed in the Chromium codebase.
Bind Operations [banned]
std::bind(function, args, ...)
Description: Declares a function object bound to certain arguments
Documentation: std::bind
Notes:
base::Bind
instead. Compared to std::bind
, base::Bind
helps prevent lifetime issues by preventing binding of capturing lambdas and by forcing callers to declare raw pointers as Unretained
. Discussion threadC Floating-Point Environment [banned]
#include <cfenv>
#include <fenv.h>
Description: Provides floating point status flags and control modes for C-compatible code
Documentation: Standard library header “cfenv”
Notes:
Date and time utilities [banned]
#include <chrono>
Description: A standard date and time library
Documentation: Date and time utilities
Notes:
Time
APIs in base/
. Keep using the base/
classes.Exceptions [banned]
#include <exception>
Description: Enhancements to exception throwing and handling
Documentation: Standard library header “exception”
Notes:
noexcept
specifier is explicitly allowed. Discussion threadFunction Objects [banned]
std::function
Description: Wraps a standard polymorphic function
Documentation: std::function
Notes:
base::{Once,Repeating}Callback
instead. Compared to std::function
, base::{Once,Repeating}Callback
directly supports Chromium's refcounting classes and weak pointers and deals with additional thread safety concerns. Discussion threadRandom Number Engines [banned]
<random>
(see separate item for random number distributions), e.g.: linear_congruential_engine
, mersenne_twister_engine
, minstd_rand0
, mt19937
, ranlinux48
, random_device
Description: Random number generation algorithms and utilities.
Documentation: Pseudo-random number generation
Notes:
<random>
. Instead, use base::RandomBitGenerator
. Discussion threadRatio Template Class [banned]
std::ratio<numerator, denominator>
Description: Provides compile-time rational numbers
Documentation: std::ratio
Notes:
Regular Expressions [banned]
#include <regex>
Description: A standard regular expressions library
Documentation: Regular expressions library
Notes:
re2
.Shared Pointers [banned]
std::shared_ptr
Description: Allows shared ownership of a pointer through reference counts
Documentation: std::shared_ptr
Notes:
Needs a lot more evaluation for Chromium, and there isn't enough of a push for this feature.
String-Number Conversion Functions [banned]
std::stoi()
std::stol()
std::stoul()
std::stoll
std::stoull()
std::stof()
std::stod()
std::stold()
std::to_string()
Description: Converts strings to/from numbers
Documentation:
- std::stoi, std::stol, std::stoll,
- std::stoul, std::stoull,
- std::stof, std::stod, std::stold,
- std::to_string
Notes:
base/strings/string_number_conversions.h
instead.Thread Library [banned]
<thread>
and related headers, including <future>
, <mutex>
, <condition_variable>
Description: Provides a standard multithreading library using std::thread
and associates
Documentation: Thread support library
Notes:
base/
. Keep using the base/
classes for now. base::Thread
is tightly coupled to MessageLoop
which would make it hard to replace. We should investigate using standard mutexes, or unique_lock, etc. to replace our locking/synchronization classes.Weak Pointers [banned]
std::weak_ptr
Description: Allows a weak reference to a std::shared_ptr
Documentation: std::weak_ptr
Notes:
std::shared_ptr
is banned. Use base::WeakPtr
instead.C++14 Banned Library Features
The following C++14 library features are not allowed in the Chromium codebase.
std::chrono literals [banned]
using namespace std::chrono_literals;
auto timeout = 30s;
Description: Allows std::chrono
types to be more easily constructed.
Documentation: std::literals::chrono_literals::operator""s
Notes:
<chrono>
is banned.C++17 Allowed Language Features
The following C++17 language features are allowed in the Chromium codebase.
Nested namespaces [allowed]
namespace A::B::C { ...
Description: Using the namespace resolution operator to create nested namespace definitions.
Documentation: Namespaces
Notes:
Template argument deduction for class templates [allowed]
template <typename T>
struct MyContainer {
MyContainer(T val) : val{val} {}
// ...
};
MyContainer c1(1); // Type deduced to be `int`.
Description: Automatic template argument deduction much like how it's done for functions, but now including class constructors.
Documentation: Class template argument deduction
Notes:
Selection statements with initializer [allowed]
if (int a = Func(); a < 3) { ...
switch (int a = Func(); a) { ...
Description: New versions of the if and switch statements which simplify common code patterns and help users keep scopes tight.
Documentation: if statement, switch statement
Notes:
fallthrough attribute [allowed]
case 1:
DoSomething();
[[fallthrough]];
case 2:
break;
Description: The [[fallthrough]]
attribute can be used in switch statements to indicate when intentionally falling through to the next case.
Documentation: C++ attribute: fallthrough
Notes:
See discussion thread.
See migration task.
constexpr if [allowed]
if constexpr (cond) { ...
Description: Write code that is instantiated depending on a compile-time condition.
Documentation: if statement
Notes:
nodiscard attribute [allowed]
struct [[nodiscard]] ErrorOrValue;
[[nodiscard]] bool DoSomething();
Description: The [[nodiscard]]
attribute can be used to indicate that
- the return value of a function should not be ignored
- values of annotated classes/structs/enums returned from functions should not be ignored
Documentation: C++ attribute: nodiscard
Notes:
maybe_unused attribute [allowed]
struct [[maybe_unused]] MyUnusedThing;
[[maybe_unused]] int x;
Description: The [[maybe_unused]]
attribute can be used to indicate that individual variables, functions, or fields of a class/struct/enum can be left unused.
Documentation: C++ attribute: maybe_unused
Notes:
Structured bindings [allowed]
const auto [x, y] = FuncReturningStdPair();
Description: Allows writing auto [x, y, z] = expr;
where the type of expr
is a tuple-like object, whose elements are bound to the variables x
, y
, and z
(which this construct declares). Tuple-like objects include std::tuple
, std::pair
, std::array
, and aggregate structures.
Documentation: Structured binding declaration Explanation of structured binding types
Notes:
In C++17, structured bindings don't work with lambda captures. C++20 will allow capturing structured bindings by value.
This feature forces omitting type names. Its use should follow the guidance around auto
in Google C++ Style guide.
See discussion thread.
Inline variables
struct S {
static constexpr int kZero = 0; // constexpr implies inline here.
};
inline constexpr int kOne = 1; // Explicit inline needed here.
Description: The inline
specifier can be applied to variables as well as to functions. A variable declared inline has the same semantics as a function declared inline. It can also be used to declare and define a static member variable, such that it does not need to be initialized in the source file.
Documentation: inline specifier
Notes:
Inline variables in anonymous namespaces in header files will still get one copy per translation unit, so they must be outside of an anonymous namespace to be effective.
Mutable inline variables and taking the address of inline variables are banned since these will break the component build.
See discussion thread.
C++17 Allowed Library Features
The following C++17 language features are allowed in the Chromium codebase.
Allocation functions with explicit alignment [allowed]
class alignas(32) Vec3d {
double x, y, z;
};
auto p_vec = new Vec3d[10]; // 32-byte aligned in C++17, maybe not previously
Description: Performs heap allocation of objects whose alignment requirements exceed __STDCPP_DEFAULT_NEW_ALIGNMENT__
.
Documentation: operator new
Notes:
Type trait variable templates [tbd]
bool b = std::is_same_v<int, std::int32_t>;
Description: Syntactic sugar to provide convenient access to ::value
members by simply adding _v
.
Documentation: Type support
Notes:
std::map::try_emplace [allowed]
std::map<std::string, std::string> m;
m.try_emplace("c", 10, 'c');
m.try_emplace("c", "Won't be inserted");
Description: Like emplace
, but does not move from rvalue arguments if the insertion does not happen.
Documentation: std::map::try_emplace,
Notes:
std::map::insert_or_assign [allowed]
std::map<std::string, std::string> m;
m.insert_or_assign("c", "cherry");
m.insert_or_assign("c", "clementine");
Description: Like operator[]
, but returns more information and does not require default-constructibility of the mapped type.
Documentation: std::map::insert_or_assign
Notes:
C++17 Banned Library Features
The following C++17 library features are not allowed in the Chromium codebase.
std::any [banned]
std::any x = 5;
Description: A type-safe container for single values of any type.
Documentation: std::any
Notes:
Banned since workaround for lack of RTTI isn't compatible with the component build (Bug). Also see absl::any
.
std::filesystem [banned]
#include <filesystem>
Description: A standard way to manipulate files, directories, and paths in a filesystem.
Documentation: Filesystem library
Notes:
weak_from_this [banned]
auto weak_ptr = weak_from_this();
Description: Returns a std::weak_ptr<T>
that tracks ownership of *this
by all existing std::shared_ptr
s that refer to *this
.
Documentation: std::enable_shared_from_this::weak_from_this
Notes:
std::shared_ptr
and std::weak_ptr
are banned.Transparent std::owner_less [banned]
std::map<std::weak_ptr<T>, U, std::owner_less<>>
Description: Function object providing mixed-type owner-based ordering of shared and weak pointers, regardless of the type of the pointee.
Documentation: std::owner_less
Notes:
std::shared_ptr
and std::weak_ptr
are banned.Array support for std::shared_ptr [banned]
std::shared_ptr<int[]> p(new int[10]{0,1,2,3,4,5,6,7,8,9});
std::cout << p[3]; // "3"
Description: Supports memory management of arrays via std::shared_ptr
.
Documentation: std::shared_ptr
Notes:
std::shared_ptr
is banned.std::uncaught_exceptions [banned]
int count = std::uncaught_exceptions();
Description: Determines whether there are live exception objects.
Documentation: std::uncaught_exceptions
Notes:
Rounding functions for duration and time_point [banned]
std::chrono::ceil<std::chrono::seconds>(dur);
std::chrono::ceil<std::chrono::seconds>(time_pt);
std::chrono::floor<std::chrono::seconds>(dur);
std::chrono::floor<std::chrono::seconds>(time_pt);
std::chrono::round<std::chrono::seconds>(dur);
std::chrono::round<std::chrono::seconds>(time_pt);
Description: Converts durations and time_points by rounding.
Documentation: std::chrono::duration, std::chrono::time_point
Notes:
std::chrono
is banned.C++17 TBD Language Features
The following C++17 language features are not allowed in the Chromium codebase. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.
Declaring non-type template parameters with auto [tbd]
template <auto... seq>
struct my_integer_sequence {
// ...
};
auto seq = my_integer_sequence<0, 1, 2>(); // Type deduced to be `int`.
Description: Following the deduction rules of auto
, while respecting the non-type template parameter list of allowable types, template arguments can be deduced from the types of its arguments.
Documentation: Template parameters
Notes:
Fold expressions [tbd]
template <typename... Args>
auto sum(Args... args) {
return (... + args);
}
Description: A fold expression performs a fold of a template parameter pack over a binary operator.
Documentation: Fold expression
Notes:
constexpr lambda [tbd]
auto identity = [](int n) constexpr { return n; };
static_assert(identity(123) == 123);
Description: Compile-time lambdas using constexpr.
Documentation: Lambda expressions
Notes:
Lambda capture this by value [tbd]
const auto l = [*this] { return member_; }
Description: *this
captures the current object by copy, while this
continues to capture by reference.
Documentation: Lambda capture
Notes:
UTF-8 character literals [tbd]
char x = u8'x';
Description: A character literal that begins with u8
is a character literal of type char
. The value of a UTF-8 character literal is equal to its ISO 10646 code point value.
Documentation: Character literal
Notes:
char8_t
, causing migration hazards for code using this.using declaration for attributes [tbd]
[[using CC: opt(1), debug]] // same as [[CC:opt(1), CC::debug]]
Description: Specifies a common namespace for a list of attributes.
Documentation: Attribute specifier sequence
Notes:
__has_include [tbd]
#if __has_include(<optional>) ...
Description: Checks whether a file is available for inclusion, i.e. the file exists.
Documentation: Source file inclusion
Notes:
C++17 TBD Library Features
The following C++17 library features are not allowed in the Chromium codebase. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.
std::variant [tbd]
std::variant<int, double> v = 12;
Description: The class template std::variant
represents a type-safe union
. An instance of std::variant
at any given time holds a value of one of its alternative types (it's also possible for it to be valueless).
Documentation: std::variant
Notes:
absl::variant
.std::optional [tbd]
std::optional<std::string> s;
Description: The class template std::optional
manages an optional contained value, i.e. a value that may or may not be present. A common use case for optional is the return value of a function that may fail.
Documentation: std::optional
Notes:
absl::optional
.std::string_view [tbd]
std::string_view str = "foo";
Description: A non-owning reference to a string. Useful for providing an abstraction on top of strings (e.g. for parsing).
Documentation: std::basic_string_view
Notes:
absl::string_view
and base::StringPiece
.std::invoke [tbd]
static_assert(std::invoke(std::plus<>(), 1, 2) == 3);
Description: Invokes a Callable
object with parameters. An example of a Callable
object is base::Callback
where an object can be called similarly to a regular function.
Documentation: std::invoke
Notes:
base::invoke
.std::apply [tbd]
static_assert(std::apply(std::plus<>(), std::make_tuple(1, 2)) == 3);
Description: Invokes a Callable
object with a tuple of arguments.
Documentation: std::apply
Notes:
absl::apply
and base::apply
.std::byte [tbd]
std::byte b = 0xFF;
int i = std::to_integer<int>(b); // 0xFF
Description: A standard way of representing data as a byte. std::byte
is neither a character type nor an arithmetic type, and the only operator overloads available are bitwise operations.
Documentation: std::byte
Notes:
Splicing for maps and sets [tbd]
std::map<...>::extract
std::map<...>::merge
std::set<...>::extract
std::set<...>::merge
Description: Moving nodes and merging containers without the overhead of expensive copies, moves, or heap allocations/deallocations.
Documentation: std::map::extract, std::map::merge
Notes:
Parallel algorithms [tbd]
auto it = std::find(std::execution::par, std::begin(vec), std::end(vec), 2);
Description: Many of the STL algorithms, such as the copy
, find
and sort
methods, now support the parallel execution policies: seq
, par
, and par_unseq
which translate to “sequentially”, “parallel” and “parallel unsequenced”.
Documentation: execution_policy_tag_t
Notes:
std::make_from_tuple [tbd]
// Calls Foo(int, double):
auto foo = std::make_from_tuple<Foo>(std::make_tuple(1, 3.5));
Description: Constructs an object from a tuple of arguments.
Documentation: std::make_from_tuple
Notes:
absl::make_from_tuple
.Searchers [tbd]
auto it = std::search(haystack.begin(), haystack.end(),
std::boyer_moore_searcher(needle.begin(), needle.end()));
Description: Alternate string searching algorithms.
Documentation: Searchers
Notes:
std::as_const [tbd]
auto&& const_ref = std::as_const(mutable_obj);
Description: Forms reference to const T.
Documentation: std::as_const
Notes:
base::as_const
.std::not_fn [tbd]
auto nonwhite = std::find_if(str.begin(), str.end(), std::not_fn(IsWhitespace));
Description: Creates a forwarding call wrapper that returns the negation of the callable object it holds.
Documentation: std::not_fn
Notes:
base::not_fn
.Uninitialized memory algorithms [tbd]
std::destroy_at(ptr);
std::destroy(ptr, ptr + 8);
std::destroy_n(ptr, 8);
std::uninitialized_move(src.begin(), src.end(), dest.begin());
std::uninitialized_value_construct(std::begin(storage), std::end(storage));
Description: Replaces direct constructor and destructor calls when manually managing memory.
Documentation: std::destroy_at, std::destroy, std::destroy_n, std::uninitialized_move, std::uninitialized_value_construct
Notes:
std::pmr::memory_resource and std::polymorphic_allocator [tbd]
#include <memory_resource>
Description: Manages memory allocations using runtime polymorphism.
Documentation: std::pmr::memory_resource, std::pmr::polymorphic_allocator,
Notes:
std::aligned_alloc [tbd]
int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024));
Description: Allocates uninitialized storage with the specified alignment.
Documentation: std::aligned_alloc
Notes:
std::conjunction/std::disjunction/std::negation [tbd]
template<typename T, typename... Ts>
std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>
func(T, Ts...) { ...
Description: Performs logical operations on type traits.
Documentation: std::conjunction, std::disjunction, std::negation
Notes:
std::is_swappable [tbd]
std::is_swappable<T>
std::is_swappable_with_v<T, U>
Description: Checks whether classes may be swapped.
Documentation: std::is_swappable
Notes:
std::is_invocable [tbd]
std::is_invocable_v<Fn, 1, "Hello">
Description: Checks whether a function may be invoked with the given argument types. The _r
variant also evaluates whether the result is convertible to a given type.
Documentation: std::is_invocable
Notes:
std::is_aggregate [tbd]
if constexpr(std::is_aggregate_v<T>) { ...
Description: Checks wither the given type is an aggregate type.
Documentation: std::is_aggregate
Notes:
std::has_unique_object_representations [tbd]
std::has_unique_object_representations_v<foo>
Description: Checks wither the given type is trivially copyable and any two objects with the same value have the same object representation.
Documentation: std::has_unique_object_representations
Notes:
std::clamp [tbd]
int x = base::clamp(inp, 0, 100);
Description: Clamps a value between a minimum and a maximum.
Documentation: std::clamp
Notes:
base::clamp
.std::reduce [tbd]
std::reduce(std::execution::par, v.cbegin(), v.cend());
Description: Like std::accumulate
except the elements of the range may be grouped and rearranged in arbitrary order.
Documentation: std::reduce
Notes:
std::execution::par
.std::inclusive_scan [tbd]
std::inclusive_scan(data.begin(), data.end(), output.begin());
Description: Like std::accumulate
but writes the result at each step into the output range.
Documentation: std::inclusive_scan
Notes:
std::exclusive_scan [tbd]
std::exclusive_scan(data.begin(), data.end(), output.begin());
Description: Like std::inclusive_scan
but omits the current element from the written output at each step; that is, results are “one value behind” those of std::inclusive_scan
.
Documentation: std::exclusive_scan
Notes:
std::gcd [tbd]
static_assert(std::gcd(12, 18) == 6);
Description: Computes the greatest common divisor of its arguments.
Documentation: std::gcd
Notes:
std::lcm [tbd]
static_assert(std::lcm(12, 18) == 36);
Description: Computes the least common multiple of its arguments.
Documentation: std::lcm
Notes:
Non-member std::size/std::empty/std::data [tbd]
for (std::size_t i = 0; i < std::size(c); ++i) { ...
if (!std::empty(c)) { ...
std::strcpy(arr, std::data(str));
Description: Non-member versions of what are normally member functions, for symmetrical use with things like arrays and initializer_lists.
Documentation: std::size, std::empty, std::data
Notes:
base::size
, base::empty
, and base::data
.Mathematical special functions [tbd]
std::assoc_laguerre()
std::assoc_legendre()
std::beta()
std::comp_ellint_1()
std::comp_ellint_2()
std::comp_ellint_3()
std::cyl_bessel_i()
std::cyl_bessel_j()
std::cyl_bessel_k()
std::cyl_neumann()
std::ellint_1()
std::ellint_2()
std::ellint_3()
std::expint()
std::hermite()
std::legendre()
std::laguerre()
std::riemann_zeta()
std::sph_bessel()
std::sph_legendre()
std::sph_neumann()
Description: A variety of mathematical functions.
Documentation: Mathematical special functions
Notes:
3D std::hypot [tbd]
double dist = std::hypot(1.0, 2.5, 3.7);
Description: Computes the distance from the origin in 3D space.
Documentation: std::hypot
Notes:
Cache line interface [tbd]
alignas(std::hardware_destructive_interference_size) std::atomic<int> cat;
static_assert(sizeof(S) <= std::hardware_constructive_interference_size);
Description: A portable way to access the L1 data cache line size.
Documentation: Hardware interference size
Notes:
std::launder [tbd]
struct Y { int z; };
alignas(Y) std::byte s[sizeof(Y)];
Y* q = new(&s) Y{2};
const int h = std::launder(reinterpret_cast<Y*>(&s))->z;
Description: When used to wrap a pointer, makes it valid to access the resulting object in cases it otherwise wouldn't have been, in a very limited set of circumstances.
Documentation: std::launder
Notes:
std::to_chars/std::from_chars [tbd]
std::to_chars(str.data(), str.data() + str.size(), 42);
std::from_chars(str.data(), str.data() + str.size(), result);
Description: Locale-independent, non-allocating, non-throwing functions to convert values to/from character strings, designed for use in high-throughput contexts.
Documentation: std::to_chars, std::from_chars
Notes:
std::atomic::is_always_lock_free [tbd]
template <typename T>
struct is_lock_free_impl
: std::integral_constant<bool, std::atomic<T>::is_always_lock_free> {};
Description: True when the given atomic type is always lock-free.
Documentation: std::atomic::is_always_lock_free
Notes:
std::scoped_lock [tbd]
std::scoped_lock lock(e1.m, e2.m);
Description: Provides an RAII-style mechanism for owning one or more mutexes for the duration of a scoped block.
Documentation: std::scoped_lock
Notes:
base::AutoLock
.std::timespec_get [tbd]
std::timespec ts;
std::timespec_get(&ts, TIME_UTC);
Description: Gets the current calendar time in the given time base.
Documentation: std::timespec_get
Notes:
Abseil Allowed Library Features
The following Abseil library features are allowed in the Chromium codebase.
128bit integer [allowed]
uint64_t a;
absl::uint128 v = a;
Description: Signed and unsigned 128-bit integer types meant to mimic intrinsic types as closely as possible.
Documentation: Numerics
Notes:
Optional [allowed]
absl::optional
Description: Early adaptation of C++17 std::optional
.
Documentation: std::optional
Notes:
base::Optional
. Discussion threadStatus [allowed]
absl::Status
Description: Type for returning detailed errors.
Documentation: status.h
Notes:
Approved for use inside a wrapper type. Use abseil_string_conversions.h to convert to and from absl::string_view so the wrapper can expose base::StringPiece. Use absl::Cord directly as minimally necessary to interface; do not expose in the wrapper type API.
Variant [allowed]
absl::variant
Description: Early adaptation of C++17 std::variant
.
Documentation: std::variant
Notes:
Abseil Banned Library Features
The following Abseil library features are not allowed in the Chromium codebase.
Any [banned]
absl::any a = int{5};
EXPECT_THAT(absl::any_cast<int>(&a), Pointee(5));
EXPECT_EQ(absl::any_cast<size_t>(&a), nullptr);
Description: Early adaptation of C++17 std::any
.
Documentation: std::any
Notes:
std::any
.Command line flags [banned]
ABSL_FLAG(bool, logs, false, "print logs to stderr");
app --logs=true;
Description: Allows programmatic access to flag values passed on the command-line to binaries.
Documentation: Flags Library
Notes:
base::CommandLine
instead.Span [banned]
absl::Span
Description: Early adaptation of C++20 std::span
.
Documentation: Using absl::Span
Notes:
base::span
. Keep using base::span
.string_view [banned]
absl::string_view
Description: Early adaptation of C++17 std::string_view
.
Documentation: absl::string_view
Notes:
base::StringPiece
from base/strings/
.Abseil TBD Features
The following Abseil library features are not allowed in the Chromium codebase. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.
bind_front [tbd]
absl::bind_front
Description: Binds the first N arguments of an invocable object and stores them by value.
Documentation:
Notes:
base::Bind
.Cleanup [tbd]
FILE* sink_file = fopen(sink_path, "w");
auto sink_closer = absl::MakeCleanup([sink_file] { fclose(sink_file); });
Description: Implements the scope guard idiom, invoking the contained callback's operator()() &&
on scope exit.
Documentation: cleanup.h
Notes:
defer
in Golang.Containers [tbd]
absl::flat_hash_map
absl::flat_hash_set
absl::node_hash_map
absl::node_hash_set
absl::btree_map
absl::btree_set
absl::btree_multimap
absl::btree_multiset
absl::InlinedVector
absl::FixedArray
Description: Alternatives to STL containers designed to be more efficient in the general case.
Documentation:
Notes:
base/containers/
.Container utilities [tbd]
auto it = absl::c_find(container, value);
Description: Container-based versions of algorithmic functions within C++ standard library.
Documentation: container.h
Notes:
base/ranges/algorithm.h
.FunctionRef [tbd]
absl::FunctionRef
Description: Type for holding a non-owning reference to an object of any invocable type.
Documentation: function_ref.h
Notes:
Random [tbd]
absl::BitGen bitgen;
size_t index = absl::Uniform(bitgen, 0u, elems.size());
Description: Functions and utilities for generating pseudorandom data.
Documentation: Random library
Notes:
base/rand_util.h
.StatusOr [tbd]
absl::StatusOr<T>
Description: An object that is either a usable value, or an error Status explaining why such a value is not present.
Documentation: statusor.h
Notes:
String Formatting [tbd]
absl::StrFormat
Description: A typesafe replacement for the family of printf() string formatting routines.
Documentation: String Formatting
Notes:
Strings Library [tbd]
absl::StrSplit
absl::StrJoin
absl::StrCat
absl::StrAppend
absl::Substitute
absl::StrContains
Description: Classes and utility functions for manipulating and comparing strings.
Documentation: String Utilities
Notes:
base/strings
.Synchronization [tbd]
absl::Mutex
Description: Primitives for managing tasks across different threads.
Documentation: Synchronization
Notes:
Lock
in base/synchronization/
.Time library [tbd]
absl::Duration
absl::Time
absl::TimeZone
absl::CivilDay
Description: Abstractions for holding time values, both in terms of absolute time and civil time.
Documentation: Time
Notes:
Time
APIs in base/
.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2015-02-10 activity中访问内部fragment的函数
2015-02-10 关于Fragment 不响应onActivityResult的情况分析
2015-02-10 AutoCompleteTextView和自定义的CursorAdapter