You don't need the preprocessor to generate a large number of overloads, just adapt your get_internal
approach to work without variadic templates. They need to have a similar amount of parameters like TupleContainer
:
template< class R, class U, class V, class W >
struct getIndex
{
static const int value = getIndex< R, V, W, null_type >::value + 1;
};
template< class R, class V, class W >
struct getIndex< R, R, V, W >
{
static const int value = 0;
};
template< class R >
struct getIndex< R, null_type, null_type, null_type >
{
// let it fail if the type is not found and avoid infinite recursion
};
and now you can use
template< class R >
R& getElementByType() {
return get< getIndex< R, U, V, W >::value >(data_);
}