Reputation: 187
I'm reading some source code in stl_construct.h,
In most cases it has sth in the <>
and i see some lines with only "template<> ...
".
what's this?
Upvotes: 5
Views: 204
Reputation: 206518
Guess, I completely misread the Q and answered something that was not being asked.
So here I answer the Q being asked:
It is an Explicit Specialization with an empty template argument list.
When you instantiate a template with a given set of template arguments the compiler generates a new definition based on those template arguments. But there is a facility to override this behavior of definition generation. Instead of compiler generating the definition We can specify the definition the compiler should use for a given set of template arguments. This is called explicit specialization.
The template<>
prefix indicates that the following template declaration takes no template parameters.
Explicit specialization can be applied to:
Upvotes: 2
Reputation: 92241
It's a template specialization where all template parameters are fully specified, and there happens to be no parameters left in the <>
.
For example:
template<class A, class B> // base template
struct Something
{
// do something here
};
template<class A> // specialize for B = int
struct Something<A, int>
{
// do something different here
};
template<> // specialize both parameters
struct Something<double, int>
{
// do something here too
};
Upvotes: 0
Reputation: 111130
This would mean that what follows is a template specialization.
Upvotes: 10