I am trying to create a template vector of arbitrary number of int parameters and create a function to print those parameters:
namespace ex {
template <int I, class... Ts>
constexpr decltype(auto) get(Ts&& ... ts) {
return std::get<I>(std::forward_as_tuple(ts...));
}
template<int... N>
struct vec
{
static const int size = sizeof...(N);
void print() {
print(size-1);
}
void print(const int n) {
if (n >= 0) {
print(n - 1);
std::cout << ex::get<n>(N...) << std::endl;
}
}
};
}
int main()
{
ex::vec<1, 2, 3> v;
v.print();
}
And I got the following errors:
error C2672: 'ex::get': no matching overloaded function found
error C2975: 'I': invalid template argument for 'ex::get', expected compile-time constant expression
Can anyone please explain that am I missing and how to achieve the behaviour I expect?
Thanks in advance.