Structure template c++

What is the difference between

template<typename T>
struct arg_type {
typedef T* ptr;
typedef T& ref;

static T& myFun(T& a) {return a;}
}

template<typename T>
struct arg_type<T*> {
typedef T* ptr;
typedef T& ref;

static T& myFun(T* a) {return *a;}
}

template<typename T>
struct arg_type<T&> {
typedef T* ptr;
typedef T& ref;

static T& myFun(T& a) {return &a;}


The thing which confuses me the most is template part following the struct keyword
}
Last edited on
From the C++ Standard

1 A primary class template declaration is one in which the class template name is an identifier. A template declaration in which the class template name is a simple-template-id is a partial specialization of the class template named in the simple-template-id. A partial specialization of a class template provides an alternative definition of the template that is used instead of the primary definition when the arguments in a specialization match those given in the partial specialization
@Vlad

Thank you very much for the reply.

Could you please give a pointer to some website or article explaining this..... with examples if possible
I even do not know such references. Try to find them yourself by using keyword "Class template partial specializations"
@Vlad Rhank you for the keyword

@JLBorges Thank you very much for providing the reference
Topic archived. No new replies allowed.