A RetroSearch Logo

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

Search Query:

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

class template

<type_traits>

std::make_unsigned
template <class T> struct make_unsigned;

Make unsigned

Obtains the unsigned type corresponding to T, keeping any cv-qualifiers.

The transformed type is aliased as member type make_unsigned::type as follows:



Notice that this class merely obtains a type using another type as model, but it does not transform values or objects between those types. To explicitly cast an integral type to its unsigned equivalent, you can use static_cast.

Template parameters
T
An integer type (except bool), or an enumeration type.

Member types member type definition type Unsigned type corresponding to T.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// make_unsigned
#include <iostream>
#include <type_traits>

enum ENUM1 {a,b,c};
enum class ENUM2 : char {a,b,c};

int main() {
  typedef std::make_unsigned<int>::type A;                // unsigned int
  typedef std::make_unsigned<unsigned>::type B;           // unsigned int
  typedef std::make_unsigned<const unsigned>::type C;     // const unsigned int
  typedef std::make_unsigned<ENUM1>::type D;              // unsigned int
  typedef std::make_unsigned<ENUM2>::type E;              // unsigned char

  std::cout << std::boolalpha;
  std::cout << "typedefs of unsigned int:" << std::endl;
  std::cout << "A: " << std::is_same<unsigned,A>::value << std::endl;
  std::cout << "B: " << std::is_same<unsigned,B>::value << std::endl;
  std::cout << "C: " << std::is_same<unsigned,C>::value << std::endl;
  std::cout << "D: " << std::is_same<unsigned,D>::value << std::endl;
  std::cout << "E: " << std::is_same<unsigned,E>::value << std::endl;

  return 0;
}

Output:
typedefs of unsigned int:
A: true
B: true
C: false
D: true
E: false


See also
make_signed
Make signed (class template)
is_unsigned
Is unsigned type (class template)
add_const
Add const qualification (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