I'm trying to call a function for each value in a std::tuple
, of course there is no way to iterate a tuple and so I've resorted to using the template techniques discussed in iterate over tuple
However, I'm using Visual Studio 2013 and it does not support expression SFINAE, so that code won't work. I've tried to partially specialize the templates based on a constant numbers (e.g 5, 4, 3, 2, 1, 0), but haven't had any success. I'm certainly no template expert, and so I was hoping somebody could help me out. My expression SFINAE code is below.
#include <iostream>
#include <tuple>
using namespace std;
struct ArgPush {
void push(bool x) {}
void push(int x) {}
void push(double x) {}
void push(const char* x) {}
void push(const std::string& x) {}
template<std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I == sizeof...(Tp), void>::type
push_tuple(const std::tuple<Tp...>& t)
{ }
template<std::size_t I = 0, typename... Tp>
inline typename std::enable_if<I < sizeof...(Tp), void>::type
push_tuple(const std::tuple<Tp...>& t)
{
push(std::get<I>(t));
push_tuple<I + 1, Tp...>(t);
}
};
int main() {
ArgPush().push_tuple(std::make_tuple(1,2,3,4));
ArgPush().push_tuple(std::make_tuple("hello", "msvc makes me sad", 4, true));
return 0;
}