17 Language support library [support] (original) (raw)

17.1 General [support.general]

This Clause describes the function signatures that are called implicitly, and the types of objects generated implicitly, during the execution of some C++ programs.

It also describes the headers that declare these function signatures and define any related types.

The following subclauses describe common type definitions used throughout the library, characteristics of the predefined types, functions supporting start and termination of a C++ program, support for dynamic memory management, support for dynamic type identification, support for exception processing, support for initializer lists, and other runtime support, as summarized in Table 37.

Table 37: Language support library summary [tab:support.summary]

🔗 Subclause Header
🔗 [support.types] Common definitions <cstddef>, <cstdlib>
🔗 [support.limits] Implementation properties <cfloat>, <climits>, <limits>, <version>
🔗 [cstdint] Integer types <cstdint>
🔗 [support.start.term] Start and termination <cstdlib>
🔗 [support.dynamic] Dynamic memory management <new>
🔗 [support.rtti] Type identification <typeinfo>
🔗 [support.srcloc] Source location <source_­location>
🔗 [support.exception] Exception handling <exception>
🔗 [support.initlist] Initializer lists <initializer_­list>
🔗 [cmp] Comparisons <compare>
🔗 [support.coroutine] Coroutines <coroutine>
🔗 [support.runtime] Other runtime support <csetjmp>, <csignal>, <cstdarg>, <cstdlib>

17.2 Common definitions [support.types]

17.2.1 Header synopsis [cstddef.syn]

namespace std { using ptrdiff_t = see below;using size_t = see below;using max_align_t = see below;using nullptr_t = decltype(nullptr);enum class byte : unsigned char {};template<class IntType> constexpr byte& operator<<=(byte& b, IntType shift) noexcept;template<class IntType> constexpr byte operator<<(byte b, IntType shift) noexcept;template<class IntType> constexpr byte& operator>>=(byte& b, IntType shift) noexcept;template<class IntType> constexpr byte operator>>(byte b, IntType shift) noexcept;constexpr byte& operator|=(byte& l, byte r) noexcept;constexpr byte operator|(byte l, byte r) noexcept;constexpr byte& operator&=(byte& l, byte r) noexcept;constexpr byte operator&(byte l, byte r) noexcept;constexpr byte& operator^=(byte& l, byte r) noexcept;constexpr byte operator^(byte l, byte r) noexcept;constexpr byte operator~(byte b) noexcept;template<class IntType> constexpr IntType to_integer(byte b) noexcept;} #define NULL see below #define offsetof(P, D) see below

The contents and meaning of the header are the same as the C standard library header , except that it does not declare the type wchar_­t, that it also declares the type byteand its associated operations ([support.types.byteops]), and as noted in[support.types.nullptr] and[support.types.layout].

17.2.2 Header synopsis [cstdlib.syn]

[Note 1:

Several functions have additional overloads in this document, but they have the same behavior as in the C standard library.

— _end note_]

17.2.3 Null pointers [support.types.nullptr]

The type nullptr_­t is a synonym for the type of a nullptr expression, and it has the characteristics described in [basic.fundamental] and [conv.ptr].

[Note 1:

Although nullptr's address cannot be taken, the address of anothernullptr_­t object that is an lvalue can be taken.

— _end note_]

The macroNULLis an implementation-defined null pointer constant.187

17.2.4 Sizes, alignments, and offsets [support.types.layout]

The macrooffsetof(type, member-designator)has the same semantics as the corresponding macro in the C standard library header , but accepts a restricted set of _type_arguments in this document.

Use of the offsetof macro with a _type_other than a standard-layout class ([class.prop]) is conditionally-supported.188

The expression offsetof(type, member-designator)is never type-dependent and it isvalue-dependent if and only if type is dependent.

The result of applying the offsetof macro to a static data member or a function member is undefined.

No operation invoked by the offsetof macro shall throw an exception andnoexcept(offsetof(type, member-designator)) shall be true.

The type ptrdiff_­t is animplementation-defined signed integer type that can hold the difference of two subscripts in an array object, as described in [expr.add].

The type size_­t is animplementation-defined unsigned integer type that is large enough to contain the size in bytes of any object ([expr.sizeof]).

[Note 1:

It is recommended that implementations choose types for ptrdiff_­t and size_­twhose integer conversion ranks are no greater than that ofsigned long int unless a larger size is necessary to contain all the possible values.

— _end note_]

The typemax_­align_­t is a trivial standard-layout type whose alignment requirement is at least as great as that of every scalar type, and whose alignment requirement is supported in every context ([basic.align]).

17.2.5 byte type operations [support.types.byteops]

template<class IntType> constexpr byte& operator<<=(byte& b, IntType shift) noexcept;

Constraints: is_­integral_­v<IntType> is true.

Effects: Equivalent to:return b = b << shift;

template<class IntType> constexpr byte operator<<(byte b, IntType shift) noexcept;

Constraints: is_­integral_­v<IntType> is true.

Effects: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(b) << shift);

template<class IntType> constexpr byte& operator>>=(byte& b, IntType shift) noexcept;

Constraints: is_­integral_­v<IntType> is true.

Effects: Equivalent to:return b = b >> shift;

template<class IntType> constexpr byte operator>>(byte b, IntType shift) noexcept;

Constraints: is_­integral_­v<IntType> is true.

Effects: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(b) >> shift);

constexpr byte& operator|=(byte& l, byte r) noexcept;

Effects: Equivalent to: return l = l | r;

constexpr byte operator|(byte l, byte r) noexcept;

Effects: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) | static_cast<unsigned int>(r));

constexpr byte& operator&=(byte& l, byte r) noexcept;

Effects: Equivalent to: return l = l & r;

constexpr byte operator&(byte l, byte r) noexcept;

Effects: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) & static_cast<unsigned int>(r));

constexpr byte& operator^=(byte& l, byte r) noexcept;

Effects: Equivalent to: return l = l ^ r;

constexpr byte operator^(byte l, byte r) noexcept;

Effects: Equivalent to:return static_cast<byte>(static_cast<unsigned int>(l) ^ static_cast<unsigned int>(r));

constexpr byte operator~(byte b) noexcept;

Effects: Equivalent to:return static_cast<byte>(~static_cast<unsigned int>(b));

template<class IntType> constexpr IntType to_integer(byte b) noexcept;

Constraints: is_­integral_­v<IntType> is true.

Effects: Equivalent to: return static_­cast<IntType>(b);

17.3 Implementation properties [support.limits]

17.3.2 Header synopsis [version.syn]

The header supplies implementation-dependent information about the C++ standard library (e.g., version number and release date).

Each of the macros defined in is also defined after inclusion of any member of the set of library headers indicated in the corresponding comment in this synopsis.

[Note 1:

Future revisions of C++ might replace the values of these macros with greater values.

— _end note_]

