Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/experimental/lib extensions"

From cppreference.com
(Add page.)
 
m (fmt)
 
(47 intermediate revisions by 9 users not shown)
Line 2: Line 2:
 
{{cpp/experimental/lib_extensions/navbar}}
 
{{cpp/experimental/lib_extensions/navbar}}
  
The C++ Extensions for Library Fundamentals technical specification includes the following significant features:
+
Version 1 of the C++ Extensions for Library Fundamentals, ISO/IEC TS 19568:2015 defines the following new components for the C++ standard library:
  
{|table class=wikitable
+
==Not selected for inclusion in C++17==
|-
+
The following components of ISO/IEC TS 19568:2015 were not selected for inclusion in C++17.
!Doc. No.||Title||Macro Name Suffix||Header
+
|-
+
| N3920
+
| Extending {{lc|std::shared_ptr}} to support arrays
+
| {{tt|shared_ptr_arrays}}
+
| {{ltt|cpp/header/memory|<memory>}}
+
|-
+
| N3916
+
| Type-erased allocator for {{lc|std::function}}
+
| {{tt|function_erased_allocator}}
+
| {{ltt|cpp/header/functional|<functional>}}
+
|-
+
| N3843
+
| A SFINAE-Friendly {{lc|std::common_type}}
+
| {{tt|common_type_sfinae}}
+
| {{ltt|cpp/header/type_traits|<type_traits>}}
+
|-
+
| N3923
+
| A SFINAE-Friendly {{lc|std::iterator_traits}}
+
| {{tt|iterator_traits_sfinae}}
+
| {{ltt|cpp/header/iterator|<iterator>}}
+
|-
+
| N3916
+
| Type-erased allocator for {{lc|std::promise}}
+
| {{tt|promise_erased_allocator}}
+
| {{ltt|cpp/header/future|<future>}}
+
|-
+
| N3916
+
| Type-erased allocator for {{lc|std::packaged_task}}
+
| {{tt|packaged_task_erased_allocator}}
+
| {{ltt|cpp/header/future|<future>}}
+
|-
+
| N3915
+
| {{tt|apply()}} call a function with arguments from a tuple
+
| {{tt|apply}}
+
| {{ltt|cpp/header/experimental/tuple|<experimental/tuple>}}
+
|-
+
| N3932
+
| Variable Templates For Type Traits
+
| {{tt|type_trait_variable_templates}}
+
| {{ltt|cpp/header/experimental/type_traits|<experimental/type_traits>}}
+
|-
+
| N3866
+
| Invocation type traits
+
| {{tt|invocation_type}}
+
| {{ltt|cpp/header/experimental/type_traits|<experimental/type_traits>}}
+
|-
+
| N3905
+
| Extending {{lc|std::search}} to use Additional Searching Algorithms
+
| {{tt|boyer_moore_searching}}
+
| {{ltt|cpp/header/experimental/functional|<experimental/functional>}}
+
|-
+
| N3672, N3793
+
| A utility class to represent optional objects
+
| {{tt|optional}}
+
| {{ltt|cpp/header/experimental/optional|<experimental/optional>}}
+
|-
+
| N3804
+
| Any Library Proposal
+
| {{tt|any}}
+
| {{ltt|cpp/header/experimental/any|<experimental/any>}}
+
|-
+
| N3921
+
| {{tt|string_view}}: a non-owning reference to a string
+
| {{tt|string_view}}
+
| {{ltt|cpp/header/experimental/string_view|<experimental/string_view>}}
+
|-
+
| N3916
+
| Polymorphic Memory Resources
+
| {{tt|memory_resources}}
+
| {{ltt|cpp/header/experimental/memory_resource|<experimental/memory_resource>}}
+
|-
+
| N3925
+
| A {{tt|sample}} Proposal
+
| {{tt|sample}}
+
| {{ltt|cpp/header/experimental/algorithm|<experimental/algorithm>}}
+
|-
+
| N3783
+
| Network Byte Order Conversion
+
| {{tt|network_byte_order}}
+
| {{ltt|cpp/header/experimental/net|<experimental/net>}}
+
|}
+
  
 +
