Namespaces
Variants
Views
Actions

deduction guides for std::function

From cppreference.com
< cpp‎ | utility‎ | functional‎ | function
 
 
 
Function objects
Function wrappers
(C++11)
(C++11)
(C++17)
Bind
(C++11)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
(deprecated)
(deprecated)

(deprecated)
(deprecated)
Searchers
Old binders and adaptors
(until C++17)
(until C++17)
(until C++17)
(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
(until C++17)(until C++17)
(until C++17)(until C++17)

(until C++17)
(until C++17)(until C++17)(until C++17)(until C++17)
 
 
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 refrence 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.

[edit] 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)>
}