#define __cpp_­lib_­addressof_­constexpr 201603L #define __cpp_­lib_­allocator_­traits_­is_­always_­equal 201411L #define __cpp_­lib_­any 201606L #define __cpp_­lib_­apply 201603L #define __cpp_­lib_­array_­constexpr 201811L #define __cpp_­lib_­as_­const 201510L #define __cpp_­lib_­assume_­aligned 201811L #define __cpp_­lib_­atomic_­flag_­test 201907L #define __cpp_­lib_­atomic_­float 201711L #define __cpp_­lib_­atomic_­is_­always_­lock_­free 201603L #define __cpp_­lib_­atomic_­lock_­free_­type_­aliases 201907L #define __cpp_­lib_­atomic_­ref 201806L #define __cpp_­lib_­atomic_­shared_­ptr 201711L #define __cpp_­lib_­atomic_­value_­initialization 201911L #define __cpp_­lib_­atomic_­wait 201907L #define __cpp_­lib_­barrier 201907L #define __cpp_­lib_­bind_­front 201907L #define __cpp_­lib_­bit_­cast 201806L #define __cpp_­lib_­bitops 201907L #define __cpp_­lib_­bool_­constant 201505L #define __cpp_­lib_­bounded_­array_­traits 201902L #define __cpp_­lib_­boyer_­moore_­searcher 201603L #define __cpp_­lib_­byte 201603L #define __cpp_­lib_­char8_­t 201907L #define __cpp_­lib_­chrono 201907L #define __cpp_­lib_­chrono_­udls 201304L #define __cpp_­lib_­clamp 201603L #define __cpp_­lib_­complex_­udls 201309L #define __cpp_­lib_­concepts 202002L #define __cpp_­lib_­constexpr_­algorithms 201806L #define __cpp_­lib_­constexpr_­complex 201711L #define __cpp_­lib_­constexpr_­dynamic_­alloc 201907L #define __cpp_­lib_­constexpr_­functional 201907L #define __cpp_­lib_­constexpr_­iterator 201811L #define __cpp_­lib_­constexpr_­memory 201811L #define __cpp_­lib_­constexpr_­numeric 201911L #define __cpp_­lib_­constexpr_­string 201907L #define __cpp_­lib_­constexpr_­string_­view 201811L #define __cpp_­lib_­constexpr_­tuple 201811L #define __cpp_­lib_­constexpr_­utility 201811L #define __cpp_­lib_­constexpr_­vector 201907L #define __cpp_­lib_­coroutine 201902L #define __cpp_­lib_­destroying_­delete 201806L #define __cpp_­lib_­enable_­shared_­from_­this 201603L #define __cpp_­lib_­endian 201907L #define __cpp_­lib_­erase_­if 202002L #define __cpp_­lib_­exchange_­function 201304L #define __cpp_­lib_­execution 201902L #define __cpp_­lib_­filesystem 201703L #define __cpp_­lib_­format 201907L #define __cpp_­lib_­gcd_­lcm 201606L #define __cpp_­lib_­generic_­associative_­lookup 201304L #define __cpp_­lib_­generic_­unordered_­lookup 201811L #define __cpp_­lib_­hardware_­interference_­size 201703L #define __cpp_­lib_­has_­unique_­object_­representations 201606L #define __cpp_­lib_­hypot 201603L #define __cpp_­lib_­incomplete_­container_­elements 201505L #define __cpp_­lib_­int_­pow2 202002L #define __cpp_­lib_­integer_­comparison_­functions 202002L #define __cpp_­lib_­integer_­sequence 201304L #define __cpp_­lib_­integral_­constant_­callable 201304L #define __cpp_­lib_­interpolate 201902L #define __cpp_­lib_­invoke 201411L #define __cpp_­lib_­is_­aggregate 201703L #define __cpp_­lib_­is_­constant_­evaluated 201811L #define __cpp_­lib_­is_­final 201402L #define __cpp_­lib_­is_­invocable 201703L #define __cpp_­lib_­is_­layout_­compatible 201907L #define __cpp_­lib_­is_­nothrow_­convertible 201806L #define __cpp_­lib_­is_­null_­pointer 201309L #define __cpp_­lib_­is_­pointer_­interconvertible 201907L #define __cpp_­lib_­is_­swappable 201603L #define __cpp_­lib_­jthread 201911L #define __cpp_­lib_­latch 201907L #define __cpp_­lib_­launder 201606L #define __cpp_­lib_­list_­remove_­return_­type 201806L #define __cpp_­lib_­logical_­traits 201510L #define __cpp_­lib_­make_­from_­tuple 201606L #define __cpp_­lib_­make_­reverse_­iterator 201402L #define __cpp_­lib_­make_­unique 201304L #define __cpp_­lib_­map_­try_­emplace 201411L #define __cpp_­lib_­math_­constants 201907L #define __cpp_­lib_­math_­special_­functions 201603L #define __cpp_­lib_­memory_­resource 201603L #define 201606L #define __cpp_­lib_­nonmember_­container_­access 201411L #define __cpp_­lib_­not_­fn 201603L #define __cpp_­lib_­null_­iterators 201304L #define __cpp_­lib_­optional 201606L #define __cpp_­lib_­parallel_­algorithm 201603L #define __cpp_­lib_­polymorphic_­allocator 201902L #define __cpp_­lib_­quoted_­string_­io 201304L #define __cpp_­lib_­ranges 201911L #define __cpp_­lib_­raw_­memory_­algorithms 201606L #define __cpp_­lib_­remove_­cvref 201711L #define __cpp_­lib_­result_­of_­sfinae 201210L #define __cpp_­lib_­robust_­nonmodifying_­seq_­ops 201304L #define __cpp_­lib_­sample 201603L #define __cpp_­lib_­scoped_­lock 201703L #define __cpp_­lib_­semaphore 201907L #define __cpp_­lib_­shared_­mutex 201505L #define __cpp_­lib_­shared_­ptr_­arrays 201707L #define __cpp_­lib_­shared_­ptr_­weak_­type 201606L #define __cpp_­lib_­shared_­timed_­mutex 201402L #define __cpp_­lib_­shift 201806L #define __cpp_­lib_­smart_­ptr_­for_­overwrite 202002L #define __cpp_­lib_­source_­location 201907L #define __cpp_­lib_­span 202002L #define __cpp_­lib_­ssize 201902L #define __cpp_­lib_­starts_­ends_­with 201711L #define __cpp_­lib_­string_­udls 201304L #define __cpp_­lib_­string_­view 201803L #define __cpp_­lib_­syncbuf 201803L #define __cpp_­lib_­three_­way_­comparison 201907L #define __cpp_­lib_­to_­address 201711L #define __cpp_­lib_­to_­array 201907L #define __cpp_­lib_­to_­chars 201611L #define __cpp_­lib_­transformation_­trait_­aliases 201304L #define __cpp_­lib_­transparent_­operators 201510L #define __cpp_­lib_­tuple_­element_­t 201402L #define __cpp_­lib_­tuples_­by_­type 201304L #define __cpp_­lib_­type_­identity 201806L #define __cpp_­lib_­type_­trait_­variable_­templates 201510L #define __cpp_­lib_­uncaught_­exceptions 201411L #define __cpp_­lib_­unordered_­map_­try_­emplace 201411L #define __cpp_­lib_­unwrap_­ref 201811L #define __cpp_­lib_­variant 201606L #define __cpp_­lib_­void_­t 201411L

17.3.3 Header synopsis [limits.syn]

namespace std { enum float_round_style;enum float_denorm_style;template<class T> class numeric_limits;template<class T> class numeric_limits<const T>;template<class T> class numeric_limits<volatile T>;template<class T> class numeric_limits<const volatile T>;template<> class numeric_limits<bool>;template<> class numeric_limits<char>;template<> class numeric_limits<signed char>;template<> class numeric_limits<unsigned char>;template<> class numeric_limits<char8_t>;template<> class numeric_limits<char16_t>;template<> class numeric_limits<char32_t>;template<> class numeric_limits<wchar_t>;template<> class numeric_limits<short>;template<> class numeric_limits<int>;template<> class numeric_limits<long>;template<> class numeric_limits<long long>;template<> class numeric_limits<unsigned short>;template<> class numeric_limits<unsigned int>;template<> class numeric_limits<unsigned long>;template<> class numeric_limits<unsigned long long>;template<> class numeric_limits<float>;template<> class numeric_limits<double>;template<> class numeric_limits<long double>;}

17.3.4 Floating-point type properties [fp.style]

17.3.4.1 Type float_­round_­style [round.style]

namespace std { enum float_round_style { round_indeterminate = -1, round_toward_zero = 0, round_to_nearest = 1, round_toward_infinity = 2, round_toward_neg_infinity = 3 };}

The rounding mode for floating-point arithmetic is characterized by the values:

17.3.4.2 Type float_­denorm_­style [denorm.style]

namespace std { enum float_denorm_style { denorm_indeterminate = -1, denorm_absent = 0, denorm_present = 1 };}

The presence or absence of subnormal numbers (variable number of exponent bits) is characterized by the values:

17.3.5 Class template numeric_­limits [numeric.limits]

17.3.5.1 General [numeric.limits.general]

Thenumeric_­limitsclass template provides a C++ program with information about various properties of the implementation's representation of the arithmetic types.

namespace std { template<class T> class numeric_limits { public: static constexpr bool is_specialized = false;static constexpr T min() noexcept { return T(); } static constexpr T max() noexcept { return T(); } static constexpr T lowest() noexcept { return T(); } static constexpr int digits = 0;static constexpr int digits10 = 0;static constexpr int max_digits10 = 0;static constexpr bool is_signed = false;static constexpr bool is_integer = false;static constexpr bool is_exact = false;static constexpr int radix = 0;static constexpr T epsilon() noexcept { return T(); } static constexpr T round_error() noexcept { return T(); } static constexpr int min_exponent = 0;static constexpr int min_exponent10 = 0;static constexpr int max_exponent = 0;static constexpr int max_exponent10 = 0;static constexpr bool has_infinity = false;static constexpr bool has_quiet_NaN = false;static constexpr bool has_signaling_NaN = false;static constexpr float_denorm_style has_denorm = denorm_absent;static constexpr bool has_denorm_loss = false;static constexpr T infinity() noexcept { return T(); } static constexpr T quiet_NaN() noexcept { return T(); } static constexpr T signaling_NaN() noexcept { return T(); } static constexpr T denorm_min() noexcept { return T(); } static constexpr bool is_iec559 = false;static constexpr bool is_bounded = false;static constexpr bool is_modulo = false;static constexpr bool traps = false;static constexpr bool tinyness_before = false;static constexpr float_round_style round_style = round_toward_zero;};}

For all members declaredstatic constexprin thenumeric_­limitstemplate, specializations shall define these values in such a way that they are usable as constant expressions.

For thenumeric_­limitsprimary template, all data members are value-initialized and all member functions return a value-initialized object.

[Note 1:

This means all members have zero or false values unless numeric_­limits is specialized for a type.

— _end note_]

Specializations shall be provided for each arithmetic type, both floating-point and integer, includingbool.

The memberis_­specializedshall betruefor all such specializations ofnumeric_­limits.

The value of each member of a specialization ofnumeric_­limits on a cv-qualified typecv T shall be equal to the value of the corresponding member of the specialization on the unqualified type T.

Non-arithmetic standard types, such ascomplex, shall not have specializations.

17.3.5.2 numeric_­limits members [numeric.limits.members]

Each member function defined in this subclause is signal-safe.

static constexpr T min() noexcept;

For floating-point types with subnormal numbers, returns the minimum positive normalized value.

Meaningful for all specializations in whichis_­bounded != false, oris_­bounded == false && is_­signed == false.

static constexpr T max() noexcept;

Meaningful for all specializations in whichis_­bounded != false.

static constexpr T lowest() noexcept;

A finite value x such that there is no other finite value y where y < x.191

Meaningful for all specializations in which is_­bounded != false.

static constexpr int digits;

Number ofradixdigits that can be represented without change.

For integer types, the number of non-sign bits in the representation.

For floating-point types, the number of radix digits in the mantissa.192

static constexpr int digits10;

Number of base 10 digits that can be represented without change.193

Meaningful for all specializations in whichis_­bounded != false.

static constexpr int max_digits10;

Number of base 10 digits required to ensure that values which differ are always differentiated.

Meaningful for all floating-point types.

static constexpr bool is_signed;

true if the type is signed.

Meaningful for all specializations.

static constexpr bool is_integer;

true if the type is integer.

Meaningful for all specializations.

static constexpr bool is_exact;

true if the type uses an exact representation.

All integer types are exact, but not all exact types are integer.

For example, rational and fixed-exponent representations are exact but not integer.

Meaningful for all specializations.

static constexpr int radix;

For floating-point types, specifies the base or radix of the exponent representation (often 2).194

For integer types, specifies the base of the representation.195

Meaningful for all specializations.

static constexpr T epsilon() noexcept;

Machine epsilon: the difference between 1 and the least value greater than 1 that is representable.196

Meaningful for all floating-point types.

static constexpr T round_error() noexcept;

Measure of the maximum rounding error.197

static constexpr int min_exponent;

Minimum negative integer such thatradixraised to the power of one less than that integer is a normalized floating-point number.198

Meaningful for all floating-point types.

static constexpr int min_exponent10;

Minimum negative integer such that 10 raised to that power is in the range of normalized floating-point numbers.199

Meaningful for all floating-point types.

static constexpr int max_exponent;

Maximum positive integer such thatradixraised to the power one less than that integer is a representable finite floating-point number.200

Meaningful for all floating-point types.

static constexpr int max_exponent10;

Maximum positive integer such that 10 raised to that power is in the range of representable finite floating-point numbers.201

Meaningful for all floating-point types.

