Do I always have to place variadic template parameters at the end of my template parameters?
template <size_t begin = 0U, typename... Tp>
void foo(tuple<Tp...> t);
For example I get all kinds of errors with this:
#include <functional>
#include <iostream>
#include <string>
#include <tuple>
using namespace std;
template <typename... Tp, size_t begin = 0U>
enable_if_t<begin == sizeof...(Tp), void> foo(tuple<Tp...>& t){
cout << endl;
}
template <typename... Tp, size_t begin = 0U>
enable_if_t<begin < sizeof...(Tp), void> foo(tuple<Tp...>& t) {
cout << get<begin>(t) << ' ';
foo<Tp..., begin + 1>(t);
}
int main() {
tuple<int, string, float> t = make_tuple(42, "Jonathan Mee", 13.13);
foo(t);
}
When run on gcc 5.1 gives me:
prog.cpp: In instantiation of
std::enable_if_t<(begin < sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&) [with Tp = {int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float}; unsigned int begin = 0u; std::enable_if_t<(begin < sizeof... (Tp)), void> = void]
:
prog.cpp:21:7: required from here
prog.cpp:15:23: error: no matching function for call tofoo(std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, float>&)
foo<Tp..., begin + 1>(t);
prog.cpp:8:43: note: candidate:template<class ... Tp, unsigned int begin> std::enable_if_t<(begin == sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&)
enable_if_t<begin == sizeof...(Tp), void> foo(tuple<Tp...>& t){
prog.cpp:8:43: note: template argument deduction/substitution failed:
prog.cpp:13:42: note: candidate:template<class ... Tp, unsigned int begin> std::enable_if_t<(begin < sizeof... (Tp)), void> foo(std::tuple<_Elements ...>&)
enable_if_t<begin < sizeof...(Tp), void> foo(tuple<Tp...>& t) {
prog.cpp:13:42: note: template argument deduction/substitution failed:
When the arguments are swapped to:
template <size_t begin = 0U, typename... Tp>
void foo(tuple<Tp...> t);
The program runs correctly: http://ideone.com/SozUbb
If this is really a requirement that variadic template parameters be last can someone give me a source on this information?