##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::function::target_type

From cppreference.com
< cpp‎ | utility‎ | functional‎ | function

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

Returns the type of the stored function.

### [edit] Parameters

(none)

### [edit] Return value

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

### [edit] Exceptions

`noexcept` specification:
noexcept

### [edit] Example

Run this code

    #include <functional>
    #include <iostream>

    int f(int a) { return -a; }
    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';
    }

Possible output:

    int (*)(int)
    main::$_0

### [edit] See also

target | obtains a pointer to the stored target (public member function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/functional/function/target_type&oldid=91584"
Category:

- unconditionally noexcept

Hidden categories:

- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template