# deduction guides for `std::function`

From cppreference.com
< cpp‎ | utility‎ | functional‎ | function

Defined in header `<functional>` |  |
template<class R, class... ArgTypes> function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>; | (1) | (since C++17)
template<class F> function(F) -> function</*see below*/>; | (2) | (since C++17)

1) This deduction guide is provided for std::function to allow deduction from functions.
2) If decltype(&F::operator()) is of the form R(G::*)(A...) (optionally cv-qualified, optionally noexcept, optionally lvalue reference qualified) for some class type G, then the deduced type is std::function<R(A...)>. This overload only participates in overload resolution if &F::operator() is well-formed when treated as an unevaluated operand.

### Notes

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

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)>
    }

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/function/deduction_guides&oldid=104227"