static constexpr bool has_infinity;

true if the type has a representation for positive infinity.

Meaningful for all floating-point types.

Shall betruefor all specializations in whichis_­iec559 != false.

static constexpr bool has_quiet_NaN;

true if the type has a representation for a quiet (non-signaling) “Not a Number”.202

Meaningful for all floating-point types.

Shall betruefor all specializations in whichis_­iec559 != false.

static constexpr bool has_signaling_NaN;

true if the type has a representation for a signaling “Not a Number”.203

Meaningful for all floating-point types.

Shall betruefor all specializations in whichis_­iec559 != false.

static constexpr float_denorm_style has_denorm;

denorm_­presentif the type allows subnormal values (variable number of exponent bits)204,denorm_­absentif the type does not allow subnormal values, anddenorm_­indeterminateif it is indeterminate at compile time whether the type allows subnormal values.

Meaningful for all floating-point types.

static constexpr bool has_denorm_loss;

true if loss of accuracy is detected as a denormalization loss, rather than as an inexact result.205

static constexpr T infinity() noexcept;

Representation of positive infinity, if available.206

Meaningful for all specializations for whichhas_­infinity != false.

Required in specializations for whichis_­iec559 != false.

static constexpr T quiet_NaN() noexcept;

Representation of a quiet “Not a Number”, if available.207

Meaningful for all specializations for whichhas_­quiet_­NaN != false.

Required in specializations for whichis_­iec559 != false.

static constexpr T signaling_NaN() noexcept;

Representation of a signaling “Not a Number”, if available.208

Meaningful for all specializations for whichhas_­signaling_­NaN != false.

Required in specializations for whichis_­iec559 != false.

static constexpr T denorm_min() noexcept;

Minimum positive subnormal value.209

Meaningful for all floating-point types.

In specializations for whichhas_­denorm == false, returns the minimum positive normalized value.

static constexpr bool is_iec559;

true if and only if the type adheres to ISO/IEC/IEEE 60559.210

Meaningful for all floating-point types.

static constexpr bool is_bounded;

true if the set of values representable by the type is finite.211

[Note 1:

This member would be false for arbitrary precision types.

— _end note_]

Meaningful for all specializations.

static constexpr bool is_modulo;

true if the type is modulo.212

A type is modulo if, for any operation involving +, -, or* on values of that type whose result would fall outside the range [min(), max()], the value returned differs from the true value by an integer multiple of max() - min() + 1.

[Example 1:

is_­modulo is false for signed integer types ([basic.fundamental]) unless an implementation, as an extension to this document, defines signed integer overflow to wrap.

— _end example_]

Meaningful for all specializations.

static constexpr bool traps;

trueif, at the start of the program, there exists a value of the type that would cause an arithmetic operation using that value to trap.213

Meaningful for all specializations.

static constexpr bool tinyness_before;

trueif tinyness is detected before rounding.214

Meaningful for all floating-point types.

static constexpr float_round_style round_style;

The rounding style for the type.215

Meaningful for all floating-point types.

Specializations for integer types shall returnround_­toward_­zero.

17.3.5.3 numeric_­limits specializations [numeric.special]

All members shall be provided for all specializations.

However, many values are only required to be meaningful under certain conditions (for example,epsilon()is only meaningful ifis_­integerisfalse).

Any value that is not “meaningful” shall be set to 0 orfalse.

[Example 1: namespace std { template<> class numeric_limits<float> { public: static constexpr bool is_specialized = true;static constexpr float min() noexcept { return 1.17549435E-38F; } static constexpr float max() noexcept { return 3.40282347E+38F; } static constexpr float lowest() noexcept { return -3.40282347E+38F; } static constexpr int digits = 24;static constexpr int digits10 = 6;static constexpr int max_digits10 = 9;static constexpr bool is_signed = true;static constexpr bool is_integer = false;static constexpr bool is_exact = false;static constexpr int radix = 2;static constexpr float epsilon() noexcept { return 1.19209290E-07F; } static constexpr float round_error() noexcept { return 0.5F; } static constexpr int min_exponent = -125;static constexpr int min_exponent10 = - 37;static constexpr int max_exponent = +128;static constexpr int max_exponent10 = + 38;static constexpr bool has_infinity = true;static constexpr bool has_quiet_NaN = true;static constexpr bool has_signaling_NaN = true;static constexpr float_denorm_style has_denorm = denorm_absent;static constexpr bool has_denorm_loss = false;static constexpr float infinity() noexcept { return value; } static constexpr float quiet_NaN() noexcept { return value; } static constexpr float signaling_NaN() noexcept { return value; } static constexpr float denorm_min() noexcept { return min(); } static constexpr bool is_iec559 = true;static constexpr bool is_bounded = true;static constexpr bool is_modulo = false;static constexpr bool traps = true;static constexpr bool tinyness_before = true;static constexpr float_round_style round_style = round_to_nearest;};} — _end example_]

The specialization forboolshall be provided as follows:namespace std { template<> class numeric_limits<bool> { public: static constexpr bool is_specialized = true;static constexpr bool min() noexcept { return false; } static constexpr bool max() noexcept { return true; } static constexpr bool lowest() noexcept { return false; } static constexpr int digits = 1;static constexpr int digits10 = 0;static constexpr int max_digits10 = 0;static constexpr bool is_signed = false;static constexpr bool is_integer = true;static constexpr bool is_exact = true;static constexpr int radix = 2;static constexpr bool epsilon() noexcept { return 0; } static constexpr bool round_error() noexcept { return 0; } static constexpr int min_exponent = 0;static constexpr int min_exponent10 = 0;static constexpr int max_exponent = 0;static constexpr int max_exponent10 = 0;static constexpr bool has_infinity = false;static constexpr bool has_quiet_NaN = false;static constexpr bool has_signaling_NaN = false;static constexpr float_denorm_style has_denorm = denorm_absent;static constexpr bool has_denorm_loss = false;static constexpr bool infinity() noexcept { return 0; } static constexpr bool quiet_NaN() noexcept { return 0; } static constexpr bool signaling_NaN() noexcept { return 0; } static constexpr bool denorm_min() noexcept { return 0; } static constexpr bool is_iec559 = false;static constexpr bool is_bounded = true;static constexpr bool is_modulo = false;static constexpr bool traps = false;static constexpr bool tinyness_before = false;static constexpr float_round_style round_style = round_toward_zero;};}

17.3.6 Header synopsis [climits.syn]

The header defines all macros the same as the C standard library header .

[Note 1:

The types of the constants defined by macros in are not required to match the types to which the macros refer.

— _end note_]

See also: ISO C 5.2.4.2.1

17.3.7 Header synopsis [cfloat.syn]

The header defines all macros the same as the C standard library header .

See also: ISO C 5.2.4.2.2

17.4 Integer types [cstdint]

17.4.1 General [cstdint.general]

The headersupplies integer types having specified widths, and macros that specify limits of integer types.

17.4.2 Header synopsis [cstdint.syn]

The header also defines numerous macros of the form:

INT_[FAST LEAST]{8 16 32 64}MIN [U]INT[FAST LEAST]{8 16 32 64}_MAX INT{MAX PTR}_MIN [U]INT{MAX PTR}_MAX {PTRDIFF SIG_ATOMIC WCHAR WINT}{_MAX _MIN} SIZE_MAX

plus function macros of the form:

[U]INT{8 16 32 64 MAX}_C

The header defines all types and macros the same as the C standard library header .

17.5 Startup and termination [support.start.term]

[Note 1:

The header declares the functions described in this subclause.

— _end note_]

[[noreturn]] void _Exit(int status) noexcept;

Effects: This function has the semantics specified in the C standard library.

Remarks: The program is terminated without executing destructors for objects of automatic, thread, or static storage duration and without calling functions passed toatexit() ([basic.start.term]).

The function _­Exit is signal-safe.

[[noreturn]] void abort() noexcept;

Effects: This function has the semantics specified in the C standard library.

Remarks: The program is terminated without executing destructors for objects of automatic, thread, or static storage duration and without calling functions passed toatexit() ([basic.start.term]).

The function abort is signal-safe.

int atexit(_c-atexit-handler_* f) noexcept;int atexit(_atexit-handler_* f) noexcept;

Effects: Theatexit()functions register the function pointed to by fto be called without arguments at normal program termination.

It is unspecified whether a call to atexit() that does nothappen beforea call to exit() will succeed.

Implementation limits: The implementation shall support the registration of at least 32 functions.

Returns: Theatexit()function returns zero if the registration succeeds, nonzero if it fails.

[[noreturn]] void exit(int status);

Effects:

int at_quick_exit(_c-atexit-handler_* f) noexcept;int at_quick_exit(_atexit-handler_* f) noexcept;

Effects: The at_­quick_­exit() functions register the function pointed to by fto be called without arguments when quick_­exit is called.

It is unspecified whether a call to at_­quick_­exit() that does nothappen beforeall calls to quick_­exit will succeed.

[Note 3:

Theat_­quick_­exit() functions do not introduce a data race ([res.on.data.races]).

— _end note_]

[Note 4:

The order of registration could be indeterminate if at_­quick_­exit was called from more than one thread.

— _end note_]

[Note 5:

Theat_­quick_­exit registrations are distinct from the atexit registrations, and applications might need to call both registration functions with the same argument.

— _end note_]

Implementation limits: The implementation shall support the registration of at least 32 functions.

Returns: Zero if the registration succeeds, nonzero if it fails.

[[noreturn]] void quick_exit(int status) noexcept;

Effects: Functions registered by calls to at_­quick_­exit are called in the reverse order of their registration, except that a function shall be called after any previously registered functions that had already been called at the time it was registered.

Objects shall not be destroyed as a result of calling quick_­exit.

If control leaves a registered function called by quick_­exit because the function does not provide a handler for a thrown exception, the function std​::​terminate shall be called.

[Note 6:

A function registered via at_­quick_­exitis invoked by the thread that calls quick_­exit, which can be a different thread than the one that registered it, so registered functions cannot rely on the identity of objects with thread storage duration.

— _end note_]

After calling registered functions, quick_­exit shall call _­Exit(status).

Remarks: The function quick_­exit is signal-safewhen the functions registered with at_­quick_­exit are.

17.6 Dynamic memory management [support.dynamic]

