I have write function to deduce how much parameters I forward to function. Something like this:
template<typename Arg>
constexpr size_t get_init_size(Arg arg, size_t i) {
return i + 1;
}
template<typename T, typename ... Args>
constexpr size_t get_init_size(T First_arg, Args ... args, size_t i) {
return get_init_size(args... , i + 1);
}
auto create_ipv4_header() {
size_t x = get_init_size(0b01, 0b10, 0b01, static_cast<size_t>(0));
return x //<= must return 3
}
But compiler write: error: no matching function for call to 'get_init_size(int, int, int, size_t)' So it is problem in variadic template? And one more thing if I change variadic template to something like this:
template<typename T, typename ... Args>
constexpr size_t get_init_size(T First_arg, Args ... args, size_t i = 0)
I can put down last parameter?(I doesn't test it with variadic template) Thanks for help!