我有一个模板类,它可以采用标量或索引类型,我想根据函数的类型调用不同版本的函数:
template <typename Ta, typename ... T>
struct MyClass {
Ta tt; //can be either a scalar (double, complex<double>, int, etc),
//or an indexed type (MyClass, std::vector<double>, double[], etc)
//....
//I would like the following to be called when tt is a scalar type:
auto operator[]( size_t i ) { return tt; };
//I would like the following to be called when tt has [] overloaded:
auto operator[]( size_t i ) { return tt[i]; };
};
有没有办法做到这一点?返回值 SFINAE 不起作用(因为此函数上没有模板参数),基于类的 SFINAE 似乎不起作用(因为可变参数模板使得最后有一个虚拟模板参数不起作用)。还有其他想法吗?