17.6.1 General [support.dynamic.general]

The header defines several functions that manage the allocation of dynamic storage in a program.

It also defines components for reporting storage management errors.

17.6.2 Header synopsis [new.syn]

namespace std { class bad_alloc;class bad_array_new_length;struct destroying_delete_t { explicit destroying_delete_t() = default;};inline constexpr destroying_delete_t destroying_delete{};enum class align_val_t : size_t {};struct nothrow_t { explicit nothrow_t() = default; };extern const nothrow_t nothrow;using new_handler = void (*)(); new_handler get_new_handler() noexcept; new_handler set_new_handler(new_handler new_p) noexcept;template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;inline constexpr size_t hardware_destructive_interference_size = implementation-defined;inline constexpr size_t hardware_constructive_interference_size = implementation-defined;} [[nodiscard]] void* operator new(std::size_t size);[[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment);[[nodiscard]] void* operator new(std::size_t size, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment,const std::nothrow_t&) noexcept;void operator delete(void* ptr) noexcept;void operator delete(void* ptr, std::size_t size) noexcept;void operator delete(void* ptr, std::align_val_t alignment) noexcept;void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;void operator delete(void* ptr, const std::nothrow_t&) noexcept;void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new[](std::size_t size);[[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment);[[nodiscard]] void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment,const std::nothrow_t&) noexcept;void operator delete[](void* ptr) noexcept;void operator delete[](void* ptr, std::size_t size) noexcept;void operator delete[](void* ptr, std::align_val_t alignment) noexcept;void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;void operator delete[](void* ptr, const std::nothrow_t&) noexcept;void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new (std::size_t size, void* ptr) noexcept;[[nodiscard]] void* operator new[](std::size_t size, void* ptr) noexcept;void operator delete (void* ptr, void*) noexcept;void operator delete[](void* ptr, void*) noexcept;

17.6.3 Storage allocation and deallocation [new.delete]

17.6.3.1 General [new.delete.general]

Except where otherwise specified, the provisions of [basic.stc.dynamic]apply to the library versions of operator new and operator delete.

If the value of an alignment argument passed to any of these functions is not a valid alignment value, the behavior is undefined.

17.6.3.2 Single-object forms [new.delete.single]

[[nodiscard]] void* operator new(std::size_t size);[[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment);

The second form is called for a type with new-extended alignment, and the first form is called otherwise.

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Required behavior: Return a non-null pointer to suitably aligned storage ([basic.stc.dynamic]), or else throw abad_­alloc exception.

This requirement is binding on any replacement versions of these functions.

Default behavior:

[[nodiscard]] void* operator new(std::size_t size, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new(std::size_t size, std::align_val_t alignment,const std::nothrow_t&) noexcept;

Effects: Same as above, except that these are called by a placement version of anew-expressionwhen a C++ program prefers a null pointer result as an error indication, instead of abad_­allocexception.

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Required behavior: Return a non-null pointer to suitably aligned storage ([basic.stc.dynamic]), or else return a null pointer.

Each of these nothrow versions ofoperator newreturns a pointer obtained as if acquired from the (possibly replaced) corresponding non-placement function.

This requirement is binding on any replacement versions of these functions.

Default behavior: Calls operator new(size), or operator new(size, alignment), respectively.

If the call returns normally, returns the result of that call.

Otherwise, returns a null pointer.

[Example 1: T* p1 = new T; T* p2 = new(nothrow) T; — _end example_]

void operator delete(void* ptr) noexcept;void operator delete(void* ptr, std::size_t size) noexcept;void operator delete(void* ptr, std::align_val_t alignment) noexcept;void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;

Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced)operator new(std​::​size_­t)oroperator new(std​::​size_­t, std​::​align_­val_­t)which has not been invalidated by an intervening call tooperator delete.

If the alignment parameter is not present,ptr was returned by an allocation function without an alignment parameter.

If present, the alignment argument is equal to the alignment argument passed to the allocation function that returned ptr.

If present, the size argument is equal to the size argument passed to the allocation function that returned ptr.

Replaceable: A C++ program may define functions with any of these function signatures, and thereby displace the default versions defined by the C++ standard library.

If a function without a size parameter is defined, the program should also define the corresponding function with a size parameter.

If a function with a size parameter is defined, the program shall also define the corresponding version without the size parameter.

[Note 1:

The default behavior below might change in the future, which will require replacing both deallocation functions when replacing the allocation function.

— _end note_]

Required behavior: A call to an operator deletewith a size parameter may be changed to a call to the corresponding operator deletewithout a size parameter, without affecting memory allocation.

[Note 2:

A conforming implementation is foroperator delete(void* ptr, std​::​size_­t size) to simply calloperator delete(ptr).

— _end note_]

Default behavior: The functions that have a size parameter forward their other parameters to the corresponding function without a size parameter.

[Note 3:

See the note in the above Replaceable: paragraph.

— _end note_]

Default behavior: If ptr is null, does nothing.

Otherwise, reclaims the storage allocated by the earlier call to operator new.

Remarks: It is unspecified under what conditions part or all of suchreclaimed storage will be allocated by subsequent calls tooperator newor any ofaligned_­alloc,calloc,malloc, orrealloc, declared in .

void operator delete(void* ptr, const std::nothrow_t&) noexcept;void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;

Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced)operator new(std​::​size_­t)oroperator new(std​::​size_­t, std​::​align_­val_­t)which has not been invalidated by an intervening call tooperator delete.

If the alignment parameter is not present,ptr was returned by an allocation function without an alignment parameter.

If present, the alignment argument is equal to the alignment argument passed to the allocation function that returned ptr.

Effects: The deallocation functions ([basic.stc.dynamic.deallocation]) called by the implementation to render the value of ptr invalid when the constructor invoked from a nothrow placement version of the new-expression throws an exception.

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Default behavior: Calls operator delete(ptr), or operator delete(ptr, alignment), respectively.

17.6.3.3 Array forms [new.delete.array]

[[nodiscard]] void* operator new[](std::size_t size);[[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment);

The second form is called for a type with new-extended alignment, and the first form is called otherwise.219

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Required behavior: Same as for the corresponding single-object forms.

This requirement is binding on any replacement versions of these functions.

Default behavior: Returnsoperator new(size), oroperator new(size, alignment), respectively.

[[nodiscard]] void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;[[nodiscard]] void* operator new[](std::size_t size, std::align_val_t alignment,const std::nothrow_t&) noexcept;

Effects: Same as above, except that these are called by a placement version of anew-expressionwhen a C++ program prefers a null pointer result as an error indication, instead of abad_­allocexception.

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Required behavior: Return a non-null pointer to suitably aligned storage ([basic.stc.dynamic]), or else return a null pointer.

Each of these nothrow versions ofoperator new[]returns a pointer obtained as if acquired from the (possibly replaced) corresponding non-placement function.

This requirement is binding on any replacement versions of these functions.

Default behavior: Calls operator new[](size), or operator new[](size, alignment), respectively.

If the call returns normally, returns the result of that call.

Otherwise, returns a null pointer.

void operator delete[](void* ptr) noexcept;void operator delete[](void* ptr, std::size_t size) noexcept;void operator delete[](void* ptr, std::align_val_t alignment) noexcept;void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;

Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced)operator new[](std​::​size_­t)oroperator new[](std​::​size_­t, std​::​align_­val_­t)which has not been invalidated by an intervening call tooperator delete[].

If the alignment parameter is not present,ptr was returned by an allocation function without an alignment parameter.

If present, the alignment argument is equal to the alignment argument passed to the allocation function that returned ptr.

If present, the size argument is equal to the size argument passed to the allocation function that returned ptr.

Replaceable: A C++ program may define functions with any of these function signatures, and thereby displace the default versions defined by the C++ standard library.

If a function without a size parameter is defined, the program should also define the corresponding function with a size parameter.

If a function with a size parameter is defined, the program shall also define the corresponding version without the size parameter.

[Note 1:

The default behavior below might change in the future, which will require replacing both deallocation functions when replacing the allocation function.

— _end note_]

Required behavior: A call to an operator delete[]with a size parameter may be changed to a call to the corresponding operator delete[]without a size parameter, without affecting memory allocation.

[Note 2:

A conforming implementation is foroperator delete[](void* ptr, std​::​size_­t size) to simply calloperator delete[](ptr).

— _end note_]

Default behavior: The functions that have a size parameter forward their other parameters to the corresponding function without a size parameter.

The functions that do not have a size parameter forward their parameters to the corresponding operator delete (single-object) function.

void operator delete[](void* ptr, const std::nothrow_t&) noexcept;void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;

Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced)operator new[](std​::​size_­t)oroperator new[](std​::​size_­t, std​::​align_­val_­t)which has not been invalidated by an intervening call tooperator delete[].

If the alignment parameter is not present,ptr was returned by an allocation function without an alignment parameter.

If present, the alignment argument is equal to the alignment argument passed to the allocation function that returned ptr.

Effects: The deallocation functions ([basic.stc.dynamic.deallocation]) called by the implementation to render the value of ptr invalid when the constructor invoked from a nothrow placement version of the array new-expression throws an exception.

Replaceable: A C++ program may define functions with either of these function signatures, and thereby displace the default versions defined by the C++ standard library.

Default behavior: Calls operator delete[](ptr), or operator delete[](ptr, alignment), respectively.

17.6.3.4 Non-allocating forms [new.delete.placement]

These functions are reserved; a C++ program may not define functions that displace the versions in the C++ standard library ([constraints]).

The provisions of [basic.stc.dynamic] do not apply to these reserved placement forms of operator new and operator delete.

[[nodiscard]] void* operator new(std::size_t size, void* ptr) noexcept;

Remarks: Intentionally performs no other action.

[Example 1:

This can be useful for constructing an object at a known address:void* place = operator new(sizeof(Something)); Something* p = new (place) Something();

— _end example_]

[[nodiscard]] void* operator new[](std::size_t size, void* ptr) noexcept;

Remarks: Intentionally performs no other action.

void operator delete(void* ptr, void*) noexcept;

Effects: Intentionally performs no action.

Remarks: Default function called when any part of the initialization in a placement new-expression that invokes the library's non-array placement operator new terminates by throwing an exception ([expr.new]).

void operator delete[](void* ptr, void*) noexcept;

Effects: Intentionally performs no action.

