I know that is not possible to use template on virtual method, because the compile there is no way to know how to implement all possibilities, but what I need is to use template on a restricted way, like that:
template<typename T, size_t N>
class MatBase {
public:
static constexpr size_t order = N;
using value_type = T;
MatBase() = default;
virtual ~MatBase() = default;
template<class Fn = T(T)>
virtual void Map(Fn&& fn) = 0;
template<class Fn = T(T,T)>
virtual T Reduce(Fn&& fn) = 0;
};
It means, Fn uses the template declared on class, so I think it is possible to compiler infer all possible types. Are there way to do something like that C++?
Aucun commentaire:
Enregistrer un commentaire