blob: aa581207cf079829483dcc01937b00392e0cb65d [file] [log] [blame]
Louis Dionne4b1b70d2021-07-06 10:39:01 -04001.. _using-libcxx:
2
Eric Fiselierd720d1f2015-08-22 19:40:49 +00003============
4Using libc++
5============
6
7.. contents::
8 :local:
9
Louis Dionne4b1b70d2021-07-06 10:39:01 -040010Usually, 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 Fiselierd720d1f2015-08-22 19:40:49 +000013
Louis Dionne4b1b70d2021-07-06 10:39:01 -040014This 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 Fiselierd720d1f2015-08-22 19:40:49 +000026
27.. code-block:: bash
28
Louis Dionne4b1b70d2021-07-06 10:39:01 -040029 $ clang++ -std=c++17 test.cpp
Eric Fiselierd720d1f2015-08-22 19:40:49 +000030
Louis Dionne4b1b70d2021-07-06 10:39:01 -040031.. 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 Fiselierd720d1f2015-08-22 19:40:49 +000035
Eric Fiselier02cea5e2018-07-27 03:07:09 +000036
Louis Dionne3d895a12022-07-19 10:44:06 -040037Enabling experimental C++ Library features
38==========================================
Eric Fiselierd720d1f2015-08-22 19:40:49 +000039
Louis Dionne3d895a12022-07-19 10:44:06 -040040Libc++ 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 Dionneeb796712022-07-20 10:42:04 -040044``-fexperimental-library`` compiler flag can be defined to turn those features on.
Eric Fiselierfa43a5c2016-05-03 22:32:08 +000045
46.. warning::
Louis Dionneeb796712022-07-20 10:42:04 -040047 Experimental libraries are experimental.
Louis Dionne3d895a12022-07-19 10:44:06 -040048 * The contents of the ``<experimental/...>`` headers and the associated static
Eric Fiselierfa43a5c2016-05-03 22:32:08 +000049 library will not remain compatible between versions.
50 * No guarantees of API or ABI stability are provided.
Louis Dionne4b1b70d2021-07-06 10:39:01 -040051 * When the standardized version of an experimental feature is implemented,
Louis Dionne37677132019-06-11 14:48:40 +000052 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 Fiselierd720d1f2015-08-22 19:40:49 +000054
Louis Dionneeb796712022-07-20 10:42:04 -040055.. 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 Fiselierd720d1f2015-08-22 19:40:49 +000061
Louis Dionne4b1b70d2021-07-06 10:39:01 -040062Using 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 Fiselierd720d1f2015-08-22 19:40:49 +000068
69.. code-block:: bash
70
Louis Dionne4b1b70d2021-07-06 10:39:01 -040071 $ clang++ -stdlib=libc++ test.cpp
Eric Fiselierd720d1f2015-08-22 19:40:49 +000072
Louis Dionnee4745512021-09-07 12:55:48 -040073On systems where libc++ is the library in use by default such as macOS and FreeBSD,
74this flag is not required.
Louis Dionne4b1b70d2021-07-06 10:39:01 -040075
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 Fiselierd720d1f2015-08-22 19:40:49 +000085
86.. code-block:: bash
87
Louis Dionne4b1b70d2021-07-06 10:39:01 -040088 $ clang++ -nostdinc++ -nostdlib++ \
89 -isystem <install>/include/c++/v1 \
90 -L <install>/lib \
91 -Wl,-rpath,<install>/lib \
92 -lc++ \
93 test.cpp
Eric Fiselierd720d1f2015-08-22 19:40:49 +000094
Louis Dionne4b1b70d2021-07-06 10:39:01 -040095The 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 Fiselierd720d1f2015-08-22 19:40:49 +000098
Louis Dionne4b1b70d2021-07-06 10:39:01 -040099GCC 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 Fiselierd720d1f2015-08-22 19:40:49 +0000102
103.. code-block:: bash
104
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400105 $ 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 Fiselier41ee4312016-01-20 01:26:30 +0000111
112
113GDB Pretty printers for libc++
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400114==============================
Eric Fiselier41ee4312016-01-20 01:26:30 +0000115
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400116GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
117provide pretty-printers itself. Those can be used as:
Eric Fiselier41ee4312016-01-20 01:26:30 +0000118
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400119.. code-block:: bash
Eric Fiselier41ee4312016-01-20 01:26:30 +0000120
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400121 $ gdb -ex "source <libcxx>/utils/gdb/libcxx/printers.py" \
122 -ex "python register_libcxx_printer_loader()" \
123 <args>
Eric Fiselierb3825302016-11-13 23:00:30 +0000124
125
Louis Dionne6e8eb552022-03-03 17:37:03 -0500126.. _assertions-mode:
127
128Enabling the "safe libc++" mode
129===============================
130
131Libc++ contains a number of assertions whose goal is to catch undefined behavior in the
132library, usually caused by precondition violations. Those assertions do not aim to be
133exhaustive -- instead they aim to provide a good balance between safety and performance.
134In particular, these assertions do not change the complexity of algorithms. However, they
135might, in some cases, interfere with compiler optimizations.
136
137By default, these assertions are turned off. Vendors can decide to turn them on while building
138the compiled library by defining ``LIBCXX_ENABLE_ASSERTIONS=ON`` at CMake configuration time.
139When ``LIBCXX_ENABLE_ASSERTIONS`` is used, the compiled library will be built with assertions
140enabled, **and** user code will be built with assertions enabled by default. If
141``LIBCXX_ENABLE_ASSERTIONS=OFF`` at CMake configure time, the compiled library will not contain
142assertions and the default when building user code will be to have assertions disabled.
143As a user, you can consult your vendor to know whether assertions are enabled by default.
144
145Furthermore, independently of any vendor-selected default, users can always control whether
146assertions are enabled in their code by defining ``_LIBCPP_ENABLE_ASSERTIONS=0|1`` before
147including any libc++ header (we recommend passing ``-D_LIBCPP_ENABLE_ASSERTIONS=X`` to the
148compiler). Note that if the compiled library was built by the vendor without assertions,
149functions compiled inside the static or shared library won't have assertions enabled even
150if the user defines ``_LIBCPP_ENABLE_ASSERTIONS=1`` (the same is true for the inverse case
151where the static or shared library was compiled **with** assertions but the user tries to
152disable them). However, most of the code in libc++ is in the headers, so the user-selected
153value for ``_LIBCPP_ENABLE_ASSERTIONS`` (if any) will usually be respected.
154
155When an assertion fails, an assertion handler function is called. The library provides a default
156assertion handler that prints an error message and calls ``std::abort()``. Note that this assertion
157handler is provided by the static or shared library, so it is only available when deploying to a
158platform where the compiled library is sufficiently recent. However, users can also override that
159assertion handler with their own, which can be useful to provide custom behavior, or when deploying
160to older platforms where the default assertion handler isn't available.
161
162Replacing the default assertion handler is done by defining the following function:
163
164.. code-block:: cpp
165
166 void __libcpp_assertion_handler(char const* file, int line, char const* expression, char const* message)
167
168This mechanism is similar to how one can replace the default definition of ``operator new``
169and ``operator delete``. For example:
170
171.. code-block:: cpp
172
173 // In HelloWorldHandler.cpp
Louis Dionneb4fce352022-03-25 12:55:36 -0400174 #include <version> // must include any libc++ header before defining the handler (C compatibility headers excluded)
Louis Dionne6e8eb552022-03-03 17:37:03 -0500175
176 void std::__libcpp_assertion_handler(char const* file, int line, char const* expression, char const* message) {
177 std::printf("Assertion %s failed at %s:%d, more info: %s", expression, file, line, message);
178 std::abort();
179 }
180
181 // In HelloWorld.cpp
182 #include <vector>
183
184 int main() {
185 std::vector<int> v;
186 int& x = v[0]; // Your assertion handler will be called here if _LIBCPP_ENABLE_ASSERTIONS=1
187 }
188
189Also note that the assertion handler should usually not return. Since the assertions in libc++
190catch undefined behavior, your code will proceed with undefined behavior if your assertion
191handler is called and does return.
192
193Furthermore, throwing an exception from the assertion handler is not recommended. Indeed, many
194functions in the library are ``noexcept``, and any exception thrown from the assertion handler
195will result in ``std::terminate`` being called.
196
197Back-deploying with a custom assertion handler
198----------------------------------------------
199When deploying to an older platform that does not provide a default assertion handler, the
200compiler will diagnose the usage of ``std::__libcpp_assertion_handler`` with an error. This
201is done to avoid the load-time error that would otherwise happen if the code was being deployed
202on the older system.
203
204If you are providing a custom assertion handler, this error is effectively a false positive.
205To let the library know that you are providing a custom assertion handler in back-deployment
206scenarios, you must define the ``_LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED`` macro,
207and the library will assume that you are providing your own definition. If no definition is
208provided and the code is back-deployed to the older platform, it will fail to load when the
209dynamic linker fails to find a definition for ``std::__libcpp_assertion_handler``, so you
210should only remove the guard rails if you really mean it!
211
Eric Fiselierb3825302016-11-13 23:00:30 +0000212Libc++ Configuration Macros
213===========================
214
215Libc++ provides a number of configuration macros which can be used to enable
216or disable extended libc++ behavior, including enabling "debug mode" or
217thread safety annotations.
218
Eric Fiselierb3825302016-11-13 23:00:30 +0000219**_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS**:
220 This macro is used to enable -Wthread-safety annotations on libc++'s
Jennifer Chukwub9788092021-04-17 20:34:06 +0530221 ``std::mutex`` and ``std::lock_guard``. By default, these annotations are
Eric Fiselierb3825302016-11-13 23:00:30 +0000222 disabled and must be manually enabled by the user.
Shoaib Meenaif36e9882016-12-05 19:40:12 +0000223
224**_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS**:
225 This macro is used to disable all visibility annotations inside libc++.
226 Defining this macro and then building libc++ with hidden visibility gives a
227 build of libc++ which does not export any symbols, which can be useful when
228 building statically for inclusion into another library.
Eric Fiselier41b686e2016-12-08 23:57:08 +0000229
Eric Fiseliera7a14ed2017-01-13 22:02:08 +0000230**_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS**:
231 This macro disables the additional diagnostics generated by libc++ using the
232 `diagnose_if` attribute. These additional diagnostics include checks for:
233
Louis Dionne878a3a82018-12-06 21:46:17 +0000234 * Giving `set`, `map`, `multiset`, `multimap` and their `unordered_`
235 counterparts a comparator which is not const callable.
236 * Giving an unordered associative container a hasher that is not const
237 callable.
Eric Fiseliera7a14ed2017-01-13 22:02:08 +0000238
Shoaib Meenaicfd19602017-10-09 19:25:17 +0000239**_LIBCPP_NO_VCRUNTIME**:
240 Microsoft's C and C++ headers are fairly entangled, and some of their C++
241 headers are fairly hard to avoid. In particular, `vcruntime_new.h` gets pulled
242 in from a lot of other headers and provides definitions which clash with
243 libc++ headers, such as `nothrow_t` (note that `nothrow_t` is a struct, so
244 there's no way for libc++ to provide a compatible definition, since you can't
245 have multiple definitions).
246
247 By default, libc++ solves this problem by deferring to Microsoft's vcruntime
248 headers where needed. However, it may be undesirable to depend on vcruntime
249 headers, since they may not always be available in cross-compilation setups,
250 or they may clash with other headers. The `_LIBCPP_NO_VCRUNTIME` macro
251 prevents libc++ from depending on vcruntime headers. Consequently, it also
252 prevents libc++ headers from being interoperable with vcruntime headers (from
253 the aforementioned clashes), so users of this macro are promising to not
254 attempt to combine libc++ headers with the problematic vcruntime headers. This
255 macro also currently prevents certain `operator new`/`operator delete`
256 replacement scenarios from working, e.g. replacing `operator new` and
257 expecting a non-replaced `operator new[]` to call the replaced `operator new`.
258
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000259**_LIBCPP_ENABLE_NODISCARD**:
260 Allow the library to add ``[[nodiscard]]`` attributes to entities not specified
261 as ``[[nodiscard]]`` by the current language dialect. This includes
262 backporting applications of ``[[nodiscard]]`` from newer dialects and
263 additional extended applications at the discretion of the library. All
264 additional applications of ``[[nodiscard]]`` are disabled by default.
265 See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>` for
266 more information.
267
268**_LIBCPP_DISABLE_NODISCARD_EXT**:
269 This macro prevents the library from applying ``[[nodiscard]]`` to entities
270 purely as an extension. See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>`
271 for more information.
272
Louis Dionneded5b772019-03-12 20:10:06 +0000273**_LIBCPP_DISABLE_DEPRECATION_WARNINGS**:
274 This macro disables warnings when using deprecated components. For example,
275 using `std::auto_ptr` when compiling in C++11 mode will normally trigger a
276 warning saying that `std::auto_ptr` is deprecated. If the macro is defined,
277 no warning will be emitted. By default, this macro is not defined.
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000278
Eric Fiselierddd77792017-02-17 03:25:08 +0000279C++17 Specific Configuration Macros
280-----------------------------------
281**_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES**:
282 This macro is used to re-enable all the features removed in C++17. The effect
283 is equivalent to manually defining each macro listed below.
284
Eric Fiselier65d5b4c2017-02-17 03:30:25 +0000285**_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR**:
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400286 This macro is used to re-enable `auto_ptr`.
287
288**_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS**:
289 This macro is used to re-enable the `binder1st`, `binder2nd`,
290 `pointer_to_unary_function`, `pointer_to_binary_function`, `mem_fun_t`,
291 `mem_fun1_t`, `mem_fun_ref_t`, `mem_fun1_ref_t`, `const_mem_fun_t`,
292 `const_mem_fun1_t`, `const_mem_fun_ref_t`, and `const_mem_fun1_ref_t`
293 class templates, and the `bind1st`, `bind2nd`, `mem_fun`, `mem_fun_ref`,
294 and `ptr_fun` functions.
295
296**_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE**:
297 This macro is used to re-enable the `random_shuffle` algorithm.
298
299**_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS**:
300 This macro is used to re-enable `set_unexpected`, `get_unexpected`, and
301 `unexpected`.
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000302
Mark de Wever0c9fe4c2022-07-07 19:07:03 +0200303C++20 Specific Configuration Macros
304-----------------------------------
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000305**_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17**:
306 This macro can be used to disable diagnostics emitted from functions marked
307 ``[[nodiscard]]`` in dialects after C++17. See :ref:`Extended Applications of [[nodiscard]] <nodiscard extension>`
308 for more information.
309
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400310**_LIBCPP_ENABLE_CXX20_REMOVED_FEATURES**:
311 This macro is used to re-enable all the features removed in C++20. The effect
312 is equivalent to manually defining each macro listed below.
313
314**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS**:
315 This macro is used to re-enable redundant members of `allocator<T>`,
316 including `pointer`, `reference`, `rebind`, `address`, `max_size`,
317 `construct`, `destroy`, and the two-argument overload of `allocate`.
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400318
Ilya Biryukov051e6b92022-06-15 10:55:55 +0200319**_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_VOID_SPECIALIZATION**:
320 This macro is used to re-enable the library-provided specializations of
321 `allocator<void>` and `allocator<const void>`.
322 Use it in conjunction with `_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS`
323 to ensure that removed members of `allocator<void>` can be accessed.
324
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400325**_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS**:
326 This macro is used to re-enable the `argument_type`, `result_type`,
327 `first_argument_type`, and `second_argument_type` members of class
328 templates such as `plus`, `logical_not`, `hash`, and `owner_less`.
329
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400330**_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS**:
331 This macro is used to re-enable `not1`, `not2`, `unary_negate`,
332 and `binary_negate`.
333
334**_LIBCPP_ENABLE_CXX20_REMOVED_RAW_STORAGE_ITERATOR**:
335 This macro is used to re-enable `raw_storage_iterator`.
336
wmbatf5b33762021-07-02 17:08:36 +0000337**_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS**:
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400338 This macro is used to re-enable `is_literal_type`, `is_literal_type_v`,
wmbatf5b33762021-07-02 17:08:36 +0000339 `result_of` and `result_of_t`.
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000340
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400341
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000342Libc++ Extensions
343=================
344
345This section documents various extensions provided by libc++, how they're
346provided, and any information regarding how to use them.
347
348.. _nodiscard extension:
349
350Extended applications of ``[[nodiscard]]``
351------------------------------------------
352
353The ``[[nodiscard]]`` attribute is intended to help users find bugs where
354function return values are ignored when they shouldn't be. After C++17 the
355C++ standard has started to declared such library functions as ``[[nodiscard]]``.
356However, this application is limited and applies only to dialects after C++17.
357Users who want help diagnosing misuses of STL functions may desire a more
358liberal application of ``[[nodiscard]]``.
359
360For this reason libc++ provides an extension that does just that! The
361extension must be enabled by defining ``_LIBCPP_ENABLE_NODISCARD``. The extended
362applications of ``[[nodiscard]]`` takes two forms:
363
3641. Backporting ``[[nodiscard]]`` to entities declared as such by the
365 standard in newer dialects, but not in the present one.
366
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003672. Extended applications of ``[[nodiscard]]``, at the library's discretion,
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000368 applied to entities never declared as such by the standard.
369
370Users may also opt-out of additional applications ``[[nodiscard]]`` using
371additional macros.
372
373Applications of the first form, which backport ``[[nodiscard]]`` from a newer
Arthur O'Dwyer108facb2021-04-05 14:56:03 -0400374dialect, may be disabled using macros specific to the dialect in which it was
375added. For example, ``_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17``.
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000376
377Applications of the second form, which are pure extensions, may be disabled
378by defining ``_LIBCPP_DISABLE_NODISCARD_EXT``.
379
380
381Entities declared with ``_LIBCPP_NODISCARD_EXT``
382~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
383
384This section lists all extended applications of ``[[nodiscard]]`` to entities
385which no dialect declares as such (See the second form described above).
386
Nico Weber471b10a2019-04-03 18:13:08 +0000387* ``adjacent_find``
388* ``all_of``
389* ``any_of``
390* ``binary_search``
391* ``clamp``
392* ``count_if``
393* ``count``
394* ``equal_range``
395* ``equal``
396* ``find_end``
397* ``find_first_of``
398* ``find_if_not``
399* ``find_if``
400* ``find``
Roman Lebedevb5959fa2018-09-22 17:54:48 +0000401* ``get_temporary_buffer``
Nico Weber471b10a2019-04-03 18:13:08 +0000402* ``includes``
403* ``is_heap_until``
404* ``is_heap``
405* ``is_partitioned``
406* ``is_permutation``
407* ``is_sorted_until``
408* ``is_sorted``
409* ``lexicographical_compare``
410* ``lower_bound``
411* ``max_element``
412* ``max``
413* ``min_element``
414* ``min``
415* ``minmax_element``
416* ``minmax``
417* ``mismatch``
418* ``none_of``
419* ``remove_if``
420* ``remove``
421* ``search_n``
422* ``search``
423* ``unique``
424* ``upper_bound``
Louis Dionne346587e2019-08-13 11:12:28 +0000425* ``lock_guard``'s constructors
Arthur O'Dwyer108facb2021-04-05 14:56:03 -0400426* ``as_const``
Louis Dionne1462d4d2020-05-28 14:28:38 -0400427* ``bit_cast``
Arthur O'Dwyer108facb2021-04-05 14:56:03 -0400428* ``forward``
429* ``move``
430* ``move_if_noexcept``
431* ``identity::operator()``
432* ``to_integer``
433* ``to_underlying``
Louis Dionne39948462022-06-01 15:25:14 -0400434
435Additional types supported in random distributions
436~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437
438The `C++ Standard <http://eel.is/c++draft/rand#req.genl-1.5>`_ mentions that instantiating several random number
439distributions with types other than ``short``, ``int``, ``long``, ``long long``, and their unsigned versions is
440undefined. As an extension, libc++ supports instantiating ``binomial_distribution``, ``discrete_distribution``,
441``geometric_distribution``, ``negative_binomial_distribution``, ``poisson_distribution``, and ``uniform_int_distribution``
442with ``int8_t``, ``__int128_t`` and their unsigned versions.