Remarks: Default function called when any part of the initialization in a placement new-expression that invokes the library's array placement operator new terminates by throwing an exception ([expr.new]).

17.6.3.5 Data races [new.delete.dataraces]

For purposes of determining the existence of data races, the library versions of operator new, user replacement versions of global operator new, the C standard library functionsaligned_­alloc, calloc, and malloc, the library versions of operator delete, user replacement versions of operator delete, the C standard library functionfree, and the C standard library function realloc shall not introduce a data race ([res.on.data.races]).

Calls to these functions that allocate or deallocate a particular unit of storage shall occur in a single total order, and each such deallocation call shall happen beforethe next allocation (if any) in this order.

17.6.4 Storage allocation errors [alloc.errors]

17.6.4.1 Class bad_­alloc [bad.alloc]

namespace std { class bad_alloc : public exception { public: const char* what() const noexcept override;};}

The classbad_­allocdefines the type of objects thrown as exceptions by the implementation to report a failure to allocate storage.

const char* what() const noexcept override;

Returns: An implementation-defined ntbs.

17.6.4.2 Class bad_­array_­new_­length [new.badlength]

namespace std { class bad_array_new_length : public bad_alloc { public: const char* what() const noexcept override;};}

The class bad_­array_­new_­length defines the type of objects thrown as exceptions by the implementation to report an attempt to allocate an array of size less than zero or greater than an implementation-defined limit ([expr.new]).

const char* what() const noexcept override;

Returns: An implementation-defined ntbs.

17.6.4.3 Type new_­handler [new.handler]

using new_handler = void (*)();

The type of ahandler functionto be called byoperator new()oroperator new[]() ([new.delete]) when they cannot satisfy a request for additional storage.

Required behavior: A new_­handler shall perform one of the following:

17.6.4.4 set_­new_­handler [set.new.handler]

new_handler set_new_handler(new_handler new_p) noexcept;

Effects: Establishes the function designated by new_­p as the currentnew_­handler.

Returns: The previous new_­handler.

Remarks: The initial new_­handler is a null pointer.

17.6.4.5 get_­new_­handler [get.new.handler]

new_handler get_new_handler() noexcept;

Returns: The current new_­handler.

[Note 1:

This can be a null pointer value.

— _end note_]

17.6.5 Pointer optimization barrier [ptr.launder]

template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;

Mandates: !is_­function_­v<T> && !is_­void_­v<T> is true.

Preconditions: p represents the address A of a byte in memory.

An object X that is within its lifetimeand whose type is similar to Tis located at the address A.

All bytes of storage that would be reachable through the result are reachable through p (see below).

Returns: A value of type T* that points to X.

Remarks: An invocation of this function may be used in a core constant expression whenever the value of its argument may be used in a core constant expression.

A byte of storage b is reachable through a pointer value that points to an object Y_if there is an object Z, pointer-interconvertible with Y, such that b is within the storage occupied by_Z, or the immediately-enclosing array object if Z is an array element.

[Note 1:

If a new object is created in storage occupied by an existing object of the same type, a pointer to the original object can be used to refer to the new object unless its complete object is a const object or it is a base class subobject; in the latter cases, this function can be used to obtain a usable pointer to the new object.

— _end note_]

[Example 1: struct X { int n; };const X *p = new const X{3};const int a = p->n;new (const_cast<X*>(p)) const X{5}; const int b = p->n; const int c = std::launder(p)->n; — _end example_]

17.6.6 Hardware interference size [hardware.interference]

inline constexpr size_t hardware_destructive_interference_size = _implementation-defined_;

This number is the minimum recommended offset between two concurrently-accessed objects to avoid additional performance degradation due to contention introduced by the implementation.

It shall be at least alignof(max_­align_­t).

[Example 1: struct keep_apart { alignas(hardware_destructive_interference_size) atomic<int> cat;alignas(hardware_destructive_interference_size) atomic<int> dog;}; — _end example_]

inline constexpr size_t hardware_constructive_interference_size = _implementation-defined_;

This number is the maximum recommended size of contiguous memory occupied by two objects accessed with temporal locality by concurrent threads.

It shall be at least alignof(max_­align_­t).

[Example 2: struct together { atomic<int> dog;int puppy;};struct kennel { alignas(sizeof(together)) together pack;};static_assert(sizeof(together) <= hardware_constructive_interference_size); — _end example_]

17.7 Type identification [support.rtti]

17.7.1 General [support.rtti.general]

The header defines a type associated with type information generated by the implementation.

It also defines two types for reporting dynamic type identification errors.

17.7.2 Header synopsis [typeinfo.syn]

namespace std { class type_info;class bad_cast;class bad_typeid;}

17.7.3 Class type_­info [type.info]

namespace std { class type_info { public: virtual ~type_info();bool operator==(const type_info& rhs) const noexcept;bool before(const type_info& rhs) const noexcept; size_t hash_code() const noexcept;const char* name() const noexcept; type_info(const type_info&) = delete; type_info& operator=(const type_info&) = delete; };}

The classtype_­infodescribes type information generated by the implementation ([expr.typeid]).

Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order.

The names, encoding rule, and collating sequence for types are all unspecifiedand may differ between programs.

bool operator==(const type_info& rhs) const noexcept;

Effects: Compares the current object with rhs.

Returns: trueif the two values describe the same type.

bool before(const type_info& rhs) const noexcept;

Effects: Compares the current object with rhs.

Returns: trueif*thisprecedes rhs in the implementation's collation order.

size_t hash_code() const noexcept;

Returns: An unspecified value, except that within a single execution of the program, it shall return the same value for any two type_­infoobjects which compare equal.

Remarks: An implementation should return different values for twotype_­info objects which do not compare equal.

const char* name() const noexcept;

Returns: An implementation-defined ntbs.

17.7.4 Class bad_­cast [bad.cast]

namespace std { class bad_cast : public exception { public: const char* what() const noexcept override;};}

The classbad_­castdefines the type of objects thrown as exceptions by the implementation to report the execution of an invaliddynamic_­castexpression ([expr.dynamic.cast]).

const char* what() const noexcept override;

Returns: An implementation-defined ntbs.

17.7.5 Class bad_­typeid [bad.typeid]

namespace std { class bad_typeid : public exception { public: const char* what() const noexcept override;};}

The classbad_­typeiddefines the type of objects thrown as exceptions by the implementation to report a null pointer in atypeidexpression ([expr.typeid]).

const char* what() const noexcept override;

Returns: An implementation-defined ntbs.

17.8 Source location [support.srcloc]

17.8.1 Header <source_­location> synopsis [source.location.syn]

The header defines the class source_­locationthat provides a means to obtain source location information.

namespace std { struct source_location;}

17.8.2 Class source_­location [support.srcloc.class]

17.8.2.1 General [support.srcloc.class.general]

namespace std { struct source_location { static consteval source_location current() noexcept;constexpr source_location() noexcept;constexpr uint_least32_t line() const noexcept;constexpr uint_least32_t column() const noexcept;constexpr const char* file_name() const noexcept;constexpr const char* function_name() const noexcept;private: uint_least32_t line_; uint_least32_t column_; const char* file_name_; const char* function_name_; };}

The type source_­location meets the_Cpp17DefaultConstructible_,Cpp17CopyConstructible,Cpp17CopyAssignable, and_Cpp17Destructible_requirements ([utility.arg.requirements]).

All of the following conditions are true:

[Note 1:

The intent of source_­location is to have a small size and efficient copying.

It is unspecified whether the copy/move constructors and the copy/move assignment operators are trivial and/or constexpr.

— _end note_]

The data members file_­name_­ and function_­name_­always each refer to an ntbs.

The copy/move constructors and the copy/move assignment operators ofsource_­location meet the following postconditions: Given two objects lhs and rhs of type source_­location, where lhs is a copy/move result of rhs, and where rhs_­p is a value denoting the state of rhsbefore the corresponding copy/move operation, then each of the following conditions is true:

17.8.2.2 Creation [support.srcloc.cons]

static consteval source_location current() noexcept;

Returns:

Remarks: Any call to current that appears as a default member initializer ([class.mem]), or as a subexpression thereof, should correspond to the location of the constructor definition or aggregate initialization that uses the default member initializer.

Any call to current that appears as a default argument ([dcl.fct.default]), or as a subexpression thereof, should correspond to the location of the invocation of the function that uses the default argument ([expr.call]).

[Example 1: struct s { source_location member = source_location::current();int other_member; s(source_location loc = source_location::current()) : member(loc) {} s(int blather) : other_member(blather) {} s(double) {} };void f(source_location a = source_location::current()) { source_location b = source_location::current(); } void g() { f(); source_location c = source_location::current(); f(c); } — _end example_]

constexpr source_location() noexcept;

Effects: The data members are initialized with valid but unspecified values.

17.8.2.3 Observers [support.srcloc.obs]

constexpr uint_least32_t line() const noexcept;

constexpr uint_least32_t column() const noexcept;

constexpr const char* file_name() const noexcept;

constexpr const char* function_name() const noexcept;

Returns: function_­name_­.

17.9 Exception handling [support.exception]

17.9.2 Header synopsis [exception.syn]

namespace std { class exception;class bad_exception;class nested_exception;using terminate_handler = void (*)(); terminate_handler get_terminate() noexcept; terminate_handler set_terminate(terminate_handler f) noexcept;[[noreturn]] void terminate() noexcept;int uncaught_exceptions() noexcept;using exception_ptr = unspecified; exception_ptr current_exception() noexcept;[[noreturn]] void rethrow_exception(exception_ptr p);template<class E> exception_ptr make_exception_ptr(E e) noexcept;template<class T> [[noreturn]] void throw_with_nested(T&& t);template<class E> void rethrow_if_nested(const E& e);}

17.9.3 Class exception [exception]

namespace std { class exception { public: exception() noexcept; exception(const exception&) noexcept; exception& operator=(const exception&) noexcept;virtual ~exception();virtual const char* what() const noexcept;};}

The classexceptiondefines the base class for the types of objects thrown as exceptions by C++ standard library components, and certain expressions, to report errors detected during program execution.

Each standard library class T that derives from class exceptionhas the following publicly accessible member functions, each of them having a non-throwing exception specification ([except.spec]):