====Modified versions of existing classes to support type-erased allocators====
 +
{{dsc begin}}
 +
{{dsc header|experimental/functional}}
 +
{{dsc tclass|cpp/experimental/function|a modified version of {{lc|std::function}} with support for type-erased allocators}}
 +
{{dsc header|experimental/future}}
 +
{{dsc tclass|cpp/experimental/lib extensions/promise|a modified version of {{lc|std::promise}} with support for type-erased allocators}}
 +
{{dsc tclass|cpp/experimental/lib extensions/packaged_task|a modified version of {{lc|std::packaged_task}} with support for type-erased allocators}}
 +
{{dsc end}}
  
{{todo}}
+
====Memory resource adaptors====
 +
{{dsc begin}}
 +
{{dsc talias|cpp/experimental/resource_adaptor|adapts an allocator into a {{lc|memory_resource}}}}
 +
{{dsc end}}
 +
 
 +
===General utilities===
 +
{{dsc begin}}
 +
{{dsc header|experimental/utility}}
 +
{{dsc class|cpp/experimental/erased_type|placeholder type for type erasure, such as in allocators}}
 +
{{dsc header|experimental/type_traits}}
 +
{{dsc tclass|cpp/experimental/invocation_type|title=invocation_type<br/>raw_invocation_type|deduce the implied function type of the callable object when called with the given argument types}}
 +
{{dsc end}}
 +
 
 +
===Feature test macros===
 +
{{dsc begin}}
 +
{{dsc header|experimental/optional}}
 +
{{dsc macro const|__cpp_lib_experimental_optional|nolink=true|a value of at least {{c|201411}} indicates that the optional type is supported}}
 +
{{dsc header|experimental/any}}
 +
{{dsc macro const|__cpp_lib_experimental_any|nolink=true|a value of at least {{c|201411}} indicates that the any type is supported}}
 +
{{dsc header|experimental/string_view}}
 +
{{dsc macro const|__cpp_lib_experimental_string_view|nolink=true|a value of at least {{c|201411}} indicates that basic_string_view template is supported}}
 +
{{dsc header|experimental/tuple}}
 +
{{dsc macro const|__cpp_lib_experimental_apply|nolink=true|a value of at least {{c|201402}} indicates that the tuple apply() function is supported}}
 +
{{dsc header|experimental/type_traits}}
 +
{{dsc macro const|__cpp_lib_experimental_type_trait_variable_templates|nolink=true|a value of at least {{c|201402}} indicates that variable template type traits are supported}}
 +
{{dsc macro const|__cpp_lib_experimental_invocation_type|nolink=true|a value of at least {{c|201406}} indicates that invocation type traits are supported}}
 +
{{dsc header|experimental/functional}}
 +
{{dsc macro const|__cpp_lib_experimental_boyer_moore_searching|nolink=true|a value of at least {{c|201411}} indicates that additional searching algorithms are supported}}
 +
{{dsc macro const|__cpp_lib_experimental_function_erased_allocator|nolink=true|a value of at least {{c|201406}} indicates that type-erased allocator for std::function is supported}}
 +
{{dsc header|experimental/future}}
 +
{{dsc macro const|__cpp_lib_experimental_promise_erased_allocator|nolink=true|a value of at least {{c|201406}} indicates that type-erased allocator for std::promise is supported}}
 +
{{dsc macro const|__cpp_lib_experimental_packaged_task_erased_allocator|nolink=true|a value of at least {{c|201406}} indicates that type-erased allocator for std::packaged_task is supported}}
 +
{{dsc header|experimental/memory}}
 +
{{dsc macro const|__cpp_lib_experimental_shared_ptr_arrays|nolink=true|a value of at least {{c|201406}} indicates that shared_ptr arrays are supported}}
 +
{{dsc header|experimental/memory_resource}}
 +
{{dsc macro const|__cpp_lib_experimental_memory_resources|nolink=true|a value of at least {{c|201402}} indicates that polymorphic memory resources are supported}}
 +
{{dsc header|experimental/algorithm}}
 +
{{dsc macro const|__cpp_lib_experimental_sample|nolink=true|a value of {{c|201402}} indicates that the sample algorithm is supported}}
 +
{{dsc end}}
 +
 
 +
