ISO/IEC TS 19568:2024
(Main)Programming Languages — C++ Extensions for Library Fundamentals
Programming Languages — C++ Extensions for Library Fundamentals
This document describes extensions to the C++ Standard Library (2). These extensions are classes and functions that are likely to be used widely within a program and/or on the interface boundaries between libraries written by different organizations. It is intended that some of the library components be considered for standardization in a future version of C++. At present, they are not part of any C++ standard. The goal of this document is to build more widespread existing practice for an expanded C++ standard library. It gives advice on extensions to those vendors who wish to provide them.
Langages de programmation — Extensions C++ pour la bibliothèque fondamentaux
General Information
Relations
Standards Content (Sample)
Technical
Specification
ISO/IEC TS 19568
Third edition
Programming Languages —
2024-08
C++ Extensions for Library
Fundamentals
Langages de programmation — Extensions C++ pour la
bibliothèque fondamentaux
Reference number
© ISO/IEC 2024
All rights reserved. Unless otherwise specified, or required in the context of its implementation, no part of this publication may
be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying, or posting on
the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below
or ISO’s member body in the country of the requester.
ISO copyright office
CP 401 • Ch. de Blandonnet 8
CH-1214 Vernier, Geneva
Phone: +41 22 749 01 11
Email: copyright@iso.org
Website: www.iso.org
Published in Switzerland
© ISO/IEC 2024 – All rights reserved
ii
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Terms and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 General principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.1 Namespaces, headers, and modifications to standard classes . . . . . . . . . . . . 4
4.2 Feature-testing recommendations . . . . . . . . . . . . . . . . . . . . . . . . 5
5 Modifications to the C++ Standard Library . . . . . . . . . . . . . . . . 7
5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5.2 Exception requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
© ISO/IEC 2024 — All rights reserved iii
© ISO/IEC 2024 – All rights reserved
iii
6 General utilities library . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6.1 Constness propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6.1.1 Header synopsis . . . . . . . . . . . . 8
6.1.2 Class template propagate_const . . . . . . . . . . . . . . . . . . . 10
6.1.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . 10
6.1.2.2 General requirements on T . . . . . . . . . . . . . . . . . 12
6.1.2.3 Requirements on class type T . . . . . . . . . . . . . . . . 12
6.1.2.4 Constructors . . . . . . . . . . . . . . . . . . . . . . . . 13
6.1.2.5 Assignment . . . . . . . . . . . . . . . . . . . . . . . . 13
6.1.2.6 Const observers . . . . . . . . . . . . . . . . . . . . . . 14
6.1.2.7 Non-const observers . . . . . . . . . . . . . . . . . . . . 14
6.1.2.8 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.1.2.9 Relational operators . . . . . . . . . . . . . . . . . . . . 15
6.1.2.10 Specialized algorithms . . . . . . . . . . . . . . . . . . . 18
6.1.2.11 Underlying pointer access . . . . . . . . . . . . . . . . . . 18
6.1.2.12 Hash support . . . . . . . . . . . . . . . . . . . . . . . 18
6.1.2.13 Comparison function objects . . . . . . . . . . . . . . . . 19
6.2 Scope guard support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.2.1 Header synopsis . . . . . . . . . . . . . . . . 20
6.2.2 Class templates scope_exit, scope_fail, and scope_success . . . . . . . 21
6.2.3 Class template unique_resource . . . . . . . . . . . . . . . . . . . . 24
6.2.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2.3.2 Constructors . . . . . . . . . . . . . . . . . . . . . . . . 26
6.2.3.3 Destructor . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2.3.4 Assignment . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2.3.5 Other member functions . . . . . . . . . . . . . . . . . . 29
6.2.3.6 unique_resource creation . . . . . . . . . . . . . . . . . . 30
6.3 Metaprogramming and type traits . . . . . . . . . . . . . . . . . . . . . . 31
6.3.1 Header synopsis . . . . . . . . . . . . . 31
6.3.2 Other type transformations . . . . . . . . . . . . . . . . . . . . . . 32
6.3.3 Detection idiom . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7 Function objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
7.1 Header synopsis . . . . . . . . . . . . . . . . . . 36
7.2 Class template function . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
7.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
7.2.2 Construct/copy/destroy . . . . . . . . . . . . . . . . . . . . . . . 38
7.2.3 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
7.2.4 Observers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
iv © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
iv
8 Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
8.1 Header synopsis . . . . . . . . . . . . . . . . . . . 40
8.2 Non-owning (observer) pointers . . . . . . . . . . . . . . . . . . . . . . . . 41
8.2.1 Class template observer_ptr overview . . . . . . . . . . . . . . . . . 41
8.2.2 observer_ptr constructors . . . . . . . . . . . . . . . . . . . . . . 42
8.2.3 observer_ptr observers . . . . . . . . . . . . . . . . . . . . . . . . 43
8.2.4 observer_ptr conversions . . . . . . . . . . . . . . . . . . . . . . . 43
8.2.5 observer_ptr modifiers . . . . . . . . . . . . . . . . . . . . . . . . 43
8.2.6 observer_ptr specialized algorithms . . . . . . . . . . . . . . . . . . 44
8.2.7 observer_ptr hash support . . . . . . . . . . . . . . . . . . . . . . 45
8.3 Header synopsis . . . . . . . . . . . . . . 45
8.4 Alias template resource_adaptor . . . . . . . . . . . . . . . . . . . . . . . 45
8.4.1 resource_adaptor . . . . . . . . . . . . . . . . . . . . . . . . . . 45
8.4.2 resource_adaptor_imp constructors . . . . . . . . . . . . . . . . . . 47
8.4.3 resource_adaptor_imp member functions . . . . . . . . . . . . . . . 47
9 Iterators library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.1 Header synopsis . . . . . . . . . . . . . . . . . . . 48
9.2 Class template ostream_joiner . . . . . . . . . . . . . . . . . . . . . . . . 48
9.2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.2.2 Constructor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
9.2.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
9.2.4 Creation function . . . . . . . . . . . . . . . . . . . . . . . . . . 50
10 Algorithms library . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
10.1 Header synopsis . . . . . . . . . . . . . . . . . . 51
10.2 Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
10.3 Shuffle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
11 Numerics library . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
11.1 Random number generation . . . . . . . . . . . . . . . . . . . . . . . . . 53
11.1.1 Header synopsis . . . . . . . . . . . . . . . 53
11.1.2 Function template randint . . . . . . . . . . . . . . . . . . . . . . 53
© ISO/IEC 2024 — All rights reserved v
© ISO/IEC 2024 – All rights reserved
v
Foreword
ISO (the International Organization for Standardization) and IEC (the International
Electrotechnical Commission) form the specialized system for worldwide standardization. National
bodies that are members of ISO or IEC participate in the development of International Standards
through technical committees established by the respective organization to deal with particular
fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual
interest. Other international organizations, governmental and non-governmental, in liaison with
ISO and IEC, also take part in the work.
The procedures used to develop this document and those intended for its further maintenance are
described in the ISO/IEC Directives, Part 1. In particular, the different approval criteria needed
for the different types of document should be noted. This document was drafted in accordance
with the editorial rules of the ISO/IEC Directives, Part 2 (see www.iso.org/directives or
www.iec.ch/members_experts/refdocs).
ISO and IEC draw attention to the possibility that the implementation of this document may
involve the use of (a) patent(s). ISO and IEC take no position concerning the evidence, validity or
applicability of any claimed patent rights in respect thereof. As of the date of publication of this
document, ISO and IEC had not received notice of (a) patent(s) which may be required to
implement this document. However, implementers are cautioned that this may not represent the
latest information, which may be obtained from the patent database available at www.iso.org/
patents and https://patents.iec.ch. ISO and IEC shall not be held responsible for identifying any
or all such patent rights.
Any trade name used in this document is information given for the convenience of users and does
not constitute an endorsement.
For an explanation of the voluntary nature of standards, the meaning of ISO specific terms and
expressions related to conformity assessment, as well as information about ISO's adherence to the
World Trade Organization (WTO) principles in the Technical Barriers to Trade (TBT) see
www.iso.org/iso/foreword.html. In the IEC, see www.iec.ch/understanding-standards.
This document was prepared by Joint Technical Committee ISO/IEC JTC 1, Information
technology, Subcommittee SC 22, Programming languages, their environments and system software
interfaces.
This third edition cancels and replaces the second edition (ISO/IEC TS 19568:2017), which has
been technically revised.
The main changes are as follows:
— The document now refers to the C++ language as defined in ISO/IEC 14882:2020; the
previous edition referred to ISO/IEC 14882:2017.
— Removal of features that have been added to ISO/IEC 14882: tuple utilities, logical
6 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
vi
operator traits, rational arithmetic, time utilities, error support, searchers, not_fn,
optional, any, string_view, shared-ownership pointers, memory_resource, search
algorithm, numeric operations (gcd/lcm), source_location.
— New feature: scope guard class templates for guard types that perform automatic actions
on scope exit.
— Feature modification: type-erasing classes now use polymorphic_allocator<>.
Any feedback or questions on this document should be directed to the user’s national standards
body. A complete listing of these bodies can be found at www.iso.org/members.html and
www.iec.ch/national-committees.
© ISO/IEC 2024 — All rights reserved 7
© ISO/IEC 2024 – All rights reserved
vii
Introduction [introduction]
In this document, the phrase C++ Standard Library refers to the library described in ISO/IEC
14882:2020, clauses 16–32.
Clauses and subclauses in this document are annotated with a so-called stable name, presented in
square brackets next to the (sub)clause heading (such as "[introduction]" for this clause). Stable
names aid in the discussion and evolution of this document by serving as stable references to
subclauses across editions that are unaffected by changes of subclause numbering.
In addition to the main font for the document body, this document uses
upright monospace font to display C++ source code, some of which forms part of the
normative specification verbatim, italic monospace font for placeholders within source code
that necessary for the specification, but whose spelling is not significant, and ItalicSerifCamelCase
for certain concepts (comprising syntactic and semantic constraints) from the C++ Standard
Library.
8 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
viii
TECHNICAL SPECIFICATION ISO/IEC TS 19568:2024(en)
Programming languages —
C++ Extensions for Library Fundamentals
1 Scope [general.scope]
This document describes extensions to the C++ Standard Library (2). These extensions are
classes and functions that are likely to be used widely within a program and/or on the interface
boundaries between libraries written by different organizations.
It is intended that some of the library components be considered for standardization in a future
version of C++. At present, they are not part of any C++ standard.
The goal of this document is to build more widespread existing practice for an expanded C++
standard library. It gives advice on extensions to those vendors who wish to provide them.
© ISO/IEC 2024 — All rights reserved 1
© ISO/IEC 2024 – All rights reserved
2 Normative references [general.references]
The following documents are referred to in the text in such a way that some or all of their content
constitutes requirements of this document. For dated references, only the edition cited applies. For
undated references, the latest edition of the referenced document (including any amendments)
applies.
— ISO/IEC 14882:2020, Programming Languages — C++
2 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
3 Terms and definitions [general.terms]
For the purposes of this document, the terms and definitions given in ISO/IEC 14882:2020 apply.
ISO and IEC maintain terminology databases for use in standardization at the following
addresses:
— ISO Online browsing platform: available at https://www.iso.org/obp
— IEC Electropedia: available at https://www.electropedia.org/
© ISO/IEC 2024 — All rights reserved 3
© ISO/IEC 2024 – All rights reserved
4 General principles [general]
4.1 Namespaces, headers, and modifications to standard classes
[general.namespaces]
Since the extensions described in this document are experimental and not part of the C++
standard library, they should not be declared directly within namespace std. Unless otherwise
specified, all components described in this document either:
— modify an existing interface in the C++ Standard Library in-place,
— are declared in a namespace whose name appends ::experimental::fundamentals_v3 to
a namespace defined in the C++ Standard Library, such as std or std::chrono, or
— are declared in a subnamespace of a namespace described in the previous bullet, whose
name is not the same as an existing subnamespace of namespace std.
EXAMPLE This document does not define std::experimental::fundamentals_v3::pmr because the
C++ Standard Library defines std::pmr.
Each header described in this document shall import the contents of
std::experimental::fundamentals_v3 into std::experimental as if by
namespace std::experimental::inline fundamentals_v3 {}
This document also describes some experimental modifications to existing interfaces in the C++
Standard Library.
Unless otherwise specified, references to other entities described in this document are assumed to
be qualified with std::experimental::fundamentals_v3::, and references to entities described
in the standard are assumed to be qualified with std::.
Extensions that are expected to eventually be added to an existing header are provided
inside the header, which shall include the standard contents of as
if by
#include
New headers are also provided in the directory, but without such an #include.
Table 1 lists the headers that are specified by this document.
Table 1 — C++ library headers
4 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
NOTE This is the last in a series of revisions of this document planned by the C++ committee; while
there are no plans to resume the series, any future versions will define their contents in
std::experimental::fundamentals_v4, std::experimental::fundamentals_v5, etc., with the most
recent implemented version inlined into std::experimental.
4.2 Feature-testing recommendations [general.feature.test]
For the sake of improved portability between partial implementations of various C++ standards,
implementers and programmers are recommended to follow the guidelines in this subclause
concerning feature-test macros.
Implementers who provide a new standard feature should define a macro with the recommended
name, in the same circumstances under which the feature is available (for example, taking into
account relevant command-line options), to indicate the presence of support for that feature.
Implementers should define that macro with the value specified in the most recent version of this
document that they have implemented. The recommended macro name is
“__cpp_lib_experimental_” followed by the string in the “Macro Name Suffix” column. Table 2
lists the headers and recommended feature-test macros for the features specified in this document.
Programmers who wish to determine whether a feature is available in an implementation should
base that determination on the presence of the header (determined with
__has_include(
absence of a tested feature may result in a program with decreased functionality, or the relevant
functionality may be provided in a different way. A program that strictly depends on support for
a feature can just try to use the feature unconditionally; presumably, on an implementation
lacking necessary support, translation will fail.)
Table 2 — Significant features in this document
Primary Macro Name
Feature Value Header
Subclause Suffix
Const-
propagate_const
propagating 6.1 201505
wrapper
Generic scope
scope
guard and RAII 6.2 201902
wrapper
Invocation type
invocation_type
6.3.2 201406
traits
Detection
6.3.3 detect 201505
metaprograms
© ISO/IEC 2024 — All rights reserved 5
© ISO/IEC 2024 – All rights reserved
Primary Macro Name
Feature Value Header
Subclause Suffix
Polymorphic
function_polymor-
allocator for 7.2 202211
phic_allocator
std::function
Polymorphic
8.3 memory_resources 201803
memory resources
Non-owning
8.2 observer_ptr 201411
pointer wrapper
Delimited
ostream_joiner
9.2 201411
iterators
Random sampling 10.2 sample 201402
Replacement for
11.1.2 randint 201511
std::rand
6 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
5 Modifications to the C++ Standard Library [mods]
5.1 General [mods.general]
Implementations that conform to this document shall behave as if the modifications contained in
this clause are made to ISO/IEC 14882:2020.
References to clauses within ISO/IEC 14882:2020 are written as "C++20, §3.2".
Unless otherwise specified, the whole of the Library introduction of ISO/IEC 14882:2020 (C++20,
§16) is included into this document by reference.
5.2 Exception requirements [mods.exception.requirements]
The following modifications to the Library introduction (C++20, §16) allow the destructor of
scope_success (6.2) to throw exceptions.
The requirements of C++20, §16.4.5.8 shall apply with the following modification: An applicable
Throws: paragraph (in addition to any applicable Required behavior: paragraph) can allow a
replacement function or handler function or destructor operation to exit via an exception.
The requirements of C++20, §16.4.6.13 shall apply with the following modifications: Destructor
operations defined in the C++ standard library are permitted to throw exceptions if this is
explicitly specified. Only those destructors in the C++ standard library that do not have an
exception specification shall behave as if they had a non-throwing exception specification.
© ISO/IEC 2024 — All rights reserved 7
© ISO/IEC 2024 – All rights reserved
6 General utilities library [utilities]
6.1 Constness propagation [propagate_const]
6.1.1 Header synopsis [propagate_const.syn]
namespace std {
namespace experimental::inline fundamentals_v3 {
// 6.1.2.1, Overview
template class propagate_const;
// 6.1.2.9, Relational operators
template
constexpr bool operator==(const propagate_const& pt, nullptr_t);
template
constexpr bool operator==(nullptr_t, const propagate_const& pu);
template
constexpr bool operator!=(const propagate_const& pt, nullptr_t);
template
constexpr bool operator!=(nullptr_t, const propagate_const& pu);
template
constexpr bool operator==(const propagate_const& pt,
const propagate_const& pu);
template
constexpr bool operator!=(const propagate_const& pt,
const propagate_const& pu);
template
constexpr bool operator<(const propagate_const& pt,
const propagate_const& pu);
template
constexpr bool operator>(const propagate_const& pt,
const propagate_const& pu);
template
constexpr bool operator<=(const propagate_const& pt,
const propagate_const& pu);
8 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
template
constexpr bool operator>=(const propagate_const& pt,
const propagate_const& pu);
template
constexpr bool operator==(const propagate_const& pt, const U& u);
template
constexpr bool operator!=(const propagate_const& pt, const U& u);
template
constexpr bool operator<(const propagate_const& pt, const U& u);
template
constexpr bool operator>(const propagate_const& pt, const U& u);
template
constexpr bool operator<=(const propagate_const& pt, const U& u);
template
constexpr bool operator>=(const propagate_const& pt, const U& u);
template
constexpr bool operator==(const T& t, const propagate_const& pu);
template
constexpr bool operator!=(const T& t, const propagate_const& pu);
template
constexpr bool operator<(const T& t, const propagate_const& pu);
template
constexpr bool operator>(const T& t, const propagate_const& pu);
template
constexpr bool operator<=(const T& t, const propagate_const& pu);
template
constexpr bool operator>=(const T& t, const propagate_const& pu);
// 6.1.2.10, Specialized algorithms
template
constexpr void swap(propagate_const& pt,
propagate_const& pt2) noexcept(see below);
// 6.1.2.11, Underlying pointer access
template
constexpr const T& get_underlying(const propagate_const& pt) noexcept;
© ISO/IEC 2024 — All rights reserved 9
© ISO/IEC 2024 – All rights reserved
template
constexpr T& get_underlying(propagate_const& pt) noexcept;
} // namespace experimental::inline fundamentals_v3
// 6.1.2.12, Hash support
template struct hash;
template
struct hash>;
// 6.1.2.13, Comparison function objects
template struct equal_to;
template
struct equal_to>;
template struct not_equal_to;
template
struct not_equal_to>;
template struct less;
template
struct less>;
template struct greater;
template
struct greater>;
template struct less_equal;
template
struct less_equal>;
template struct greater_equal;
template
struct greater_equal>;
} // namespace std
6.1.2 Class template propagate_const [propagate_const.tmpl]
6.1.2.1 Overview [propagate_const.overview]
namespace std::experimental::inline fundamentals_v3 {
template class propagate_const {
10 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
public:
using element_type = remove_reference_t())>;
// 6.1.2.4, Constructors
constexpr propagate_const() = default;
propagate_const(const propagate_const& p) = delete;
constexpr propagate_const(propagate_const&& p) = default;
template
explicit(!is_convertible_v)
constexpr propagate_const(propagate_const&& pu);
template
explicit(!is_convertible_v)
constexpr propagate_const(U&& u);
// 6.1.2.5, Assignment
propagate_const& operator=(const propagate_const& p) = delete;
constexpr propagate_const& operator=(propagate_const&& p) = default;
template
constexpr propagate_const& operator=(propagate_const&& pu);
template
constexpr propagate_const& operator=(U&& u);
// 6.1.2.6, Const observers
explicit constexpr operator bool() const;
constexpr const element_type* operator->() const;
constexpr operator const element_type*() const; // Not always defined
constexpr const element_type& operator*() const;
constexpr const element_type* get() const;
// 6.1.2.7, Non-const observers
constexpr element_type* operator->();
constexpr operator element_type*(); // Not always defined
constexpr element_type& operator*();
constexpr element_type* get();
// 6.1.2.8, Modifiers
constexpr void swap(propagate_const& pt) noexcept(is_nothrow_swappable);
© ISO/IEC 2024 — All rights reserved 11
© ISO/IEC 2024 – All rights reserved
private:
T t_; //exposition only
};
} // namespace std::experimental::inline fundamentals_v3
propagate_const is a wrapper around a pointer-like object type T which treats the wrapped
pointer as a pointer to const when the wrapper is accessed through a const access path.
6.1.2.2 General requirements on T [propagate_const.requirements]
T shall be a cv-unqualified pointer-to-object type or a cv-unqualified class type for which
decltype(*declval()) is an lvalue reference to object type; otherwise the program is ill-
formed.
NOTE propagate_const is well-formed but propagate_const is not.
6.1.2.3 Requirements on class type T [propagate_const.class_type_requirements]
If T is class type then it shall satisfy the requirements described in this subclause and in Table 3.
In this subclause t denotes an lvalue of type T, ct denotes as_const(t).
T and const T shall be contextually convertible to bool.
If T is implicitly convertible to element_type*, (element_type*)t == t.get() shall be true.
If const T is implicitly convertible to const element_type*,
(const element_type*)ct == ct.get() shall be true.
Table 3 — Requirements on class types T
Expression Return type Pre-conditions Operational semantics
t.get() element_type*
const element_type*
ct.get() t.get() == ct.get().
or element_type*
*t refers to the same object as
*t element_type& t.get() != nullptr
*(t.get())
const element_type& *ct refers to the same object as
*ct ct.get() != nullptr
or element_type& *(ct.get())
t.operator->() element_type* t.get() != nullptr t.operator->() == t.get()
const element_type*
ct.operator->() ct.get() != nullptr ct.operator->() == ct.get()
or element_type*
(bool)t is equivalent to
(bool)t bool
t.get() != nullptr
12 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
(bool)ct is equivalent to
(bool)ct bool
ct.get() != nullptr
6.1.2.4 Constructors [propagate_const.ctor]
template
explicit(!is_convertible_v)
constexpr propagate_const(propagate_const&& pu);
Constraints: is_constructible_v is true.
Effects: Initializes t_ as if direct-non-list-initializing an object of type T with the expression
std::move(pu.t_).
template
explicit(!is_convertible_v) constexpr propagate_const(U&& u);
Constraints: is_constructible_v is true and decay_t is not a specialization of
propagate_const.
Effects: Initializes t_ as if direct-non-list-initializing an object of type T with the expression
std::forward(u).
6.1.2.5 Assignment [propagate_const.assignment]
template
constexpr propagate_const& operator=(propagate_const&& pu);
Constraints: U is implicitly convertible to T.
Effects: t_ = std::move(pu.t_).
Returns: *this.
template
constexpr propagate_const& operator=(U&& u);
Constraints: U is implicitly convertible to T and decay_t is not a specialization of
propagate_const.
Effects: t_ = std::forward(u).
Returns: *this.
© ISO/IEC 2024 — All rights reserved 13
© ISO/IEC 2024 – All rights reserved
6.1.2.6 Const observers [propagate_const.const_observers]
explicit constexpr operator bool() const;
Returns: (bool)t_.
constexpr const element_type* operator->() const;
Preconditions: get() != nullptr.
Returns: get().
constexpr operator const element_type*() const;
Constraints: T is an object pointer type or has an implicit conversion to
const element_type*.
Returns: get().
constexpr const element_type& operator*() const;
Preconditions: get() != nullptr.
Returns: *get().
constexpr const element_type* get() const;
Returns: t_ if T is an object pointer type, otherwise t_.get().
6.1.2.7 Non-const observers [propagate_const.non_const_observers]
constexpr element_type* operator->();
Preconditions: get() != nullptr.
Returns: get().
constexpr operator element_type*();
Constraints: T is an object pointer type or has an implicit conversion to element_type*.
Returns: get().
14 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
constexpr element_type& operator*();
Preconditions: get() != nullptr.
Returns: *get().
constexpr element_type* get();
Returns: t_ if T is an object pointer type, otherwise t_.get().
6.1.2.8 Modifiers [propagate_const.modifiers]
constexpr void swap(propagate_const& pt) noexcept(is_nothrow_swappable);
Preconditions: Lvalues of type T are swappable (C++20, §16.4.4.3).
Effects: swap(t_, pt.t_).
6.1.2.9 Relational operators [propagate_const.relational]
template
constexpr bool operator==(const propagate_const& pt, nullptr_t);
Returns: pt.t_ == nullptr.
template
constexpr bool operator==(nullptr_t, const propagate_const& pt);
Returns: nullptr == pt.t_.
template
constexpr bool operator!=(const propagate_const& pt, nullptr_t);
Returns: pt.t_ != nullptr.
template
constexpr bool operator!=(nullptr_t, const propagate_const& pt);
Returns: nullptr != pt.t_.
template
constexpr bool operator==(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ == pu.t_.
© ISO/IEC 2024 — All rights reserved 15
© ISO/IEC 2024 – All rights reserved
template
constexpr bool operator!=(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ != pu.t_.
template
constexpr bool operator<(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ < pu.t_.
template
constexpr bool operator>(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ > pu.t_.
template
constexpr bool operator<=(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ <= pu.t_.
template
constexpr bool operator>=(const propagate_const& pt,
const propagate_const& pu);
Returns: pt.t_ >= pu.t_.
template
constexpr bool operator==(const propagate_const& pt, const U& u);
Returns: pt.t_ == u.
template
constexpr bool operator!=(const propagate_const& pt, const U& u);
Returns: pt.t_ != u.
template
constexpr bool operator<(const propagate_const& pt, const U& u);
Returns: pt.t_ < u.
16 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
template
constexpr bool operator>(const propagate_const& pt, const U& u);
Returns: pt.t_ > u.
template
constexpr bool operator<=(const propagate_const& pt, const U& u);
Returns: pt.t_ <= u.
template
constexpr bool operator>=(const propagate_const& pt, const U& u);
Returns: pt.t_ >= u.
template
constexpr bool operator==(const T& t, const propagate_const& pu);
Returns: t == pu.t_.
template
constexpr bool operator!=(const T& t, const propagate_const& pu);
Returns: t != pu.t_.
template
constexpr bool operator<(const T& t, const propagate_const& pu);
Returns: t < pu.t_.
template
constexpr bool operator>(const T& t, const propagate_const& pu);
Returns: t > pu.t_.
template
constexpr bool operator<=(const T& t, const propagate_const& pu);
Returns: t <= pu.t_.
template
constexpr bool operator>=(const T& t, const propagate_const& pu);
Returns: t >= pu.t_.
© ISO/IEC 2024 — All rights reserved 17
© ISO/IEC 2024 – All rights reserved
6.1.2.10 Specialized algorithms [propagate_const.algorithms]
template
constexpr void swap(propagate_const& pt1,
propagate_const& pt2) noexcept(see below);
Constraints: is_swappable_v is true.
Effects: Equivalent to: pt1.swap(pt2).
Remarks: The expression inside noexcept is equivalent to:
noexcept(pt1.swap(pt2))
6.1.2.11 Underlying pointer access [propagate_const.underlying]
Access to the underlying object pointer type is through free functions rather than member
functions. These functions are intended to resemble cast operations to encourage caution when
using them.
template
constexpr const T& get_underlying(const propagate_const& pt) noexcept;
Returns: a reference to the underlying object pointer type.
template
constexpr T& get_underlying(propagate_const& pt) noexcept;
Returns: a reference to the underlying object pointer type.
6.1.2.12 Hash support [propagate_const.hash]
template
struct hash>;
The specialization hash> is
enabled (C++20, §20.14.19) if and only if hash is enabled. When enabled, for an object p
of type propagate_const,
hash>()(p) evaluates to the same
value as hash()(p.t_).
18 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
6.1.2.13 Comparison function objects[propagate_const.comparison_function_objects]
template
struct equal_to>;
For objects p, q of type propagate_const,
equal_to>()(p, q) shall
evaluate to the same value as equal_to()(p.t_, q.t_).
Mandates: The specialization equal_to is well-formed.
Preconditions: The specialization equal_to is well-defined.
template
struct not_equal_to>;
For objects p, q of type propagate_const,
not_equal_to>()(p, q) shall
evaluate to the same value as not_equal_to()(p.t_, q.t_).
Mandates: The specialization not_equal_to is well-formed.
Preconditions: The specialization not_equal_to is well-defined.
template
struct less>;
For objects p, q of type propagate_const,
less>()(p, q) shall evaluate to
the same value as less()(p.t_, q.t_).
Mandates: The specialization less is well-formed.
Preconditions: The specialization less is well-defined.
template
struct greater>;
For objects p, q of type propagate_const,
greater>()(p, q) shall evaluate
to the same value as greater()(p.t_, q.t_).
Mandates: The specialization greater is well-formed.
Preconditions: The specialization greater is well-defined.
© ISO/IEC 2024 — All rights reserved 19
© ISO/IEC 2024 – All rights reserved
template
struct less_equal>;
For objects p, q of type propagate_const,
less_equal>()(p, q) shall
evaluate to the same value as less_equal()(p.t_, q.t_).
Mandates: The specialization less_equal is well-formed.
Preconditions: The specialization less_equal is well-defined.
template
struct greater_equal>;
For objects p, q of type propagate_const,
greater_equal>()(p, q) shall
evaluate to the same value as greater_equal()(p.t_, q.t_).
Mandates: The specialization greater_equal is well-formed.
Preconditions: The specialization greater_equal is well-defined.
6.2 Scope guard support [scopeguard]
6.2.1 Header synopsis [scope.syn]
namespace std::experimental::inline fundamentals_v3 {
// 6.2.2, Class templates scope_exit, scope_fail, and scope_success
template
class scope_exit;
template
class scope_fail;
template
class scope_success;
// 6.2.3, Class template unique_resource
template
class unique_resource;
// 6.2.3.6, unique_resource creation
template >
unique_resource, decay_t>
20 © ISO/IEC 2024 — All rights reserved
© ISO/IEC 2024 – All rights reserved
make_unique_resource_checked(
R&& r, const S& invalid, D&& d) noexcept(see below);
} // namespace std::experimental::inline fundamentals_v3
6.2.2 Class templates scope_exit, scope_fail, and scope_success [scopeguard.exit]
The class templates scope_exit, scope_fail, and scope_success define scope guards that wrap
a function object to be called on their destruction.
In this subclause, the placeholder scope-guard denotes each of these class templates. In
descriptions of the class members, scope-guard refers to the enclosing class.
namespace std::experimental::inline fundamentals_v3 {
template class scope-guard {
public:
template
explicit scope-guard(EFP&& f) noexcept(see below);
scope-guard(scope-guard&& rhs) noexcept(see below);
scope-guard(const scope-guard&) = delete;
scope-guard& operator=(const scope-guard&) = delete;
scope-guard& operator=(scope-guard&&) = delete;
~scope-guard () noexcept(see below);
void release() noexcept;
private:
EF exit_function; // exposition only
bool execute_on_destruction{true}; // exposition only
int uncaught_on_creation{uncaught_exceptions()}; // exposition only
};
template
scope-guard(EF) -> scope-guard;
} // namespace std::experimental::inline fundamentals_v3
The class template scope_exit is a general-purpose scope guard that calls its exit function when
© ISO/IEC 2024 — All rights reserved 21
© ISO/IEC 2024 – All rights reserved
a scope is exited. The class templates scope_fail and scope_success share the scope_exit
interface, only the situation when the exit function is called differs.
EXAMPLE
void grow(vector& v) {
scope_success guard([]{ cout << "Good!" << endl; });
v.resize(1024);
}
NOTE 1 If the exit function object of a scope_success or scope_exit object refers to a local variable of
the function where it is defined, e.g., as a lambda capturing the variable by reference, and that variable is
used as a return operand in that function, it is possible for that variable to already have been returned
when the scope-guard’s destructor executes, calling the exit function. This can lead to surprising behavior.
Template argument EF shall be a function object type (C++20, §20.14), lvalue reference to
function, or lvalue reference to function object type. If
...








Questions, Comments and Discussion
Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.
Loading comments...