I have a code like:
#include <tuple>
#include <utility>
#include <iostream>
template<int ...> struct seq {};
template<int N, int ...S> struct gens : gens<N - 1, N - 1, S...> {};
template<int ...S> struct gens<0, S...> { typedef seq<S...> type; };
template<typename ValueType>
bool get_value(ValueType& value, int index) {
//just for test
value = 100;
return true;
}
template<>
bool get_value(const char*& value, int index) {
//just for test
value = "Hello?";
return true;
}
template<int index, std::size_t remaining, typename... Args>
struct arg_helper {
inline static bool
get_args(std::tuple<Args...>& t) {
if (get_value(std::get<index>(t), index)) {
return arg_helper<index + 1, remaining - 1, Args...>::get_args(t);
}
else {
return false;
}
return true;
}
};
template<std::size_t index, typename... Args>
struct arg_helper<index, 0, Args... > {
inline static bool
get_args(std::tuple<Args...>& t) {
return true;
}
};
template<typename R, typename... Args, int ...S>
void callFunc(R(func)(Args...), seq<S...>, std::tuple<Args...>& tup) {
func(std::get<S>(tup) ...);
}
template<typename R, typename... Args>
void TestFunc(R(func)(Args...)) {
std::tuple<Args...> tup;
arg_helper<0, sizeof ...(Args), Args...>::get_args(tup);
callFunc(func, typename gens<sizeof...(Args)>::type(), tup);
}
static void FuncA(int test, const char* str) {
std::cout << "test func" << test << str << std::endl;
}
int main() {
TestFunc(FuncA);
return 0;
}
It can run on MSVC2013, but compiler error on GCC on the line :
arg_helper<0, sizeof ...(Args), Args...>::get_args(tup);
What am I doing wrong?
BTW: I know iterate over tuple it can run on gcc, but seems not work for MSVC2013