mardi 27 novembre 2018

Using tuple as a parameter of a function

Hi I'm trying to pass a tuple as a parameter to a function. I would like to not to specify the amount of elements in the tuple (I followed this example: tuple as function argument)

What is missing now is how I can count the number of element into the tuple in order to access it with std::get

#include<tuple>
#include<iostream>

template <typename... T> void fill(std::tuple<T...> values) {
    std::cout << std::tuple_size<T...>::value << '\n';
    //std::cout << std::get<0>(values) << '\n';
    //std::cout << std::get<1>(values) << '\n';
}
int main() {
    fill(std::make_tuple(2.));
    fill(std::make_tuple(2., 5));
}

tuple_size seems not suitable to be used (https://en.cppreference.com/w/cpp/utility/tuple/tuple_size)

Aucun commentaire:

Enregistrer un commentaire