deductiongu...td::function(3)
π NAME π
deductionguidesforstd::function β deductionguidesforstd::function. Yep, the page says it twice, and honestly? Iconic.
This is the deductiongu...td::function(3) page from the C++ Standard Libary (spelled exactly like that in the header, no cap), and it's all about the deduction guides for std::function. π«Ά
β¨ Synopsis β¨
Defined in header <functional>
template< class R, class... ArgTypes > (1) (since C++17)
function( R(*)(ArgTypes...) ) -> function<R(ArgTypes...)>;
template< class F > (2) (since C++17)
function( F ) -> function</*see below*/>;
template< class F > (3) (since C++23)
function( F ) -> function</*see below*/>;
template< class F > (4) (since C++23)
function( F ) -> function</*see below*/>;
- Guide (1) β this deduction guide is provided for
std::functionto allow deduction from functions. Slay. - Guide (2) β this overload participates in overload resolution only if
&F::operator()is well-formed when treated as an unevaluated operand anddecltype(&F::operator())is of the formR(G::*)(A...)(optionally cv-qualified, optionallynoexcept, optionally lvalue reference qualified). The deduced type isstd::function<R(A...)>. π - Guide (3) β this overload participates in overload resolution only if
&F::operator()is well-formed when treated as an unevaluated operand andF::operator()is an explicit object parameter function whose type is of formR(G, A...)orR(G, A...) noexcept. The deduced type isstd::function<R(A...)>. β¨ - Guide (4) β this overload participates in overload resolution only if
&F::operator()is well-formed when treated as an unevaluated operand andF::operator()is a static member function whose type is of formR(A...)orR(A...) noexcept. The deduced type isstd::function<R(A...)>. π¦
π§ Notes π§
No cap, these deduction guides do not allow deduction from a function with ellipsis parameter, and the ... in the types is always treated as a pack expansion. π
The type deduced by these deduction guides may change in a later standard revision (in particular, this might happen if noexcept support is added to std::function in a later standard). So like, future-you has been warned. π₯
π Example π
// Run this code
#include <functional>
int func(double) { return 0; }
int main() {
std::function f{func}; // guide #1 deduces function<int(double)>
int i = 5;
std::function g = [&](double) { return i; }; // guide #2 deduces function<int(double)>
}
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. Time-travel bug fixes, we love to see it. π§
- DR
LWG 3238β applied to C++17.- Behavior as published: behavior of
(2)was unclear whenF::operator()is&&-qualified. - Correct behavior: clarified to be excluded from overload resolution.
- Behavior as published: behavior of
Okay bestie, that's the page. Source/version/date from the footer: http://cppreference.com, 2024.06.10, and deductiongu...td::function(3). Go deduce something iconic π
β¨
π¦ 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