You can use std::integer_sequence
for that purpose:
namespace Detail
{
template <typename Reader, typename T, std::size_t... I>
void read_row(Reader& in, T* data, std::index_sequence<I...>)
{
in.read_row(data[I]...); // A trick here
}
}
template <std::size_t N, typename T>
void read_row(io::CSVReader<N>& in, T* data)
{
Detail::read_row(in, data, std::make_index_sequence<N>{});
}
And of course, use like this:
int a[7];
io::CSVReader<7> r;
read_row(r, a);
"Working" example: link
For compiler "below" C++14 - integer_sequence
(actually just index_sequence
needed) is pretty easy to implement:
template <std::size_t... I>
class index_sequence {};
And make_index_sequence
not so easy - but also doable:
template <std::size_t N, std::size_t ...I>
struct make_index_sequence : make_index_sequence<N-1, N-1,I...> {};
template <std::size_t ...I>
struct make_index_sequence<0,I...> : index_sequence<I...> {};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…