samedi 30 juin 2018

Loop over template types

I have a function with two template arguments, one for a vector data type (int, float, double, etc.) and one for an integer type (int, int16_t, uint32_t, etc.):

template <typename T, typename I>
void
add(std::vector<T> array, std::vector<I> idx) {
  // ...
}

For tests, I would now like to loop over every possible combination of data/integer types, e.g.,

// pseudo code
for I in [int, int16_t, int32_t, ...] {
    for T in [float, double, int, int16_t, ...] {
        // create arguments a, b
        add<T, I>(a, b);
    }
}

Is it possible to loop over types at all? How?

Aucun commentaire:

Enregistrer un commentaire