<type_traits>

class template
<type_traits>

std::add_pointer

template <class T> struct add_pointer;
Add pointer
Obtains the pointer type that points to T.

The transformed type is aliased as member type add_pointer::type.

If T is a reference type, this is remove_reference<T>::type*, otherwise it is T*.

Template parameters

T
A type.

Member types

member typedefinition
typeIf T is a reference type: remove_reference<T>::type*
Otherwise: 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
// add_pointer
#include <iostream>
#include <type_traits>

typedef std::add_pointer<int>::type A;        // int*
typedef std::add_pointer<const int>::type B;  // const int*
typedef std::add_pointer<int&>::type C;       // int*
typedef std::add_pointer<int*>::type D;       // int**
typedef std::add_pointer<int(int)>::type E;   // int(*)(int)


typedef int X[3];

int main() {
  std::cout << std::boolalpha;
  std::cout << "typedefs of int*:" << std::endl;
  std::cout << "A: " << std::is_same<int*,A>::value << std::endl;
  std::cout << "B: " << std::is_same<int*,B>::value << std::endl;
  std::cout << "C: " << std::is_same<int*,C>::value << std::endl;
  std::cout << "D: " << std::is_same<int*,D>::value << std::endl;
  std::cout << "E: " << std::is_same<int*,E>::value << std::endl;

  return 0;
}

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


See also