==Merged into C++17==
 +
The following components of ISO/IEC TS 19568:2015 were included into C++17.
 +
 
 +
===optional objects===
 +
{{dsc begin}}
 +
{{dsc header|experimental/optional}}
 +
{{dsc tclass|cpp/experimental/optional|a class template representing ''optional objects''}}
 +
{{dsc end}}
 +
 
 +
===class {{tt|any}}===
 +
{{dsc begin}}
 +
{{dsc header|experimental/any}}
 +
{{dsc class|cpp/experimental/any|a type-safe container for single values of any type}}
 +
{{dsc end}}
 +
 
 +
==={{tt|string_view}}===
 +
{{dsc begin}}
 +
{{dsc header|experimental/string_view}}
 +
{{dsc tclass|cpp/experimental/basic_string_view|a non-owning reference to a string}}
 +
{{dsc end}}
 +
 
 +
===Type-erased and polymorphic allocators===
 +
 
 +
====Polymorphic allocators and memory resources====
 +
The entities in this section are declared in the {{lc|std::experimental::pmr}} namespace.
 +
 
 +
{{dsc begin}}
 +
{{dsc header|experimental/memory_resource}}
 +
{{dsc class|cpp/experimental/memory_resource| an abstract interface for classes that encapsulate memory resources}}
 +
{{dsc inc|cpp/experimental/pmr/dsc synchronized_pool_resource}}
 +
{{dsc inc|cpp/experimental/pmr/dsc unsynchronized_pool_resource}}
 +
{{dsc class|cpp/experimental/monotonic_buffer_resource|a special-purpose {{lc|memory_resource}} that releases the allocated memory only when the resource is destroyed}}
 +
{{dsc tclass|cpp/experimental/polymorphic_allocator|an allocator that supports run-time polymorphism based on the {{lc|memory_resource}} it is constructed with}}
 +
{{dsc inc|cpp/experimental/pmr/dsc new_delete_resource}}
 +
{{dsc inc|cpp/experimental/pmr/dsc null_memory_resource}}
 +
{{dsc inc|cpp/experimental/pmr/dsc get_default_resource}}
 +
{{dsc inc|cpp/experimental/pmr/dsc set_default_resource}}
 +
{{dsc end}}
 +
 
 +
====Convenience aliases for containers using polymorphic allocators====
 +
[[cpp/experimental/lib extensions/pmr_container|Convenience aliases and alias templates]] for containers using polymorphic allocators are provided in the {{tt|std::experimental::pmr}} namespace for the following class templates in the standard library:
 +
{{collapse top|List of container templates for which convenience aliases are provided}}
 +
{{div col|3}}
 +
* {{lc|std::vector}}
 +
* {{lc|std::deque}}
 +
* {{lc|std::forward_list}}
 +
* {{lc|std::list}}
 +
* {{lc|std::basic_string}}
 +
* {{lc|std::map}}
 +
* {{lc|std::multimap}}
 +
* {{lc|std::set}}
 +
* {{lc|std::multiset}}
 +
* {{lc|std::match_results}}
 +
* {{lc|std::unordered_map}}
 +
* {{lc|std::unordered_multimap}}
 +
* {{lc|std::unordered_set}}
 +
* {{lc|std::unordered_multiset}}
 +
{{div col end}}
 +
{{collapse bottom}}
 +
 
 +
===Array support for {{tt|shared_ptr}}===
 +
{{dsc begin}}
 +
{{dsc header|experimental/memory}}
 +
{{dsc hitem|Class|Description}}
 +
{{dsc tclass|cpp/experimental/shared_ptr|a modified version of {{lc|std::shared_ptr}} that supports arrays}}
 +
{{dsc tclass|cpp/experimental/weak_ptr|a modified version of {{lc|std::weak_ptr}} that supports arrays}}
 +
{{dsc end}}
 +
 
 +
