blob: a7ab788dbc597060783d53206957603fc647f5f8 [file] [log] [blame]
Louis Dionne2ce0df42021-07-06 14:39:011.. _using-libcxx:
2
Eric Fiselierb17bb062015-08-22 19:40:493============
4Using libc++
5============
6
7.. contents::
8 :local:
9
Louis Dionne2ce0df42021-07-06 14:39:0110Usually, libc++ is packaged and shipped by a vendor through some delivery vehicle
11(operating system distribution, SDK, toolchain, etc) and users don't need to do
12anything special in order to use the library.
Eric Fiselierb17bb062015-08-22 19:40:4913
Louis Dionne2ce0df42021-07-06 14:39:0114This page contains information about configuration knobs that can be used by
15users when they know libc++ is used by their toolchain, and how to use libc++
16when it is not the default library used by their toolchain.
17
18
19Using a different version of the C++ Standard
20=============================================
21
22Libc++ implements the various versions of the C++ Standard. Changing the version of
23the standard can be done by passing ``-std=c++XY`` to the compiler. Libc++ will
24automatically detect what Standard is being used and will provide functionality that
25matches that Standard in the library.
Eric Fiselierb17bb062015-08-22 19:40:4926
27.. code-block:: bash
28
Louis Dionne2ce0df42021-07-06 14:39:0129 $ clang++ -std=c++17 test.cpp
Eric Fiselierb17bb062015-08-22 19:40:4930
Louis Dionne2ce0df42021-07-06 14:39:0131.. warning::
32 Using ``-std=c++XY`` with a version of the Standard that has not been ratified yet
33 is considered unstable. Libc++ reserves the right to make breaking changes to the
34 library until the standard has been ratified.
Eric Fiselierb17bb062015-08-22 19:40:4935
Eric Fiselier998a5c82018-07-27 03:07:0936
Louis Dionne7300a652022-07-19 14:44:0637Enabling experimental C++ Library features
38==========================================
Eric Fiselierb17bb062015-08-22 19:40:4939
Louis Dionne7300a652022-07-19 14:44:0640Libc++ provides implementations of some experimental features. Experimental features
41are either Technical Specifications (TSes) or official features that were voted to
42the Standard but whose implementation is not complete or stable yet in libc++. Those
43are disabled by default because they are neither API nor ABI stable. However, the
Louis Dionnedeb3b552022-07-20 14:42:0444``-fexperimental-library`` compiler flag can be defined to turn those features on.
Eric Fiselier539cd672016-05-03 22:32:0845
46.. warning::
Louis Dionnedeb3b552022-07-20 14:42:0447 Experimental libraries are experimental.
Louis Dionne7300a652022-07-19 14:44:0648 * The contents of the ``<experimental/...>`` headers and the associated static
Eric Fiselier539cd672016-05-03 22:32:0849 library will not remain compatible between versions.
50 * No guarantees of API or ABI stability are provided.
Louis Dionne2ce0df42021-07-06 14:39:0151 * When the standardized version of an experimental feature is implemented,
Louis Dionne776acf22019-06-11 14:48:4052 the experimental feature is removed two releases after the non-experimental
53 version has shipped. The full policy is explained :ref:`here <experimental features>`.
Eric Fiselierb17bb062015-08-22 19:40:4954
Louis Dionnedeb3b552022-07-20 14:42:0455.. note::
56 On compilers that do not support the ``-fexperimental-library`` flag, users can
57 define the ``_LIBCPP_ENABLE_EXPERIMENTAL`` macro and manually link against the
58 appropriate static library (usually shipped as ``libc++experimental.a``) to get
59 access to experimental library features.
60
Eric Fiselierb17bb062015-08-22 19:40:4961
Louis Dionne2ce0df42021-07-06 14:39:0162Using libc++ when it is not the system default
63==============================================
64
65On systems where libc++ is provided but is not the default, Clang provides a flag
66called ``-stdlib=`` that can be used to decide which standard library is used.
67Using ``-stdlib=libc++`` will select libc++:
Eric Fiselierb17bb062015-08-22 19:40:4968
69.. code-block:: bash
70
Louis Dionne2ce0df42021-07-06 14:39:0171 $ clang++ -stdlib=libc++ test.cpp
Eric Fiselierb17bb062015-08-22 19:40:4972
Louis Dionneff7a3322021-09-07 16:55:4873On systems where libc++ is the library in use by default such as macOS and FreeBSD,
74this flag is not required.
Louis Dionne2ce0df42021-07-06 14:39:0175
76
77.. _alternate libcxx:
78
79Using a custom built libc++
80===========================
81
82Most compilers provide a way to disable the default behavior for finding the
83standard library and to override it with custom paths. With Clang, this can
84be done with:
Eric Fiselierb17bb062015-08-22 19:40:4985
86.. code-block:: bash
87
Louis Dionne2ce0df42021-07-06 14:39:0188 $ clang++ -nostdinc++ -nostdlib++ \
89 -isystem <install>/include/c++/v1 \
90 -L <install>/lib \
91 -Wl,-rpath,<install>/lib \
92 -lc++ \
93 test.cpp
Eric Fiselierb17bb062015-08-22 19:40:4994
Louis Dionne2ce0df42021-07-06 14:39:0195The option ``-Wl,-rpath,<install>/lib`` adds a runtime library search path,
96which causes the system's dynamic linker to look for libc++ in ``<install>/lib``
97whenever the program is loaded.
Eric Fiselierb17bb062015-08-22 19:40:4998
Louis Dionne2ce0df42021-07-06 14:39:0199GCC does not support the ``-nostdlib++`` flag, so one must use ``-nodefaultlibs``
100instead. Since that removes all the standard system libraries and not just libc++,
101the system libraries must be re-added manually. For example:
Eric Fiselierb17bb062015-08-22 19:40:49102
103.. code-block:: bash
104
Louis Dionne2ce0df42021-07-06 14:39:01105 $ g++ -nostdinc++ -nodefaultlibs \
106 -isystem <install>/include/c++/v1 \
107 -L <install>/lib \
108 -Wl,-rpath,<install>/lib \
109 -lc++ -lc++abi -lm -lc -lgcc_s -lgcc \
110 test.cpp
Eric Fiselier19352b12016-01-20 01:26:30111
112
113GDB Pretty printers for libc++
Louis Dionne2ce0df42021-07-06 14:39:01114==============================
Eric Fiselier19352b12016-01-20 01:26:30115
Louis Dionne2ce0df42021-07-06 14:39:01116GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
117provide pretty-printers itself. Those can be used as:
Eric Fiselier19352b12016-01-20 01:26:30118
Louis Dionne2ce0df42021-07-06 14:39:01119.. code-block:: bash
Eric Fiselier19352b12016-01-20 01:26:30120
Louis Dionne2ce0df42021-07-06 14:39:01121 $ gdb -ex "source <libcxx>/utils/gdb/libcxx/printers.py" \
122 -ex "python register_libcxx_printer_loader()" \
123 <args>
Eric Fiselierefd48ca2016-11-13 23:00:30124
Christopher Di Bellaab466482022-11-17 07:36:37125.. _include-what-you-use:
126
127include-what-you-use (IWYU)
128===========================
129
130libc++ provides an IWYU `mapping file <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md>`,
131which drastically improves the accuracy of the tool when using libc++. To use the mapping file with
132IWYU, you should run the tool like so:
133
134.. code-block:: bash
135
136 $ include-what-you-use -Xiwyu /path/to/libcxx/include/libcxx.imp file.cpp
137
138If you would prefer to not use that flag, then you can replace ``/path/to/include-what-you-use/share/libcxx.imp```
139file with the libc++-provided ``libcxx.imp`` file.
Eric Fiselierefd48ca2016-11-13 23:00:30140
Louis Dionneb0fd9492022-03-03 22:37:03141.. _assertions-mode:
142
143Enabling the "safe libc++" mode
144===============================
145
146Libc++ contains a number of assertions whose goal is to catch undefined behavior in the
147library, usually caused by precondition violations. Those assertions do not aim to be
148exhaustive -- instead they aim to provide a good balance between safety and performance.
149In particular, these assertions do not change the complexity of algorithms. However, they
150might, in some cases, interfere with compiler optimizations.
151
152By default, these assertions are turned off. Vendors can decide to turn them on while building
153the compiled library by defining ``LIBCXX_ENABLE_ASSERTIONS=ON`` at CMake configuration time.
154When ``LIBCXX_ENABLE_ASSERTIONS`` is used, the compiled library will be built with assertions
155enabled, **and** user code will be built with assertions enabled by default. If
156``LIBCXX_ENABLE_ASSERTIONS=OFF`` at CMake configure time, the compiled library will not contain
157assertions and the default when building user code will be to have assertions disabled.
158As a user, you can consult your vendor to know whether assertions are enabled by default.
159
160Furthermore, independently of any vendor-selected default, users can always control whether
161assertions are enabled in their code by defining ``_LIBCPP_ENABLE_ASSERTIONS=0|1`` before
162including any libc++ header (we recommend passing ``-D_LIBCPP_ENABLE_ASSERTIONS=X`` to the
163compiler). Note that if the compiled library was built by the vendor without assertions,
164functions compiled inside the static or shared library won't have assertions enabled even
165if the user defines ``_LIBCPP_ENABLE_ASSERTIONS=1`` (the same is true for the inverse case
166where the static or shared library was compiled **with** assertions but the user tries to
167disable them). However, most of the code in libc++ is in the headers, so the user-selected
168value for ``_LIBCPP_ENABLE_ASSERTIONS`` (if any) will usually be respected.
169
Louis Dionne507125a2022-07-25 17:43:47170When an assertion fails, the program is aborted through a special verbose termination function. The
171library provides a default function that prints an error message and calls ``std::abort()``. Note
172that this function is provided by the static or shared library, so it is only available when deploying
Louis Dionnee36f9e12022-08-04 19:25:48173to a platform where the compiled library is sufficiently recent. On older platforms, the program will
174terminate in an unspecified unsuccessful manner, but the quality of diagnostics won't be great.
Louis Dionne17c05a42023-01-09 21:59:59175However, users can also override that mechanism at two different levels. First, the mechanism can be
176overriden at compile-time by defining the ``_LIBCPP_VERBOSE_ABORT(format, args...)`` variadic macro.
177When that macro is defined, it will be called with a format string as the first argument, followed by
178a series of arguments to format using printf-style formatting. Compile-time customization may be
179interesting to get precise control over code generation, however it is also inconvenient to use in
180some cases. Indeed, compile-time customization of the verbose termination function requires that all
181translation units be compiled with a consistent definition for ``_LIBCPP_VERBOSE_ABORT`` to avoid ODR
182violations, which can add complexity in the build system of users.
Louis Dionneb0fd9492022-03-03 22:37:03183
Louis Dionne17c05a42023-01-09 21:59:59184Otherwise, if compile-time customization is not necessary, link-time customization of the handler is also
185possible, similarly to how replacing ``operator new`` works. This mechanism trades off fine-grained control
186over the call site where the termination is initiated in exchange for more ergonomics. Link-time customization
187is done by simply defining the following function in exactly one translation unit of your program:
Louis Dionneb0fd9492022-03-03 22:37:03188
189.. code-block:: cpp
190
Louis Dionne507125a2022-07-25 17:43:47191 void __libcpp_verbose_abort(char const* format, ...)
Louis Dionneb0fd9492022-03-03 22:37:03192
193This mechanism is similar to how one can replace the default definition of ``operator new``
194and ``operator delete``. For example:
195
196.. code-block:: cpp
197
198 // In HelloWorldHandler.cpp
Louis Dionne507125a2022-07-25 17:43:47199 #include <version> // must include any libc++ header before defining the function (C compatibility headers excluded)
Louis Dionneb0fd9492022-03-03 22:37:03200
Louis Dionne507125a2022-07-25 17:43:47201 void std::__libcpp_verbose_abort(char const* format, ...) {
Louis Dionne7de5aca2022-07-25 17:19:51202 va_list list;
203 va_start(list, format);
204 std::vfprintf(stderr, format, list);
205 va_end(list);
206
Louis Dionneb0fd9492022-03-03 22:37:03207 std::abort();
208 }
209
210 // In HelloWorld.cpp
211 #include <vector>
212
213 int main() {
214 std::vector<int> v;
Louis Dionne507125a2022-07-25 17:43:47215 int& x = v[0]; // Your termination function will be called here if _LIBCPP_ENABLE_ASSERTIONS=1
Louis Dionneb0fd9492022-03-03 22:37:03216 }
217
Louis Dionne507125a2022-07-25 17:43:47218Also note that the verbose termination function should never return. Since assertions in libc++
219catch undefined behavior, your code will proceed with undefined behavior if your function is called
220and does return.
Louis Dionneb0fd9492022-03-03 22:37:03221
Louis Dionne507125a2022-07-25 17:43:47222Furthermore, exceptions should not be thrown from the function. Indeed, many functions in the
223library are ``noexcept``, and any exception thrown from the termination function will result
224in ``std::terminate`` being called.
Louis Dionneb0fd9492022-03-03 22:37:03225
Eric Fiselierefd48ca2016-11-13 23:00:30226Libc++ Configuration Macros
227===========================
228
229Libc++ provides a number of configuration macros which can be used to enable
230or disable extended libc++ behavior, including enabling "debug mode" or
231thread safety annotations.
232
Eric Fiselierefd48ca2016-11-13 23:00:30233**_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
234 This macro is used to enable -Wthread-safety annotations on libc++'s
Jennifer Chukwu21bef4e2021-04-17 15:04:06235 ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
Eric Fiselierefd48ca2016-11-13 23:00:30236 disabled and must be manually enabled by the user.
Shoaib Meenaifc6100c2016-12-05 19:40:12237
238**_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
239 This macro is used to disable all visibility annotations inside libc++.
240 Defining this macro and then building libc++ with hidden visibility gives a
241 build of libc++ which does not export any symbols, which can be useful when
242 building statically for inclusion into another library.
Eric Fiselierbd688252016-12-08 23:57:08243
Eric Fiselierb1e7a122017-01-13 22:02:08244**_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS**:
245 This macro disables the additional diagnostics generated by libc++ using the
246 `diagnose_if` attribute. These additional diagnostics include checks for:
247
Louis Dionne3560fbf32018-12-06 21:46:17248 * Giving `set`, `map`, `multiset`, `multimap` and their `unordered_`
249 counterparts a comparator which is not const callable.
250 * Giving an unordered associative container a hasher that is not const
251 callable.
Eric Fiselierb1e7a122017-01-13 22:02:08252
Shoaib Meenai492d7132017-10-09 19:25:17253**_LIBCPP_NO_VCRUNTIME**:
254 Microsoft's C and C++ headers are fairly entangled, and some of their C++
255 headers are fairly hard to avoid. In particular, `vcruntime_new.h` gets pulled
256 in from a lot of other headers and provides definitions which clash with
257 libc++ headers, such as `nothrow_t` (note that `nothrow_t` is a struct, so
258 there's no way for libc++ to provide a compatible definition, since you can't
259 have multiple definitions).
260
261 By default, libc++ solves this problem by deferring to Microsoft's vcruntime
262 headers where needed. However, it may be undesirable to depend on vcruntime
263 headers, since they may not always be available in cross-compilation setups,
264 or they may clash with other headers. The `_LIBCPP_NO_VCRUNTIME` macro
265 prevents libc++ from depending on vcruntime headers. Consequently, it also
266 prevents libc++ headers from being interoperable with vcruntime headers (from
267 the aforementioned clashes), so users of this macro are promising to not
268 attempt to combine libc++ headers with the problematic vcruntime headers. This
269 macro also currently prevents certain `operator new`/`operator delete`
270 replacement scenarios from working, e.g. replacing `operator new` and
271 expecting a non-replaced `operator new[]` to call the replaced `operator new`.
272
Nikolas Klauser3c355e22022-09-01 10:02:58273**_LIBCPP_DISABLE_NODISCARD_EXT**:
274 This macro disables library-extensions of ``[[nodiscard]]``.
Nikolas Klauserb978dfb2022-08-19 13:41:56275 See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>` for more information.
Roman Lebedevc65d39a2018-09-22 17:54:48276
Louis Dionnea470a132019-03-12 20:10:06277**_LIBCPP_DISABLE_DEPRECATION_WARNINGS**:
278 This macro disables warnings when using deprecated components. For example,
279 using `std::auto_ptr` when compiling in C++11 mode will normally trigger a
280 warning saying that `std::auto_ptr` is deprecated. If the macro is defined,
281 no warning will be emitted. By default, this macro is not defined.
Roman Lebedevc65d39a2018-09-22 17:54:48282
Eric Fiselier2a1bfa92017-02-17 03:25:08283C++17 Specific Configuration Macros
284-----------------------------------
285**_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES**:
286 This macro is used to re-enable all the features removed in C++17. The effect
287 is equivalent to manually defining each macro listed below.
288
Eric Fiselier07e93d32017-02-17 03:30:25289**_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR**:
Arthur O'Dwyerd42d9e12021-05-24 22:36:17290 This macro is used to re-enable `auto_ptr`.
291
292**_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS**:
293 This macro is used to re-enable the `binder1st`, `binder2nd`,
294 `pointer_to_unary_function`, `pointer_to_binary_function`, `mem_fun_t`,
295 `mem_fun1_t`, `mem_fun_ref_t`, `mem_fun1_ref_t`, `const_mem_fun_t`,
296 `const_mem_fun1_t`, `const_mem_fun_ref_t`, and `const_mem_fun1_ref_t`
297 class templates, and the `bind1st`, `bind2nd`, `mem_fun`, `mem_fun_ref`,
298 and `ptr_fun` functions.
299
300**_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE**:
301 This macro is used to re-enable the `random_shuffle` algorithm.
302
303**_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS**:
304 This macro is used to re-enable `set_unexpected`, `get_unexpected`, and
305 `unexpected`.
Roman Lebedevc65d39a2018-09-22 17:54:48306
Mark de Wever8aa59652022-07-07 17:07:03307C++20 Specific Configuration Macros
308-----------------------------------
Roman Lebedevc65d39a2018-09-22 17:54:48309**_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17**:
310 This macro can be used to disable diagnostics emitted from functions marked
311 ``[[nodiscard]]`` in dialects after C++17. See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>`
312 for more information.
313
Arthur O'Dwyerd42d9e12021-05-24 22:36:17314**_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES**:
315 This macro is used to re-enable all the features removed in C++20. The effect
316 is equivalent to manually defining each macro listed below.
317
318**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS**:
319 This macro is used to re-enable redundant members of `allocator<T>`,
320 including `pointer`, `reference`, `rebind`, `address`, `max_size`,
321 `construct`, `destroy`, and the two-argument overload of `allocate`.
Arthur O'Dwyerd42d9e12021-05-24 22:36:17322
Ilya Biryukov374f9382022-06-15 08:55:55323**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION**:
324 This macro is used to re-enable the library-provided specializations of
325 `allocator<void>` and `allocator<const void>`.
326 Use it in conjunction with `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`
327 to ensure that removed members of `allocator<void>` can be accessed.
328
Arthur O'Dwyerdc066882021-05-25 18:34:18329**_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS**:
330 This macro is used to re-enable the `argument_type`, `result_type`,
331 `first_argument_type`, and `second_argument_type` members of class
332 templates such as `plus`, `logical_not`, `hash`, and `owner_less`.
333
Arthur O'Dwyerd42d9e12021-05-24 22:36:17334**_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS**:
335 This macro is used to re-enable `not1`, `not2`, `unary_negate`,
336 and `binary_negate`.
337
338**_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR**:
339 This macro is used to re-enable `raw_storage_iterator`.
340
wmbat2ff5a562021-07-02 17:08:36341**_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS**:
Louis Dionne2ce0df42021-07-06 14:39:01342 This macro is used to re-enable `is_literal_type`, `is_literal_type_v`,
wmbat2ff5a562021-07-02 17:08:36343 `result_of` and `result_of_t`.
Roman Lebedevc65d39a2018-09-22 17:54:48344
Louis Dionne2ce0df42021-07-06 14:39:01345
Roman Lebedevc65d39a2018-09-22 17:54:48346Libc++ Extensions
347=================
348
349This section documents various extensions provided by libc++, how they're
350provided, and any information regarding how to use them.
351
352.. _nodiscard extension:
353
354Extended applications of ``[[nodiscard]]``
355------------------------------------------
356
357The ``[[nodiscard]]`` attribute is intended to help users find bugs where
358function return values are ignored when they shouldn't be. After C++17 the
359C++ standard has started to declared such library functions as ``[[nodiscard]]``.
360However, this application is limited and applies only to dialects after C++17.
361Users who want help diagnosing misuses of STL functions may desire a more
362liberal application of ``[[nodiscard]]``.
363
364For this reason libc++ provides an extension that does just that! The
Nikolas Klauser3c355e22022-09-01 10:02:58365extension is enabled by default and can be disabled by defining ``_LIBCPP_DISABLE_NODISCARD_EXT``.
366The extended applications of ``[[nodiscard]]`` takes two forms:
Roman Lebedevc65d39a2018-09-22 17:54:48367
3681. Backporting ``[[nodiscard]]`` to entities declared as such by the
369 standard in newer dialects, but not in the present one.
370
Arthur O'Dwyer4b7bad92021-04-05 18:56:033712. Extended applications of ``[[nodiscard]]``, at the library's discretion,
Roman Lebedevc65d39a2018-09-22 17:54:48372 applied to entities never declared as such by the standard.
373
Roman Lebedevc65d39a2018-09-22 17:54:48374Entities declared with ``_LIBCPP_NODISCARD_EXT``
375~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376
377This section lists all extended applications of ``[[nodiscard]]`` to entities
378which no dialect declares as such (See the second form described above).
379
Nico Weber1362d7e2019-04-03 18:13:08380* ``adjacent_find``
381* ``all_of``
382* ``any_of``
383* ``binary_search``
384* ``clamp``
385* ``count_if``
386* ``count``
387* ``equal_range``
388* ``equal``
389* ``find_end``
390* ``find_first_of``
391* ``find_if_not``
392* ``find_if``
393* ``find``
Roman Lebedevc65d39a2018-09-22 17:54:48394* ``get_temporary_buffer``
Nico Weber1362d7e2019-04-03 18:13:08395* ``includes``
396* ``is_heap_until``
397* ``is_heap``
398* ``is_partitioned``
399* ``is_permutation``
400* ``is_sorted_until``
401* ``is_sorted``
402* ``lexicographical_compare``
403* ``lower_bound``
404* ``max_element``
405* ``max``
406* ``min_element``
407* ``min``
408* ``minmax_element``
409* ``minmax``
410* ``mismatch``
411* ``none_of``
412* ``remove_if``
413* ``remove``
414* ``search_n``
415* ``search``
416* ``unique``
417* ``upper_bound``
Nikolas Klauser660b2432022-11-01 19:06:11418* ``ranges::adjacent_find``
419* ``ranges::all_of``
420* ``ranges::any_of``
421* ``ranges::binary_search``
422* ``ranges::clamp``
423* ``ranges::count_if``
424* ``ranges::count``
425* ``ranges::equal_range``
426* ``ranges::equal``
427* ``ranges::find_end``
428* ``ranges::find_first_of``
429* ``ranges::find_if_not``
430* ``ranges::find_if``
431* ``ranges::find``
432* ``ranges::get_temporary_buffer``
433* ``ranges::includes``
434* ``ranges::is_heap_until``
435* ``ranges::is_heap``
436* ``ranges::is_partitioned``
437* ``ranges::is_permutation``
438* ``ranges::is_sorted_until``
439* ``ranges::is_sorted``
440* ``ranges::lexicographical_compare``
441* ``ranges::lower_bound``
442* ``ranges::max_element``
443* ``ranges::max``
444* ``ranges::min_element``
445* ``ranges::min``
446* ``ranges::minmax_element``
447* ``ranges::minmax``
448* ``ranges::mismatch``
449* ``ranges::none_of``
450* ``ranges::remove_if``
451* ``ranges::remove``
452* ``ranges::search_n``
453* ``ranges::search``
454* ``ranges::unique``
455* ``ranges::upper_bound``
Louis Dionne86dd28a2019-08-13 11:12:28456* ``lock_guard``'s constructors
Arthur O'Dwyer4b7bad92021-04-05 18:56:03457* ``as_const``
Louis Dionneb1fb3d72020-05-28 18:28:38458* ``bit_cast``
Arthur O'Dwyer4b7bad92021-04-05 18:56:03459* ``forward``
460* ``move``
461* ``move_if_noexcept``
462* ``identity::operator()``
463* ``to_integer``
464* ``to_underlying``
Nikolas Klauser633927d2022-12-25 19:13:39465* ``signbit``
466* ``fpclassify``
467* ``isfinite``
468* ``isinf``
469* ``isnan``
470* ``isnormal``
471* ``isgreater``
472* ``isgreaterequal``
473* ``isless``
474* ``islessequal``
475* ``islessgreater``
476* ``isunordered``
477* ``ceil``
478* ``fabs``
479* ``floor``
480* ``cbrt``
481* ``copysign``
482* ``fmax``
483* ``fmin``
484* ``nearbyint``
485* ``rint``
486* ``round``
487* ``trunc``
Louis Dionne07e984b2022-06-01 19:25:14488
Louis Dionne497705f2022-08-10 21:34:45489Extended integral type support
490------------------------------
491
492Several platforms support types that are not specified in the Standard, such as
493the 128-bit integral types ``__int128_t`` and ``__uint128_t``. As an extension,
494libc++ does a best-effort attempt to support these types like other integral
495types, by supporting them notably in:
496
497* ``<bits>``
498* ``<charconv>``
499* ``<functional>``
500* ``<type_traits>``
501* ``<format>``
502* ``<random>``
503
Louis Dionne07e984b2022-06-01 19:25:14504Additional types supported in random distributions
505~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
506
507The `C++ Standard <http://eel.is/c++draft/rand#req.genl-1.5>`_ mentions that instantiating several random number
508distributions with types other than ``short``, ``int``, ``long``, ``long long``, and their unsigned versions is
509undefined. As an extension, libc++ supports instantiating ``binomial_distribution``, ``discrete_distribution``,
510``geometric_distribution``, ``negative_binomial_distribution``, ``poisson_distribution``, and ``uniform_int_distribution``
511with ``int8_t``, ``__int128_t`` and their unsigned versions.
Mark de Wever77ccf632022-07-07 18:02:07512
Mark de Weverf7127752022-07-15 05:42:17513Extensions to ``<format>``
514--------------------------
515
516The exposition only type ``basic-format-string`` and its typedefs
517``format-string`` and ``wformat-string`` became ``basic_format_string``,
518``format_string``, and ``wformat_string`` in C++23. Libc++ makes these types
519available in C++20 as an extension.
Mark de Wever68c3d662023-02-21 16:33:56520
521For padding Unicode strings the ``format`` library relies on the Unicode
522Standard. Libc++ retroactively updates the Unicode Standard in older C++
523versions. This allows the library to have better estimates for newly introduced
524Unicode code points, without requiring the user to use the latest C++ version
525in their code base.
Advenam Tacet2fa1bec2023-05-04 21:16:06526=======
527Turning off ASan annotation in containers
528~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
529
530``__asan_annotate_container_with_allocator`` is a customization point to allow users to disable
531`Address Sanitizer annotations for containers <https://github.com/google/sanitizers/wiki/AddressSanitizerContainerOverflow>`_ for specific allocators. This may be necessary for allocators that access allocated memory.
532This customization point exists only when ``_LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS`` Feature Test Macro is defined.
533
534For allocators not running destructors, it is also possible to `bulk-unpoison memory <https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning>`_ instead of disabling annotations altogether.
535
536The struct may be specialized for user-defined allocators. It is a `Cpp17UnaryTypeTrait <http://eel.is/c++draft/type.traits#meta.rqmts>`_ with a base characteristic of ``true_type`` if the container is allowed to use annotations and ``false_type`` otherwise.
537
538The annotations for a ``user_allocator`` can be disabled like this:
539
540.. code-block:: cpp
541
542 #ifdef _LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS
543 template <class T>
544 struct std::__asan_annotate_container_with_allocator<user_allocator<T>> : std::false_type {};
545 #endif
546
547Why may I want to turn it off?
548------------------------------
549
550There are a few reasons why you may want to turn off annotations for an allocator.
551Unpoisoning may not be an option, if (for example) you are not maintaining the allocator.
552
553* You are using allocator, which does not call destructor during deallocation.
554* You are aware that memory allocated with an allocator may be accessed, even when unused by container.