Namespaces
Variants
Views
Actions

std::is_same

From cppreference.com
< cpp‎ | types
Revision as of 16:01, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Primary type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
Supported operations
Relationships and property queries
is_same
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++11)
Type trait constants
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template< class T, class U >
struct is_same;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

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
[static]
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)
operator()
(C++14)
returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>
[edit template]

Possible implementation

template<class T, class U>
struct is_same : std::false_type {};
 
template<class T>
struct is_same<T, T> : std::true_type {};

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

See also