===Sampling and searching algorithms===
 +
{{dsc begin}}
 +
{{dsc header|experimental/algorithm}}
 +
{{dsc tfun|cpp/experimental/sample|selects n random elements from a sequence}}
 +
{{dsc tfun|cpp/experimental/search|applies a Searcher to a sequence}}
 +
{{dsc header|experimental/functional}}
 +
{{dsc tclass|cpp/experimental/default_searcher|standard C++ library search algorithm implementation}}
 +
{{dsc tfun|cpp/experimental/default_searcher|title=make_default_searcher|helper function to create a default_searcher}}
 +
{{dsc tclass|cpp/experimental/boyer_moore_searcher|Boyer-Moore search algorithm implementation}}
 +
{{dsc tfun|cpp/experimental/boyer_moore_searcher|title=make_boyer_moore_searcher|helper function to create a boyer_moore_searcher}}
 +
{{dsc tclass|cpp/experimental/boyer_moore_horspool_searcher|Boyer-Moore-Horspool search algorithm implementation}}
 +
{{dsc tfun|cpp/experimental/boyer_moore_horspool_searcher|title= make_boyer_moore_horspool_searcher|helper function to create a boyer_moore_horspool_searcher}}
 +
{{dsc end}}
 +
 
 +
===General utilities===
 +
{{dsc begin}}
 +
{{dsc header|experimental/tuple}}
 +
{{dsc tfun|cpp/experimental/apply|calls a function to a tuple of arguments}}
 +
{{dsc end}}
 +
 
 +
In addition, the TS provides [[cpp/experimental/type_trait_variable_templates|numerous {{tt|constexpr}} variable templates]] for the following type traits and other class templates in the standard library:
 +
{{collapse top|List of type traits and other class templates for which variable templates are provided}}
 +
{{div col|2}}
 +
* {{lc|std::is_void}}
 +
* {{lc|std::is_null_pointer}}
 +
* {{lc|std::is_integral}}
 +
* {{lc|std::is_floating_point}}
 +
* {{lc|std::is_array}}
 +
* {{lc|std::is_pointer}}
 +
* {{lc|std::is_lvalue_reference}}
 +
* {{lc|std::is_rvalue_reference}}
 +
* {{lc|std::is_member_object_pointer}}
 +
* {{lc|std::is_member_function_pointer}}
 +
* {{lc|std::is_enum}}
 +
* {{lc|std::is_union}}
 +
* {{lc|std::is_class}}
 +
* {{lc|std::is_function}}
 +
* {{lc|std::is_reference}}
 +
* {{lc|std::is_arithmetic}}
 +
* {{lc|std::is_fundamental}}
 +
* {{lc|std::is_object}}
 +
* {{lc|std::is_scalar}}
 +
* {{lc|std::is_compound}}
 +
* {{lc|std::is_member_pointer}}
 +
* {{lc|std::is_const}}
 +
* {{lc|std::is_volatile}}
 +
* {{lc|std::is_trivial}}
 +
* {{lc|std::is_trivially_copyable}}
 +
* {{lc|std::is_standard_layout}}
 +
* {{lc|std::is_pod}}
 +
* {{lc|std::is_literal_type}}
 +
* {{lc|std::is_empty}}
 +
* {{lc|std::is_polymorphic}}
 +
* {{lc|std::is_abstract}}
 +
* {{lc|std::is_final}}
 +
* {{lc|std::is_signed}}
 +
* {{lc|std::is_unsigned}}
 +
* {{lc|std::is_constructible}}
 +
* {{lc|std::is_trivially_constructible}}
 +
* {{lc|std::is_nothrow_constructible}}
 +
* {{lc|std::is_default_constructible}}
 +
* {{lc|std::is_trivially_default_constructible}}
 +
* {{lc|std::is_nothrow_default_constructible}}
 +
* {{lc|std::is_copy_constructible}}
 +
* {{lc|std::is_trivially_copy_constructible}}
 +
* {{lc|std::is_nothrow_copy_constructible}}
 +
