Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can std::remove_pointer be used to remove all indirection from pointer type?

Tags:

c++

Say that I have.. int, int*, int**, etc. Can I use std::remove_pointer or similar to get straight to type int? Thanks

like image 427
Neil Kirk Avatar asked Jul 02 '13 01:07

Neil Kirk


People also ask

How to get the value out of a pointer c++?

To get the value pointed to by a pointer, you need to use the dereferencing operator * (e.g., if pNumber is a int pointer, *pNumber returns the value pointed to by pNumber . It is called dereferencing or indirection).

How do you define a pointer in C++?

Pointers (C++) A pointer is a variable that stores the memory address of an object. Pointers are used extensively in both C and C++ for three main purposes: to allocate new objects on the heap, to pass functions to other functions.


1 Answers

Yuppers.

template<typename T> struct remove_all {
    typedef T type;
};
template<typename T> struct remove_all<T*> {
    typedef typename remove_all<T>::type type;
};

std::remove_pointer itself isn't of that much use here.

like image 192
Puppy Avatar answered Oct 16 '22 21:10

Puppy