What does <> do for the structure?

Ok, the following code is copied from another stack question here

template<typename T>
struct remove_pointer
{
    typedef T type;
};

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

Although I understand this is a recursive definition in a template, I was puzzled by the lines

template<typename T>
struct remove_pointer<T*>

Does this mean that remove_pointer will result in T = int * ? Why is T = int **? explained.

+4
source share
1 answer

. . , type T , T , type T . , , :

template<typename T>
struct remove_pointer
{
    typedef T type;
};

template<typename S>
struct remove_pointer<S*>       // specialization for T = S*
{
    typedef typename remove_pointer<S>::type type;
};

. type T, T , S, T == S*.

PS: , , . "" :

template<>
struct remove_pointer<int*>   // specialization for T = int*
{
    typedef typename remove_pointer<int>::type type;
};

, , . , (S). Afaik , S , S T .

+8

Source: https://habr.com/ru/post/1661040/


All Articles