Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::function<R(Args...)>::target_type

      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*)
       
       
      conststd::type_info& target_type()constnoexcept;
      (since C++11)

      Returns the type of the stored function.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      typeid(T) if the stored function has typeT, otherwisetypeid(void)

      [edit]Example

      Run this code
      #include <functional>#include <iostream> int f(int a){return-a;}void g(double){}int main(){// fn1 and fn2 have the same type, but their targets do notstd::function<int(int)> fn1(f),                            fn2([](int a){return-a;});std::cout<< fn1.target_type().name()<<'\n'<< fn2.target_type().name()<<'\n'; // since C++17 deduction guides (CTAD) can availstd::cout<<std::function{g}.target_type().name()<<'\n';}

      Possible output:

      PFiiEZ4mainEUliE_PFvdE

      [edit]See also

      obtains a pointer to the stored target
      (public member function)[edit]
      contains some type’s information, the class returned by the typeid operator
      (class)[edit]
      typeid queries information of a type, returning astd::type_info object representing the type
      (operator)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/function/target_type&oldid=176892"

      [8]ページ先頭

      ©2009-2025 Movatter.jp