Home > Back-end >  Class template specialization and the specialized problems
Class template specialization and the specialized problems

Time:10-07

Specialized or all specialized in Angle brackets behind the template without any content, why does it feel iterator_traits didn't follow?
 template & lt; The class _Iterator & gt; 
Struct iterator_traits {
Typedef typename _Iterator: : iterator_category iterator_category;
Typedef typename _Iterator: : value_type value_type.
Typedef typename _Iterator: : difference_type difference_type;
Typedef typename _Iterator: : pointer pointer;
Typedef typename _Iterator: : reference reference;
};

The template & lt; The class _Tp & gt;
Struct iterator_traits & lt; The _Tp * & gt; {
Typedef random_access_iterator_tag iterator_category;
Typedef _Tp value_type.
Typedef ptrdiff_t difference_type;
Typedef _Tp * pointer;
Typedef _Tp & amp; The reference;
};

The template & lt; The class _Tp & gt;
Struct iterator_traits & lt; Const _Tp * & gt; {
Typedef random_access_iterator_tag iterator_category;
Typedef _Tp value_type.
Typedef ptrdiff_t difference_type;
Typedef const _Tp * pointer;
Typedef const _Tp & amp; The reference;
};



According to "c + + primer", class template in specialized template<> After empty parameters, why didn't the standard library so write? Still added parameters not empty

CodePudding user response:

The template & lt; The class _Tp & gt; Struct iterator_traits & lt; The _Tp * & gt;
Specialized for a generic type, is to add a class _Tp

The template & lt;> Struct iterator_traits & lt; Int * & gt;
This template<> Is a specific type, specialized
And specialized series of type, will write template
  • Related