Unable to use make_index_sequence as a default argument to a function (instantiation of undefined template)

  c++, tuples

I have the following C++ code, which correctly prints out the 3 values of the tuple, comma-separated.

#include <iostream>
#include <utility>
#include <tuple>

std::tuple<int, const char*, float> t(10, "ten", -0.0);

#define SEQ std::make_index_sequence<std::tuple_size_v<decltype(t)> >{}

template <typename... Ts, size_t... Is>
void print_tuple(const std::tuple<Ts...>& t, std::index_sequence<Is...>) {
    ((
        std::cout << (Is == 0 ? "" : ", ") << std::get<Is>(t)
    ), ...);
}

int main() {
    print_tuple(t, SEQ);
}

However, if I want to just call print_tuple(t), I would want to make a default argument.

#include <iostream>
#include <utility>
#include <tuple>

std::tuple<int, const char*, float> t(10, "ten", -0.0);

#define SEQ std::make_index_sequence<std::tuple_size_v<decltype(t)> >{}

template <typename... Ts, size_t... Is>
void print_tuple(const std::tuple<Ts...>& t, std::index_sequence<Is...> = SEQ) {
    ((
        std::cout << (Is == 0 ? "" : ", ") << std::get<Is>(t)
    ), ...);
}

int main() {
    print_tuple(t);
}

The problem is that this code produces an error –

implicit instantiation of undefined template 'std::tuple_size<const
      std::tuple<int, const char *, float> &>'
    inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
                                           ^
main.cpp:10:75: note: in instantiation of variable template specialization
      'std::tuple_size_v<const std::tuple<int, const char *, float> &>'
      requested here

I tried using std::remove_cv & std::remove_reference to remove const &, but I got the same error.

Source: Windows Questions C++

LEAVE A COMMENT