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

> C++ Atlas: `cppatlas.com/w/cpp/utility/functional/function/target_type` | Source: https://en.cppreference.com/w/cpp/utility/functional/function/target_type | Domain: Utility | Standards: C++11

Returns the type of the stored function.

## Official Specification Summary (cppreference)

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

Returns the type of the stored function.

### Parameters

(none)

### Return value

`typeid(T)` if the stored function has type `T`, otherwise `typeid(void)`

### Example

```cpp
#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:

```text
PFiiE
Z4mainEUliE_
PFvdE
```

### See also

- [`target`](https://en.cppreference.com/w/cpp/utility/functional/function/target): obtains a pointer to the stored target (public member function)
- [`type_info`](https://en.cppreference.com/w/cpp/types/type_info): contains some type’s information, the class returned by the typeid operator (class)
- [`typeid`](https://en.cppreference.com/w/cpp/language/typeid): queries information of a type, returning a `std::type_info` object representing the type (operator)

---
Attribution: content from https://en.cppreference.com/w/cpp/utility/functional/function/target_type (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.