std::function::target_type(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

okay bestie, welcome to the std::function::target_type(3) page from the C++ Standard Libary πŸ’… this is the manual for std::function::target_type - std::function::target_type, and yes, the name is literally the name. no notes. iconic.

🌸 Synopsis 🌸

this is the signature, and she has been serving since C++11:

const std::type_info& target_type() const noexcept;  (since C++11)

she returns the type of the stored function. periodt.

πŸŽ€ Parameters πŸŽ€

bestie. there are none. literally (none). the parameter list is empty and living her best life.

πŸ¦‹ Return value πŸ¦‹

if the stored function has type T, you get typeid(T); otherwise you get typeid(void). that's the whole situation. πŸ’–

πŸ”₯ Example πŸ”₯

run this code, it's right here:

// 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 not
    std::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 avail
    std::cout << std::function{g}.target_type().name() << '\n';
}

πŸ’€ Possible output πŸ’€

your output could look like this:

PFiiE
Z4mainEUliE_
PFvdE

πŸ‘‘ See also πŸ‘‘

  • target β€” obtains a pointer to the stored target (public member function)
  • typeid β€” Queries information of a type, returning a std::type_info object representing the type.
  • type_info β€” This is the class returned by the typeid operator. contains some type's information, generated by the implementation. (class)

catch you later bestie 🫢 this little page came from http://cppreference.com, dated 2024.06.10, for std::function::target_type(3). mwah πŸ’‹

πŸ“¦ where this page comes from