我本质上有一个std::integral_constant包含变量的模拟版本,我想专门为这些类派生一个函数模板Base<T>,如下所示:
template<class T> struct Base{
typedef T type;
T t;
};
template<class T> struct A : Base<T>{
static constexpr T value = 1;
};
template<class T> struct B : Base<T>{
static constexpr T value = 2;
};
struct Unrelated{};
// etc.
template<class T> void foo(T t){
//I would like to specialize foo for A and B and have a version for other types
}
int main(){
foo(A<float>());//do something special based on value fields of A and …Run Code Online (Sandbox Code Playgroud)