The copy constructor and the copy assignment operator meet the following postcondition: If two objects lhs and rhs both have dynamic type T and lhs is a copy of rhs, thenstrcmp(lhs.what(), rhs.what()) is equal to 0.

The what() member function of each such T satisfies the constraints specified for exception​::​what() (see below).

exception(const exception& rhs) noexcept; exception& operator=(const exception& rhs) noexcept;

Postconditions: If *this and rhs both have dynamic type exceptionthen the value of the expression strcmp(what(), rhs.what()) shall equal 0.

Effects: Destroys an object of classexception.

virtual const char* what() const noexcept;

Returns: An implementation-defined ntbs.

The return value remains valid until the exception object from which it is obtained is destroyed or a non-constmember function of the exception object is called.

17.9.4 Class bad_­exception [bad.exception]

namespace std { class bad_exception : public exception { public: const char* what() const noexcept override;};}

The classbad_­exceptiondefines the type of the object referenced by the exception_­ptrreturned from a call to current_­exception ([propagation]) when the currently active exception object fails to copy.

const char* what() const noexcept override;

Returns: An implementation-defined ntbs.

17.9.5 Abnormal termination [exception.terminate]

17.9.5.1 Type terminate_­handler [terminate.handler]

using terminate_handler = void (*)();

The type of ahandler functionto be called bystd​::​terminate() when terminating exception processing.

Required behavior: A terminate_­handler shall terminate execution of the program without returning to the caller.

Default behavior: The implementation's default terminate_­handler callsabort().

17.9.5.2 set_­terminate [set.terminate]

terminate_handler set_terminate(terminate_handler f) noexcept;

Effects: Establishes the function designated by f as the current handler function for terminating exception processing.

Returns: The previous terminate_­handler.

Remarks: It is unspecified whether a null pointer value designates the defaultterminate_­handler.

17.9.5.3 get_­terminate [get.terminate]

terminate_handler get_terminate() noexcept;

Returns: The current terminate_­handler.

[Note 1:

This can be a null pointer value.

— _end note_]

17.9.5.4 terminate [terminate]

[[noreturn]] void terminate() noexcept;

Effects: Calls a terminate_­handler function.

It is unspecified whichterminate_­handler function will be called if an exception is active during a call to set_­terminate.

Otherwise calls the current terminate_­handler function.

[Note 1:

A default terminate_­handler is always considered a callable handler in this context.

— _end note_]

Remarks: Called by the implementation when exception handling must be abandoned for any of several reasons ([except.terminate]).

May also be called directly by the program.

17.9.6 uncaught_­exceptions [uncaught.exceptions]

int uncaught_exceptions() noexcept;

Remarks: When uncaught_­exceptions() > 0, throwing an exception can result in a call of the functionstd​::​terminate.

17.9.7 Exception propagation [propagation]

using exception_ptr = _unspecified_;

The type exception_­ptr can be used to refer to an exception object.

exception_­ptr meets the requirements of_Cpp17NullablePointer_ (Table 33).

Two non-null values of type exception_­ptr are equivalent and compare equal if and only if they refer to the same exception.

The default constructor of exception_­ptr produces the null value of the type.

exception_­ptr shall not be implicitly convertible to any arithmetic, enumeration, or pointer type.

[Note 1:

An implementation might use a reference-counted smart pointer as exception_­ptr.

— _end note_]

For purposes of determining the presence of a data race, operations onexception_­ptr objects shall access and modify only theexception_­ptr objects themselves and not the exceptions they refer to.

Use of rethrow_­exception on exception_­ptr objects that refer to the same exception object shall not introduce a data race.

[Note 2:

Ifrethrow_­exception rethrows the same exception object (rather than a copy), concurrent access to that rethrown exception object can introduce a data race.

Changes in the number of exception_­ptr objects that refer to a particular exception do not introduce a data race.

— _end note_]

exception_ptr current_exception() noexcept;

Returns: An exception_­ptr object that refers to thecurrently handled exceptionor a copy of the currently handled exception, or a null exception_­ptr object if no exception is being handled.

The referenced object shall remain valid at least as long as there is anexception_­ptr object that refers to it.

If the function needs to allocate memory and the attempt fails, it returns anexception_­ptr object that refers to an instance of bad_­alloc.

It is unspecified whether the return values of two successive calls tocurrent_­exception refer to the same exception object.

[Note 3:

That is, it is unspecified whether current_­exceptioncreates a new copy each time it is called.

— _end note_]

If the attempt to copy the current exception object throws an exception, the function returns an exception_­ptr object that refers to the thrown exception or, if this is not possible, to an instance of bad_­exception.

[Note 4:

The copy constructor of the thrown exception can also fail, so the implementation is allowed to substitute a bad_­exception object to avoid infinite recursion.

— _end note_]

[[noreturn]] void rethrow_exception(exception_ptr p);

Preconditions: p is not a null pointer.

Throws: The exception object to which p refers.

template<class E> exception_ptr make_exception_ptr(E e) noexcept;

Effects: Creates an exception_­ptr object that refers to a copy of e, as if:try { throw e;} catch(...) { return current_exception();}

[Note 5:

This function is provided for convenience and efficiency reasons.

— _end note_]

17.9.8 nested_­exception [except.nested]

namespace std { class nested_exception { public: nested_exception() noexcept; nested_exception(const nested_exception&) noexcept = default; nested_exception& operator=(const nested_exception&) noexcept = default;virtual ~nested_exception() = default;[[noreturn]] void rethrow_nested() const; exception_ptr nested_ptr() const noexcept;};template<class T> [[noreturn]] void throw_with_nested(T&& t);template<class E> void rethrow_if_nested(const E& e);}

The class nested_­exception is designed for use as a mixin through multiple inheritance.

It captures the currently handled exception and stores it for later use.

[Note 1:

nested_­exception has a virtual destructor to make it a polymorphic class.

Its presence can be tested for with dynamic_­cast.

— _end note_]

nested_exception() noexcept;

Effects: The constructor calls current_­exception() and stores the returned value.

[[noreturn]] void rethrow_nested() const;

Effects: If nested_­ptr() returns a null pointer, the function calls the function std​::​terminate.

Otherwise, it throws the stored exception captured by *this.

exception_ptr nested_ptr() const noexcept;

Returns: The stored exception captured by this nested_­exception object.

template<class T> [[noreturn]] void throw_with_nested(T&& t);

Preconditions: U meets the Cpp17CopyConstructible requirements.

Throws: If is_­class_­v<U> && !is_­final_­v<U> && !is_­base_­of_­v<nested_­exception, U>is true, an exception of unspecified type that is publicly derived from bothU and nested_­exceptionand constructed from std​::​forward<T>(t), otherwisestd​::​forward<T>(t).

template<class E> void rethrow_if_nested(const E& e);

Effects: If E is not a polymorphic class type, or if nested_­exception is an inaccessible or ambiguous base class of E, there is no effect.

Otherwise, performs:if (auto p = dynamic_cast<const nested_exception*>(addressof(e))) p->rethrow_nested();

17.10 Initializer lists [support.initlist]

17.10.2 Header <initializer_­list> synopsis [initializer.list.syn]

namespace std { template<class E> class initializer_list { public: using value_type = E;using reference = const E&;using const_reference = const E&;using size_type = size_t;using iterator = const E*;using const_iterator = const E*;constexpr initializer_list() noexcept;constexpr size_t size() const noexcept; constexpr const E* begin() const noexcept; constexpr const E* end() const noexcept; };template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;template<class E> constexpr const E* end(initializer_list<E> il) noexcept;}

An object of type initializer_­list<E> provides access to an array of objects of type const E.

[Note 1:

A pair of pointers or a pointer plus a length would be obvious representations for initializer_­list.

initializer_­list is used to implement initializer lists as specified in [dcl.init.list].

Copying an initializer list does not copy the underlying elements.

— _end note_]

If an explicit specialization or partial specialization ofinitializer_­list is declared, the program is ill-formed.

17.10.3 Initializer list constructors [support.initlist.cons]

constexpr initializer_list() noexcept;

Postconditions: size() == 0.

17.10.4 Initializer list access [support.initlist.access]

constexpr const E* begin() const noexcept;

Returns: A pointer to the beginning of the array.

If size() == 0 the values of begin() and end() are unspecified but they shall be identical.

constexpr const E* end() const noexcept;

Returns: begin() + size().

constexpr size_t size() const noexcept;

Returns: The number of elements in the array.

Complexity: Constant time.

17.10.5 Initializer list range access [support.initlist.range]

template<class E> constexpr const E* begin(initializer_list<E> il) noexcept;

template<class E> constexpr const E* end(initializer_list<E> il) noexcept;

17.11 Comparisons [cmp]

17.11.1 Header synopsis [compare.syn]

namespace std { class partial_ordering;class weak_ordering;class strong_ordering;constexpr bool is_eq (partial_ordering cmp) noexcept { return cmp == 0; } constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; } constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; } constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; } constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; } constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; } template<class... Ts> struct common_comparison_category { using type = see below;};template<class... Ts> using common_comparison_category_t = typename common_comparison_category<Ts...>::type;template<class T, class Cat = partial_ordering> concept three_way_comparable = see below;template<class T, class U, class Cat = partial_ordering> concept three_way_comparable_with = see below;template<class T, class U = T> struct compare_three_way_result;template<class T, class U = T> using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;struct compare_three_way;inline namespace unspecified { inline constexpr unspecified strong_order = unspecified;inline constexpr unspecified weak_order = unspecified;inline constexpr unspecified partial_order = unspecified;inline constexpr unspecified compare_strong_order_fallback = unspecified;inline constexpr unspecified compare_weak_order_fallback = unspecified;inline constexpr unspecified compare_partial_order_fallback = unspecified;} }

17.11.2 Comparison category types [cmp.categories]

17.11.2.1 Preamble [cmp.categories.pre]

The typespartial_­ordering,weak_­ordering, andstrong_­orderingare collectively termed the comparison category types.

Each is specified in terms of an exposition-only data member named valuewhose value typically corresponds to that of an enumerator from one of the following exposition-only enumerations:enum class ord { equal = 0, equivalent = equal, less = -1, greater = 1 }; enum class ncmp { unordered = -127 };

[Note 1:

The type strong_­orderingcorresponds to the term total ordering in mathematics.

— _end note_]

