std::move_o...nly_function(3)
std::move_o...nly_function(3) β okay so this is from the C++ Standard Libary manual (yes, βLibaryβ, thatβs canon π
), and itβs all about the constructors for std::move_only_function.
π NAME π
The NAME line is literally std::move_only_function::move_only_function - std::move_only_function::move_only_function β it said it twice, and honestly? obsessed with the redundancy π«Ά.
β¨ Synopsis β¨
Creates a new std::move_only_function. Every overload here is (since C++23), bestie.
- (1) (since C++23) β
move_only_function() noexcept; - (2) (since C++23) β
move_only_function( std::nullptr_t ) noexcept; - (3) (since C++23) β
move_only_function( move_only_function&& other ) noexcept; - (4) (since C++23) β
move_only_function( const move_only_function& ) = delete; - (5) (since C++23) β
template< class F > move_only_function( F&& f ); - (6) (since C++23) β
template< class T, class... CArgs > explicit move_only_function( std::in_place_type_t<T>, CArgs&&... args ); - (7) (since C++23) β
template< class T, class U, class... CArgs > explicit move_only_function( std::in_place_type_t<T>, std::initializer_list<U> il, CArgs&&... args );
okay so hereβs the rundown of what each constructor is giving:
- 1,2) The default constructor and the constructor taking
nullptrboth construct an emptystd::move_only_function. clean, empty, no target, no drama π . - 3) Move constructor constructs a
std::move_only_functionwhose target is that ofother.otheris in a valid but unspecified state after move construction. lowkey iconic but also donβt go readingotherafterward expecting a whole personality. - 4) Copy constructor is deleted.
std::move_only_functiondoes not satisfyCopyConstructible. no cap, it does not copy, periodt. - 5) Let
VTbestd::decay_t<F>. Iffis a null function pointer, a null pointer to member value, or an emptystd::move_only_function(may be any specialization), then constructs an emptystd::move_only_function. Otherwise, constructs astd::move_only_functionwhose target is of typeVTand direct-non-list-initialized withstd::forward<F>(f).- This overload participates in overload resolution only if
VTis neither same asmove_only_functionnor a specialization ofstd::in_place_type_t, and/*is-callable-from*/<VT>(see below) is true. - The program is ill-formed if
std::is_constructible_v<VT, F>is not true.
- This overload participates in overload resolution only if
- 6) Let
VTbestd::decay_t<T>. Constructs astd::move_only_functionwhose target is of typeVTand direct-non-list-initialized withstd::forward<CArgs>(args)....- This overload participates in overload resolution only if both
std::is_constructible_v<VT, CArgs...>and/*is-callable-from*/<VT>(see below) are true. - The program is ill-formed if
VTis not the same type asT.
- This overload participates in overload resolution only if both
- 7) Let
VTbestd::decay_t<T>. Constructs astd::move_only_functionwhose target is of typeVTand direct-non-list-initialized withil,std::forward<CArgs>(args)....- This overload participates in overload resolution only if both
std::is_constructible_v<VT, std::initializer_list<U>&, CArgs...>and/*is-callable-from*/<VT>(see below) are true. - The program is ill-formed if
VTis not the same type asT.
- This overload participates in overload resolution only if both
For constructors (5-7), the behavior is undefined if VT does not satisfy the Destructible requirements, or std::is_move_constructible_v<VT> is true but VT does not satisfy the MoveConstructible requirements. not me writing that, itβs literally the page π.
π§ the /*is-callable-from*/<VT> constant π§
The constant /*is-callable-from*/<VT> is dependent on cv, ref, and noex in the template parameter of std::move_only_function as below:
cvempty,refempty,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, VT, Args...> && std::is_invocable_r_v<R, VT&, Args...>cvempty,refempty,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, VT, Args...> && std::is_nothrow_invocable_r_v<R, VT&, Args...>cv=const,refempty,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, const VT, Args...> && std::is_invocable_r_v<R, const VT&, Args...>cv=const,refempty,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, const VT, Args...> && std::is_nothrow_invocable_r_v<R, const VT&, Args...>cvempty,ref=&,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, VT&, Args...>cvempty,ref=&,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, VT&, Args...>cv=const,ref=&,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, const VT&, Args...>cv=const,ref=&,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, const VT&, Args...>cvempty,ref=&&,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, VT, Args...>cvempty,ref=&&,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, VT, Args...>cv=const,ref=&&,noexcept(noex)=noexcept(false)βstd::is_invocable_r_v<R, const VT, Args...>cv=const,ref=&&,noexcept(noex)=noexcept(true)βstd::is_nothrow_invocable_r_v<R, const VT, Args...>
πΈ Parameters πΈ
otherβ anotherstd::move_only_functionto move fromfβ a function or a Callable object to wrapargsβ arguments to construct the target objectilβstd::initializer_listto construct the target object
π₯ Exceptions π₯
- 5-7) May throw
std::bad_allocon allocation failure or propagate the exception thrown by the initialization of the target. No exception is thrown ifVTis a function pointer type or a specialization ofstd::reference_wrapper.
π¦ Example π¦
bestie the Example section is literally leaving us on read:
This section is incompleteReason: no example
π See also π
constructorβ constructs a newstd::functioninstance (public member function of std::function<R(Args...)>)
π Category π
* Todo no exampleβ yes, thatβs the whole category π
thatβs the page, bestie π source/version http://cppreference.com, date 2024.06.10, and the footer is std::move_o...nly_function(3). mwah π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms