Dean Seo
Dean Seo

Reputation: 5683

How does boost::remove_pointer work?

So remove_reference or remove_pointer always return the primitive type.

I know that they use so called template specialization to do that in the template meta-programming, but I don't quite understand how.

For example below.

template<class T>
struct AAA
{
    typedef T Type;
};

template<class T>
struct AAA<T*>
{
    // Why does T become int, not int * all of sudden?
    // How come does this get rid of '*' in a specific way?
    typedef T Type;
};

int main()
{
    AAA<int *>::Type MyVar = 3; // MyVar is not a pointer!
    return 0;
}

Obviously I'm missing something, or some designated rules in using template, and I can't find any good articles that explain this well.

Any help would be appreciated.

Thanks in adavance.

Upvotes: 0

Views: 299

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119877

// Why does T become int, not int * all of sudden?

T* is int*, so T must be int.

Upvotes: 2

Related Questions