* {{lc|std::is_move_constructible}}
 +
* {{lc|std::is_trivially_move_constructible}}
 +
* {{lc|std::is_nothrow_move_constructible}}
 +
* {{lc|std::is_assignable}}
 +
* {{lc|std::is_trivially_assignable}}
 +
* {{lc|std::is_nothrow_assignable}}
 +
* {{lc|std::is_copy_assignable}}
 +
* {{lc|std::is_trivially_copy_assignable}}
 +
* {{lc|std::is_nothrow_copy_assignable}}
 +
* {{lc|std::is_move_assignable}}
 +
* {{lc|std::is_trivially_move_assignable}}
 +
* {{lc|std::is_nothrow_move_assignable}}
 +
* {{lc|std::is_destructible}}
 +
* {{lc|std::is_trivially_destructible}}
 +
* {{lc|std::is_nothrow_destructible}}
 +
* {{lc|std::has_virtual_destructor}}
 +
* {{lc|std::alignment_of}}
 +
* {{lc|std::rank}}
 +
* {{lc|std::extent}}
 +
* {{lc|std::is_same}}
 +
* {{lc|std::is_base_of}}
 +
* {{lc|std::is_convertible}}
 +
* {{lc|std::ratio_equal}}
 +
* {{lc|std::ratio_not_equal}}
 +
* {{lc|std::ratio_less}}
 +
* {{lc|std::ratio_less_equal}}
 +
* {{lc|std::ratio_greater}}
 +
* {{lc|std::ratio_greater_equal}}
 +
* {{lc|std::tuple_size}}
 +
* {{lc|std::chrono::treat_as_floating_point}}
 +
* {{lc|std::is_error_code_enum}}
 +
* {{lc|std::is_error_condition_enum}}
 +
* {{lc|std::is_bind_expression}}
 +
* {{lc|std::is_placeholder}}
 +
* {{lc|std::uses_allocator}}
 +
{{div col end}}
 +
{{collapse bottom}}
 +
 
 +
{{langlinks|de|es|ja|ru|zh}}

Latest revision as of 00:10, 28 November 2023

 
 
Experimental
Technical Specification
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals TS v2)
Library fundamentals 3 (library fundamentals TS v3)
Extensions for parallelism (parallelism TS)
Extensions for parallelism 2 (parallelism TS v2)
Extensions for concurrency (concurrency TS)
Extensions for concurrency 2 (concurrency TS v2)
Concepts (concepts TS)
Ranges (ranges TS)
Reflection (reflection TS)
Mathematical special functions (special functions TR)
Experimental Non-TS
Pattern Matching
Linear Algebra
std::execution
Contracts
2D Graphics
 
 

Version 1 of the C++ Extensions for Library Fundamentals, ISO/IEC TS 19568:2015 defines the following new components for the C++ standard library:

Contents

[edit] Not selected for inclusion in C++17

The following components of ISO/IEC TS 19568:2015 were not selected for inclusion in C++17.

[edit] Modified versions of existing classes to support type-erased allocators

Defined in header <experimental/functional>
a modified version of std::function with support for type-erased allocators
(class template)
Defined in header <experimental/future>
a modified version of std::promise with support for type-erased allocators
(class template)
a modified version of std::packaged_task with support for type-erased allocators
(class template)

[edit] Memory resource adaptors

adapts an allocator into a memory_resource
(alias template)

[edit] General utilities

Defined in header <experimental/utility>
placeholder type for type erasure, such as in allocators
(class)
Defined in header <experimental/type_traits>
deduce the implied function type of the callable object when called with the given argument types
(class template)

[edit] Feature test macros