The relational and equality operators for the comparison category types are specified with an anonymous parameter of unspecified type.

This type shall be selected by the implementation such that these parameters can accept literal 0 as a corresponding argument.

[Example 1:

nullptr_­tmeets this requirement.

— _end example_]

In this context, the behavior of a program that supplies an argument other than a literal 0 is undefined.

For the purposes of subclause [cmp.categories],substitutability is the property that f(a) == f(b) is truewhenever a == b is true, where f denotes a function that reads only comparison-salient state that is accessible via the argument's public const members.

17.11.2.2 Class partial_­ordering [cmp.partialord]

The partial_­ordering type is typically used as the result type of a three-way comparison operatorthat (a) admits all of the six two-way comparison operators ([expr.rel], [expr.eq]), (b) does not imply substitutability, and (c) permits two values to be incomparable.220

namespace std { class partial_ordering { int value; bool is_ordered; constexpr explicit partial_ordering(ord v) noexcept : value(int(v)), is_ordered(true) {} constexpr explicit partial_ordering(ncmp v) noexcept : value(int(v)), is_ordered(false) {} public: static const partial_ordering less;static const partial_ordering equivalent;static const partial_ordering greater;static const partial_ordering unordered;friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;friend constexpr bool operator< (partial_ordering v, _unspecified_) noexcept;friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;friend constexpr bool operator<=(partial_ordering v, _unspecified_) noexcept;friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;friend constexpr bool operator< (_unspecified_, partial_ordering v) noexcept;friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;friend constexpr bool operator<=(_unspecified_, partial_ordering v) noexcept;friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;};inline constexpr partial_ordering partial_ordering::less(ord::less);inline constexpr partial_ordering partial_ordering::equivalent(ord::equivalent);inline constexpr partial_ordering partial_ordering::greater(ord::greater);inline constexpr partial_ordering partial_ordering::unordered(ncmp::unordered);}

constexpr bool operator==(partial_ordering v, _unspecified_) noexcept;constexpr bool operator< (partial_ordering v, _unspecified_) noexcept;constexpr bool operator> (partial_ordering v, _unspecified_) noexcept;constexpr bool operator<=(partial_ordering v, _unspecified_) noexcept;constexpr bool operator>=(partial_ordering v, _unspecified_) noexcept;

Returns: For operator@, v.is_­ordered && v.value @ 0.

constexpr bool operator< (_unspecified_, partial_ordering v) noexcept;constexpr bool operator> (_unspecified_, partial_ordering v) noexcept;constexpr bool operator<=(_unspecified_, partial_ordering v) noexcept;constexpr bool operator>=(_unspecified_, partial_ordering v) noexcept;

Returns: For operator@, v.is_­ordered && 0 @ v.value.

constexpr partial_ordering operator<=>(partial_ordering v, _unspecified_) noexcept;

constexpr partial_ordering operator<=>(_unspecified_, partial_ordering v) noexcept;

Returns: v < 0 ? partial_­ordering​::​greater : v > 0 ? partial_­ordering​::​less : v.

17.11.2.3 Class weak_­ordering [cmp.weakord]

namespace std { class weak_ordering { int value; constexpr explicit weak_ordering(ord v) noexcept : value(int(v)) {} public: static const weak_ordering less;static const weak_ordering equivalent;static const weak_ordering greater;constexpr operator partial_ordering() const noexcept;friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;friend constexpr bool operator< (weak_ordering v, _unspecified_) noexcept;friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;friend constexpr bool operator<=(weak_ordering v, _unspecified_) noexcept;friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;friend constexpr bool operator< (_unspecified_, weak_ordering v) noexcept;friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;friend constexpr bool operator<=(_unspecified_, weak_ordering v) noexcept;friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;};inline constexpr weak_ordering weak_ordering::less(ord::less);inline constexpr weak_ordering weak_ordering::equivalent(ord::equivalent);inline constexpr weak_ordering weak_ordering::greater(ord::greater);}

constexpr operator partial_ordering() const noexcept;

Returns: value == 0 ? partial_ordering::equivalent :value < 0 ? partial_ordering::less : partial_ordering::greater

constexpr bool operator==(weak_ordering v, _unspecified_) noexcept;constexpr bool operator< (weak_ordering v, _unspecified_) noexcept;constexpr bool operator> (weak_ordering v, _unspecified_) noexcept;constexpr bool operator<=(weak_ordering v, _unspecified_) noexcept;constexpr bool operator>=(weak_ordering v, _unspecified_) noexcept;

Returns: v.value @ 0 for operator@.

constexpr bool operator< (_unspecified_, weak_ordering v) noexcept;constexpr bool operator> (_unspecified_, weak_ordering v) noexcept;constexpr bool operator<=(_unspecified_, weak_ordering v) noexcept;constexpr bool operator>=(_unspecified_, weak_ordering v) noexcept;

Returns: 0 @ v.value for operator@.

constexpr weak_ordering operator<=>(weak_ordering v, _unspecified_) noexcept;

constexpr weak_ordering operator<=>(_unspecified_, weak_ordering v) noexcept;

Returns: v < 0 ? weak_­ordering​::​greater : v > 0 ? weak_­ordering​::​less : v.

17.11.2.4 Class strong_­ordering [cmp.strongord]

namespace std { class strong_ordering { int value; constexpr explicit strong_ordering(ord v) noexcept : value(int(v)) {} public: static const strong_ordering less;static const strong_ordering equal;static const strong_ordering equivalent;static const strong_ordering greater;constexpr operator partial_ordering() const noexcept;constexpr operator weak_ordering() const noexcept;friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;friend constexpr bool operator< (strong_ordering v, _unspecified_) noexcept;friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;friend constexpr bool operator<=(strong_ordering v, _unspecified_) noexcept;friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;friend constexpr bool operator< (_unspecified_, strong_ordering v) noexcept;friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;friend constexpr bool operator<=(_unspecified_, strong_ordering v) noexcept;friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;};inline constexpr strong_ordering strong_ordering::less(ord::less);inline constexpr strong_ordering strong_ordering::equal(ord::equal);inline constexpr strong_ordering strong_ordering::equivalent(ord::equivalent);inline constexpr strong_ordering strong_ordering::greater(ord::greater);}

constexpr operator partial_ordering() const noexcept;

Returns: value == 0 ? partial_ordering::equivalent :value < 0 ? partial_ordering::less : partial_ordering::greater

constexpr operator weak_ordering() const noexcept;

Returns: value == 0 ? weak_ordering::equivalent :value < 0 ? weak_ordering::less : weak_ordering::greater

constexpr bool operator==(strong_ordering v, _unspecified_) noexcept;constexpr bool operator< (strong_ordering v, _unspecified_) noexcept;constexpr bool operator> (strong_ordering v, _unspecified_) noexcept;constexpr bool operator<=(strong_ordering v, _unspecified_) noexcept;constexpr bool operator>=(strong_ordering v, _unspecified_) noexcept;

Returns: v.value @ 0 for operator@.

constexpr bool operator< (_unspecified_, strong_ordering v) noexcept;constexpr bool operator> (_unspecified_, strong_ordering v) noexcept;constexpr bool operator<=(_unspecified_, strong_ordering v) noexcept;constexpr bool operator>=(_unspecified_, strong_ordering v) noexcept;

Returns: 0 @ v.value for operator@.

constexpr strong_ordering operator<=>(strong_ordering v, _unspecified_) noexcept;

constexpr strong_ordering operator<=>(_unspecified_, strong_ordering v) noexcept;

Returns: v < 0 ? strong_­ordering​::​greater : v > 0 ? strong_­ordering​::​less : v.

17.11.3 Class template common_­comparison_­category [cmp.common]

The type common_­comparison_­category provides an alias for the strongest comparison category to which all of the template arguments can be converted.

[Note 1:

A comparison category type is stronger than another if they are distinct types and an instance of the former can be converted to an instance of the latter.

— _end note_]

template<class... Ts> struct common_comparison_category { using type = _see below_;};

Remarks: The member typedef-name type denotes the common comparison type ([class.spaceship]) of Ts..., the expanded parameter pack, orvoid if any element of Tsis not a comparison category type.

[Note 2:

This is std​::​strong_­ordering if the expansion is empty.

— _end note_]

17.11.4 Concept three_­way_­comparable [cmp.concept]

Let t and u be lvalues of types const remove_­reference_­t<T> andconst remove_­reference_­t<U>, respectively.

T and U modelpartially-ordered-with<T, U> only if:

template<class T, class Cat = partial_ordering> concept three_­way_­comparable = weakly-equality-comparable-with<T, T> && partially-ordered-with<T, T> && requires(const remove_reference_t<T>& a, const remove_reference_t<T>& b) { { a <=> b } -> compares-as<Cat>;};

Let a and b be lvalues of type const remove_­reference_­t<T>.

T and Catmodel three_­way_­comparable<T, Cat> only if:

template<class T, class U, class Cat = partial_ordering> concept three_­way_­comparable_­with = three_­way_­comparable<T, Cat> && three_­way_­comparable<U, Cat> && common_­reference_­with<const remove_reference_t<T>&, const remove_reference_t<U>&> && three_­way_­comparable< common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>, Cat> && weakly-equality-comparable-with<T, U> && partially-ordered-with<T, U> && requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t <=> u } -> compares-as<Cat>;{ u <=> t } -> compares-as<Cat>;};

Let t and u be lvalues of types const remove_­reference_­t<T> andconst remove_­reference_­t<U>, respectively.

Let C becommon_­reference_­t<const remove_­reference_­t<T>&, const remove_­reference_­t<U>&>.

T, U, and Catmodel three_­way_­comparable_­with<T, U, Cat> only if:

17.11.5 Result of three-way comparison [cmp.result]

The behavior of a program that adds specializations for the compare_­three_­way_­result template defined in this subclause is undefined.

For the compare_­three_­way_­result type trait applied to the types T and U, let t and u denote lvalues of typesconst remove_­reference_­t<T> and const remove_­reference_­t<U>, respectively.

If the expression t <=> u is well-formed when treated as an unevaluated operand ([expr.context]), the member typedef-name typedenotes the type decltype(t <=> u).

Otherwise, there is no member type.

17.11.6 Comparison algorithms [cmp.alg]

