How to check template template type in template argument?
Example
B<T>and C<T>is a template class.
I want to create a class D<class BC>that can be D<B>or D<C>.
Only D<B>has D::f().
Here is my way ( demo ). He works.
#include <iostream>
using namespace std;
class Dummy{};
template<class T>class B{};
template<class T>class C{};
template<template<class T> class BC>class D{
public: template<class BCLocal=BC<Dummy>> static
typename std::enable_if<std::is_same<BCLocal,B<Dummy>>::value,void>::type f(){
}
};
int main() {
D<B>::f();
return 0;
}
The line is #1very long and ugly (use Dummyfor hacking).
In a real program, it is also error prone, especially when B<...>it C<...>can have 5-7 template arguments.
Are there any ways to improve it?
I dream of something like: -
template<class BCLocal=BC> static
typename std::enable_if<std::is_same<BCLocal,B>::value,void>::type f(){
}