I am an beginner in template metaprogramming trying to implement generation of multiple versions of similar but slightly different code:
#include <iostream>
enum Type
{
a1,
a2
};
enum Style
{
b1,
b2
};
template<Type,Style>
void doSomething();
{
std::cout<<" some rubbish\n";
};
Full specialization works well:
template<>
void doSomething<a1,b2>()
{
std::cout<<" this is my template parameters one :" <<a1<< " and two:"<<b2<<std::endl;
}
int main(int argc, char* argv[])
{
doSomething<a1,b1>();
doSomething<a1,b2>();
return 0;
}
:some rubbish
:this is my template parameters one :0 and two:1
But partial specialization like below fails:
template<Style Some>
void doSomething<a1,Some>()
{
// here I want to use sub-template on some: e.g do_other<Some>
}
with error: error C2768: 'DoSomething' : illegal use of explicit template arguments
(Body of generic template is commented in this case, though it does not make any difference)
Such specialization is in all samples for partial specialization, but does not work for me. This confuses me a lot.
Very appreciative for any suggestions