deduction guides for std::function
Min standard notice:
Header: <functional>
- This deduction guide is provided for std::function to allow deduction from functions.
# Declarations
template< class R, class... ArgTypes >
function( R(*)(ArgTypes...) ) -> function<R(ArgTypes...)>;
(since C++17)
template< class F >
function( F ) -> function</*see below*/>;
(since C++17)
template< class F >
function( F ) -> function</*see below*/>;
(since C++23)
template< class F >
function( F ) -> function</*see below*/>;
(since C++23)
# Notes
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).
# Example
#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
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3238 | C++17 | behavior of (2) was unclear whenF::operator() is &&-qualified | clarified to be excluded from overload resolution |