Defined in header <experimental/optional>
__cpp_lib_experimental_optional
a value of at least 201411 indicates that the optional type is supported
(macro constant)
Defined in header <experimental/any>
__cpp_lib_experimental_any
a value of at least 201411 indicates that the any type is supported
(macro constant)
Defined in header <experimental/string_view>
__cpp_lib_experimental_string_view
a value of at least 201411 indicates that basic_string_view template is supported
(macro constant)
Defined in header <experimental/tuple>
__cpp_lib_experimental_apply
a value of at least 201402 indicates that the tuple apply() function is supported
(macro constant)
Defined in header <experimental/type_traits>
__cpp_lib_experimental_type_trait_variable_templates
a value of at least 201402 indicates that variable template type traits are supported
(macro constant)
__cpp_lib_experimental_invocation_type
a value of at least 201406 indicates that invocation type traits are supported
(macro constant)
Defined in header <experimental/functional>
__cpp_lib_experimental_boyer_moore_searching
a value of at least 201411 indicates that additional searching algorithms are supported
(macro constant)
__cpp_lib_experimental_function_erased_allocator
a value of at least 201406 indicates that type-erased allocator for std::function is supported
(macro constant)
Defined in header <experimental/future>
__cpp_lib_experimental_promise_erased_allocator
a value of at least 201406 indicates that type-erased allocator for std::promise is supported
(macro constant)
__cpp_lib_experimental_packaged_task_erased_allocator
a value of at least 201406 indicates that type-erased allocator for std::packaged_task is supported
(macro constant)
Defined in header <experimental/memory>
__cpp_lib_experimental_shared_ptr_arrays
a value of at least 201406 indicates that shared_ptr arrays are supported
(macro constant)
__cpp_lib_experimental_memory_resources
a value of at least 201402 indicates that polymorphic memory resources are supported
(macro constant)
Defined in header <experimental/algorithm>
__cpp_lib_experimental_sample
a value of 201402 indicates that the sample algorithm is supported
(macro constant)

[edit] Merged into C++17

The following components of ISO/IEC TS 19568:2015 were included into C++17.

[edit] optional objects

Defined in header <experimental/optional>
a class template representing optional objects
(class template)

[edit] class any

Defined in header <experimental/any>
a type-safe container for single values of any type
(class)

[edit] string_view

Defined in header <experimental/string_view>
a non-owning reference to a string
(class template)

[edit] Type-erased and polymorphic allocators

[edit] Polymorphic allocators and memory resources

The entities in this section are declared in the std::experimental::pmr namespace.

an abstract interface for classes that encapsulate memory resources
(class)
a thread-safe memory_resource for managing allocations in pools of different block sizes
(class) [edit]
a thread-unsafe memory_resource for managing allocations in pools of different block sizes
(class) [edit]
a special-purpose memory_resource that releases the allocated memory only when the resource is destroyed
(class)
an allocator that supports run-time polymorphism based on the memory_resource it is constructed with
(class template)
returns a static program-wide memory_resource that uses the global operator new and operator delete to allocate and deallocate memory
(function) [edit]
returns a static memory_resource that performs no allocation
(function) [edit]
gets the default memory_resource
(function) [edit]
sets the default memory_resource
(function) [edit]

[edit] Convenience aliases for containers using polymorphic allocators

Convenience aliases and alias templates for containers using polymorphic allocators are provided in the std::experimental::pmr namespace for the following class templates in the standard library:

List of container templates for which convenience aliases are provided

[edit] Array support for shared_ptr

Defined in header <experimental/memory>
Class Description
a modified version of std::shared_ptr that supports arrays
(class template)
a modified version of std::weak_ptr that supports arrays
(class template)

[edit] Sampling and searching algorithms

Defined in header <experimental/algorithm>
selects n random elements from a sequence
(function template)
applies a Searcher to a sequence
(function template)
Defined in header <experimental/functional>
standard C++ library search algorithm implementation
(class template)
helper function to create a default_searcher
(function template)
Boyer-Moore search algorithm implementation
(class template)
helper function to create a boyer_moore_searcher
(function template)
Boyer-Moore-Horspool search algorithm implementation
(class template)
helper function to create a boyer_moore_horspool_searcher
(function template)

[edit] General utilities

Defined in header <experimental/tuple>
calls a function to a tuple of arguments
(function template)

In addition, the TS provides numerous constexpr variable templates for the following type traits and other class templates in the standard library:

List of type traits and other class templates for which variable templates are provided