It is part of how one defines nested template classes and functions, and their specializations outside of their containing classes:
#include <exception>
template<class yams_t>
class outer
{
public:
template<class potatoes_t>
class inner;
};
template<class yams_t>
template<class potatoes_t>
class outer<yams_t>::inner
{
public:
template<typename result_t>
result_t verb_my_noun();
};
template<class yams_t> // yams_t is resolved first
template<class potatoes_t> // potatoes_t is resolved next
template<typename result_t> // result_t is resolved last
result_t outer<
yams_t // we want to parameterize outer<> first
>::inner<
potatoes_t // then inner<>
>::verb_my_noun() // then verb_my_noun()
{
return result_t(47);
}
template<>
class outer<float>
{
public:
template<class potatoes_t>
class inner;
};
template<>
class outer<float>::inner<float>
{
public:
template<typename result_t>
result_t verb_my_noun()
{
throw std::exception("You've been verbed!");
}
};
template<>
class outer<float>::inner<double>
{
public:
template<typename result_t>
result_t verb_my_noun();
};
// As this is a full specialization of both
// outer<> and its inner class inner<>,
// we don't need two 'template<>'s above this.
//
// However, we still need a template<> for verb_my_noun()
template<typename result_t>
result_t outer<float>::inner<double>::verb_my_noun()
{
return result_t();
}
Example:
int main(int argc, char **argv)
{
outer<int>::inner<unsigned> good_thing;
float x = good_thing.verb_my_noun<float>();
// x is 47.0
outer<float>::inner<float> bad_thing;
// throws exception("You've been verbed!");
float cant_see_me = bad_thing.verb_my_noun<float>();
return 0;
}
Also note that you can do silly things like the following:
template<
class alpha_t, // #1
class beta_t, // #2
class gamma_t // #3
>
class thing
{
void frob();
};
template<
class herp_t, // #1
class derp_t, // #2
class dorp_t // #3
>
void thing<herp_t,derp_t,dorp_t>::frob()
{
}
Please do not actually do anything like the above. It is there for the sake of exposition, and in practice, it makes template code incredibly difficult to read.