A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/type_traits/is_same/ below:

class template

<type_traits>

std::is_same
template <class T, class U> struct is_same;

Is same type


Trait class that identifies whether T is the same type as U, including having the same const and/or volatile qualification, if any.

Two different type names are considered to represent the same type if -and only if- one is a typedef of the other: Two names representing types with the exact same characteristics but which none is a typedef of the other are not considered the same type.

is_same inherits from integral_constant as being either true_type or false_type, depending on whether T and U are the same type.



Template parameters
T, U
Types.

Member types Inherited from integral_constant:

Member constants Inherited from integral_constant:
member constant definition value either true or false
Member functions Inherited from integral_constant:
operator bool
Returns value (public member function)

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// is_same example
#include <iostream>
#include <type_traits>
#include <cstdint>

typedef int integer_type;
struct A { int x,y; };
struct B { int x,y; };
typedef A C;

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_same:" << std::endl;
  std::cout << "int, const int: " << std::is_same<int, const int>::value << std::endl;
  std::cout << "int, integer_type: " << std::is_same<int, integer_type>::value << std::endl;
  std::cout << "A, B: " << std::is_same<A,B>::value << std::endl;
  std::cout << "A, C: " << std::is_same<A,C>::value << std::endl;
  std::cout << "signed char, std::int8_t: " << std::is_same<signed char,std::int8_t>::value << std::endl;
  return 0;
}

Output:
is_same:
int, const int: false
int, integer_type: true
A, B: false
A, C: true
signed char, std::int8_t: true


See also
is_assignable
Is assignable (class template)
is_constructible
Is constructible (class template)
is_base_of
Is base class of (class template)
is_convertible
Is convertible (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4