std::is_same

From Cppreference

Jump to: navigation, search
Defined in header <type_traits>

template< class T, class U >
struct is_same;
(C++11 feature)

If T and U name the same type with the same const-volatile qualifications, provides the member constant value equal to true. Otherwise value is false.

Contents

Inherited from std::integral_constant

Member constants

value true if T and U is the same type , false otherwise
(public static member constant)

Member functions

operator bool converts the object to bool, returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

[edit] Equivalent definition

[edit] Example

#include <iostream>
#include <type_traits>
#include <cstdint>
 
int main()
{
    std::cout << std::boolalpha;
    std::cout << std::is_same<int, int32_t>::value << '\n';
    std::cout << std::is_same<int, int64_t>::value << '\n';
    std::cout << std::is_same<float, int32_t>::value << '\n';
}

Output:

true
false
false

[edit] See also