Given subexpressions E and F, the expression strong_­order(E, F)is expression-equivalent ([defns.expression-equivalent]) to the following:

Given subexpressions E and F, the expression weak_­order(E, F)is expression-equivalent ([defns.expression-equivalent]) to the following:

Given subexpressions E and F, the expression partial_­order(E, F)is expression-equivalent ([defns.expression-equivalent]) to the following:

Given subexpressions E and F, the expression compare_­strong_­order_­fallback(E, F)is expression-equivalent ([defns.expression-equivalent]) to:

Given subexpressions E and F, the expression compare_­weak_­order_­fallback(E, F)is expression-equivalent ([defns.expression-equivalent]) to:

Given subexpressions E and F, the expression compare_­partial_­order_­fallback(E, F)is expression-equivalent ([defns.expression-equivalent]) to:

17.12 Coroutines [support.coroutine]

17.12.1 General [support.coroutine.general]

The header defines several types providing compile and run-time support for coroutines in a C++ program.

17.12.3 Coroutine traits [coroutine.traits]

17.12.3.1 General [coroutine.traits.general]

Subclause [coroutine.traits] defines requirements on classes representingcoroutine traits, and defines the class templatecoroutine_­traitsthat meets those requirements.

17.12.3.2 Class template coroutine_­traits [coroutine.traits.primary]

The header defines the primary templatecoroutine_­traits such that if ArgTypes is a parameter pack of types and if the qualified-id R​::​promise_­type is valid and denotes a type ([temp.deduct]), then coroutine_­traits<R,ArgTypes...> has the following publicly accessible member:using promise_type = typename R::promise_type;

Otherwise, coroutine_­traits<R,ArgTypes...> has no members.

Program-defined specializations of this template shall define a publicly accessible nested type named promise_­type.

17.12.4 Class template coroutine_­handle [coroutine.handle]

17.12.4.1 General [coroutine.handle.general]

namespace std { template<> struct coroutine_handle<void> { constexpr coroutine_handle() noexcept;constexpr coroutine_handle(nullptr_t) noexcept; coroutine_handle& operator=(nullptr_t) noexcept;constexpr void* address() const noexcept;static constexpr coroutine_handle from_address(void* addr);constexpr explicit operator bool() const noexcept;bool done() const;void operator()() const;void resume() const;void destroy() const;private: void* ptr; };template<class Promise> struct coroutine_handle : coroutine_handle<> { using coroutine_handle<>::coroutine_handle;static coroutine_handle from_promise(Promise&); coroutine_handle& operator=(nullptr_t) noexcept;static constexpr coroutine_handle from_address(void* addr); Promise& promise() const;};}

An object of typecoroutine_­handle<T> is called a coroutine handleand can be used to refer to a suspended or executing coroutine.

A default-constructed coroutine_­handle object does not refer to any coroutine.

If a program declares an explicit or partial specialization ofcoroutine_­handle, the behavior is undefined.

17.12.4.2 Construct/reset [coroutine.handle.con]

constexpr coroutine_handle() noexcept;constexpr coroutine_handle(nullptr_t) noexcept;

Postconditions: address() == nullptr.

static coroutine_handle from_promise(Promise& p);

Preconditions: p is a reference to a promise object of a coroutine.

Postconditions: addressof(h.promise()) == addressof(p).

Returns: A coroutine handle h referring to the coroutine.

coroutine_handle& operator=(nullptr_t) noexcept;

Postconditions: address() == nullptr.

17.12.4.3 Export/import [coroutine.handle.export.import]

constexpr void* address() const noexcept;

static constexpr coroutine_handle<> coroutine_handle<>::from_address(void* addr);static constexpr coroutine_handle<Promise> coroutine_handle<Promise>::from_address(void* addr);

Preconditions: addr was obtained via a prior call to address.

Postconditions: from_­address(address()) == *this.

17.12.4.4 Observers [coroutine.handle.observers]

constexpr explicit operator bool() const noexcept;

Returns: address() != nullptr.

Preconditions: *this refers to a suspended coroutine.

Returns: true if the coroutine is suspended at its final suspend point, otherwise false.

17.12.4.5 Resumption [coroutine.handle.resumption]

Resuming a coroutine via resume, operator(), or destroyon an execution agent other than the one on which it was suspended has implementation-defined behavior unless each execution agent either is an instance of std​::​thread or std​::​jthread, or is the thread that executes main.

[Note 1:

A coroutine that is resumed on a different execution agent should avoid relying on consistent thread identity throughout, such as holding a mutex object across a suspend point.

— _end note_]

[Note 2:

A concurrent resumption of the coroutine can result in a data race.

— _end note_]

void operator()() const;void resume() const;

Preconditions: *this refers to a suspended coroutine.

The coroutine is not suspended at its final suspend point.

Effects: Resumes the execution of the coroutine.

Preconditions: *this refers to a suspended coroutine.

17.12.4.6 Promise access [coroutine.handle.promise]

Promise& promise() const;

Preconditions: *this refers to a coroutine.

Returns: A reference to the promise of the coroutine.

17.12.4.7 Comparison operators [coroutine.handle.compare]

constexpr bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept;

Returns: x.address() == y.address().

constexpr strong_ordering operator<=>(coroutine_handle<> x, coroutine_handle<> y) noexcept;

Returns: compare_­three_­way()(x.address(), y.address()).

17.12.5 No-op coroutines [coroutine.noop]

17.12.5.1 Class noop_­coroutine_­promise [coroutine.promise.noop]

struct noop_coroutine_promise {};

The class noop_­coroutine_­promise defines the promise type for the coroutine referred to by noop_­coroutine_­handle ([coroutine.syn]).

17.12.5.2 Class coroutine_­handle<noop_­coroutine_­promise> [coroutine.handle.noop]

namespace std { template<> struct coroutine_handle<noop_coroutine_promise> : coroutine_handle<> { constexpr explicit operator bool() const noexcept;constexpr bool done() const noexcept;constexpr void operator()() const noexcept;constexpr void resume() const noexcept;constexpr void destroy() const noexcept; noop_coroutine_promise& promise() const noexcept;constexpr void* address() const noexcept;private: coroutine_handle(unspecified);};}

17.12.5.2.2 Resumption [coroutine.handle.noop.resumption]

constexpr void operator()() const noexcept;constexpr void resume() const noexcept;constexpr void destroy() const noexcept;

Remarks: If noop_­coroutine_­handle is converted to coroutine_­handle<>, calls to operator(), resume and destroy on that handle will also have no observable effects.

17.12.5.2.3 Promise access [coroutine.handle.noop.promise]

noop_coroutine_promise& promise() const noexcept;

Returns: A reference to the promise object associated with this coroutine handle.

17.12.5.3 Function noop_­coroutine [coroutine.noop.coroutine]

noop_coroutine_handle noop_coroutine() noexcept;

Returns: A handle to a coroutine that has no observable effects when resumed or destroyed.

Remarks: A handle returned from noop_­coroutine may or may not compare equal to a handle returned from another invocation of noop_­coroutine.

17.12.6 Trivial awaitables [coroutine.trivial.awaitables]

namespace std { struct suspend_never { constexpr bool await_ready() const noexcept { return true; } constexpr void await_suspend(coroutine_handle<>) const noexcept {} constexpr void await_resume() const noexcept {} };struct suspend_always { constexpr bool await_ready() const noexcept { return false; } constexpr void await_suspend(coroutine_handle<>) const noexcept {} constexpr void await_resume() const noexcept {} };}

[Note 1:

The types suspend_­never and suspend_­always can be used to indicate that an await-expression either never suspends or always suspends, and in either case does not produce a value.

— _end note_]

17.13 Other runtime support [support.runtime]

17.13.1 General [support.runtime.general]

Headers (nonlocal jumps), (signal handling), (variable arguments), and (runtime environment getenv, system), provide further compatibility with C code.

Calls to the functiongetenv ([cstdlib.syn]) shall not introduce a data race ([res.on.data.races]) provided that nothing modifies the environment.

[Note 1:

Calls to the POSIX functionssetenv andputenv modify the environment.

— _end note_]

A call to the setlocale function may introduce a data race with other calls to the setlocale function or with calls to functions that are affected by the current C locale.

The implementation shall behave as if no library function other than locale​::​global calls the setlocalefunction.

17.13.2 Header synopsis [cstdarg.syn]

The contents of the header are the same as the C standard library header , with the following changes: The restrictions that ISO C places on the second parameter to theva_­start macro in header are different in this document.

The parameterparmNis the rightmost parameter in the variable parameter list of the function definition (the one just before the...).221

If the parameter parmN is a pack expansion ([temp.variadic]) or an entity resulting from a lambda capture ([expr.prim.lambda]), the program is ill-formed, no diagnostic required.

If the parameterparmNis of a reference type, or of a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined.

17.13.3 Header synopsis [csetjmp.syn]

namespace std { using jmp_buf = see below;[[noreturn]] void longjmp(jmp_buf env, int val);} #define setjmp(env) see below

The contents of the header are the same as the C standard library header .

The function signaturelongjmp(jmp_­buf jbuf, int val)has more restricted behavior in this document.

A setjmp/longjmp call pair has undefined behavior if replacing the setjmp and longjmpby catch and throw would invoke any non-trivial destructors for any objects with automatic storage duration.

A call to setjmp or longjmp has undefined behavior if invoked in a suspension context of a coroutine ([expr.await]).

17.13.4 Header synopsis [csignal.syn]

namespace std { using sig_atomic_t = see below;extern "C" using signal-handler = void(int); signal-handler* signal(int sig, signal-handler* func);int raise(int sig);} #define SIG_DFL see below #define SIG_ERR see below #define SIG_IGN see below #define SIGABRT see below #define SIGFPE see below #define SIGILL see below #define SIGINT see below #define SIGSEGV see below #define SIGTERM see below

The contents of the header are the same as the C standard library header .

17.13.5 Signal handlers [support.signal]

A call to the function signal synchronizes with any resulting invocation of the signal handler so installed.

A plain lock-free atomic operation is an invocation of a function f from [atomics], such that:

An evaluation is signal-safe unless it includes one of the following:

A signal handler invocation has undefined behavior if it includes an evaluation that is not signal-safe.

The function signal is signal-safe if it is invoked with the first argument equal to the signal number corresponding to the signal that caused the invocation of the handler.