Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      deduction guides forstd::function

      From cppreference.com
      <cpp‎ |utility‎ |functional‎ |function
       
       
      Utilities library
       
      Function objects
      Function invocation
      (C++17)(C++23)
      Identity function object
      (C++20)
      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++20*)
      (until C++20*)
      (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++20*)
      (until C++20*)
       
       
      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)
      template<class F>
      function( F)-> function</*see below*/>;
      (3)(since C++23)
      template<class F>
      function( F)-> function</*see below*/>;
      (4)(since C++23)
      1) Thisdeduction guide is provided forstd::function to allow deduction from functions.
      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, optionally noexcept, optionally lvalue reference qualified). The deduced type isstd::function<R(A...)>.
      3) This overload participates in overload resolution only if&F::operator() is well-formed when treated as an unevaluated operand andF::operator() is anexplicit object parameter function whose type is of formR(G, A...) orR(G, A...)noexcept. The deduced type isstd::function<R(A...)>.
      4) This overload participates in overload resolution only if&F::operator() is well-formed when treated as an unevaluated operand andF::operator() is astatic member function whose type is of formR(A...) orR(A...)noexcept. The deduced type isstd::function<R(A...)>.

      [edit]Notes

      These deduction guides do not allow deduction from a function withellipsis parameter, and the... in the types is always treated as apack expansion.

      The type deduced by these deduction guides may change in a later standard revision (in particular, this might happen ifnoexcept support is added tostd::function in a later standard).

      [edit]Example

      Run this code
      #include <functional>int func(double){return0;}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)>}

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3238C++17behavior of(2) was unclear when
      F::operator() is &&-qualified
      clarified to be excluded from overload resolution
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/function/deduction_guides&oldid=141959"

      [8]ページ先頭

      ©2009-2025 Movatter.jp