Does template specialization work with alias templates? Specifically, the following code throws an unexpected error:
$ cat test01.h
#ifndef TEST01_H
#define TEST01_H
#include <iostream>
#include <typeinfo>
#include <cstdlib>
template <template <typename> class Ops>
double add1(double const & x) {
std::cerr << "Undefined for type: " << typeid(Ops <double>).name() << std::endl;
exit(EXIT_FAILURE);
}
template <typename Real>
struct MyOps {
static Real add(Real const & x,Real const & y) {
return x+y;
}
};
template <typename Real> using MyOpsAlias = MyOps <Real>;
#endif
In addition,
$ cat test01.cpp
#include "test01.h"
template <>
double add1 <MyOps> (double const & x) {
return MyOps <double>::add(x,1.);
}
int main() {
std::cout << add1 <MyOps> (2.) << std::endl;
std::cout << add1 <MyOpsAlias> (2.) << std::endl;
}
After running this code, I receive
$ ./test01
3
Undefined for type: 5MyOpsIdE
I expected that both answers should return 3 since MyOpsAlias should just be an alias template of MyOps. In case it matters, I'm using GCC 4.7.3.