jeudi 4 février 2021

c++ pass multiple data types (including arrays of different dimensions) to function

i am trying to create a class that can handle tensors. In the constructor of the function i want to pass inputs of different data types (int, vectors...). I also want to pass arrays that always have different dimensions (1D, 3D...). For the constructor i figured out something like this:

template <class T>
Tensor(T input) {
  // ...      
}

However, how should i do to get what dtype has been passed in order to do things with the input? I'd hope in something like this:

if (isInt(input)) {

} else if (isFloat(input)) {

} /* and so on for vectors, strings etc... */ {

} else if (isArray(input)) {
   int dim = getDimension(input);
}

Aucun commentaire:

Enregistrer un commentaire