How to unpack a variadic template parameter with a numeric sequence? - c++

How to (or is it possible to) unpack a parameter pack with a numeric sequence? For example,
template <typename C, typename... T>
C* init_from_tuple(bp::tuple tpl)
{
return new C{bp::extract<T>("magic"(tpl))...}; // <--
}
which the <-- line should expand to
return new C{bp::extract<T0>(tpl[0]),
bp::extract<T1>(tpl[1]),
.....
bp::extract<Tn>(tpl[n])};
where n == sizeof...(T) - 1.
The purpose is to create a __init__ function for Boost.Python which accepts a tuple with predefined types.

Actually, it is possible for the unpack operations to target two different packs of parameters at once (I think they need be of equal length). Here we would like a pack of types, and a pack of numbers.
Something akin to:
template <typename C, typename... T, size_t... N>
C* init_from_tuple_impl(bp::tuple tpl) {
return new C{ bp::extract<T>(tpl[N])... };
}
We "just" need to generate the pack of indices:
template <size_t... N> struct Collection {};
template <typename C> struct ExtendCollection;
template <size_t... N>
struct ExtendCollection< Collection<N...> > {
typedef Collection<N..., sizeof...(N)> type;
};
template <typename... T>
struct GenerateCollection;
template <>
struct GenerateCollection<> { typedef Collection<> type; };
template <typename T0, typename... T>
struct GenerateCollection<T0, T...> {
typedef typename ExtendCollection<
typename GenerateCollection<T...>::type
>::type type;
};
And then use it:
template <typename C, typename... T, size_t... N>
C* init_from_tuple_impl(bp::tuple tpl, Collection<N...>) {
return new C { bp::extract<T>(tpl[N])... };
}
template <typename C, typename... T>
C* init_from_tuple(bp::tuple tpl) {
typename GenerateCollection<T...>::type collection;
return init_from_tuple_impl<C, T...>(tpl, collection);
}
In action at Ideone.
We can witness the correctness by making a "mistake" in the implementation of init_from_tuple_impl (remove the new for example):
template <typename C, typename... T, size_t... N>
C* init_from_tuple_impl(bp::tuple tpl, Collection<N...>) {
return C { bp::extract<T>(tpl[N])... };
}
In action at Ideone:
prog.cpp: In function 'C* init_from_tuple_impl(bp::tuple, Collection<N ...>)
[with
C = bp::Object,
T = {int, float, char},
unsigned int ...N = {0u, 1u, 2u},
bp::tuple = std::basic_string<char>
]':
Exactly what we wanted :)

Its possible if you first extract the parameters into their own pack and then call the constructor. its far from finished, but you get the general idea:
template <typename C, int N, typename... T>
C* init_from_tuple(bp::tuple tpl, T... args) // enable_if N == sizeof...(T)
{
return new C{args...};
}
template <typename C, int N, typename T0, typename... T>
C* init_from_tuple(bp::tuple tpl, T... args) // enable_if N != sizeof...(T)
{
return init_from_tuple<C, N + 1>(tpl, args, bp::extract<T0>(tpl[N]));
}
template <typename C, typename... T>
C* init_from_tuple(bp::tuple tpl, T... args)
{
return init_from_tuple<C, 0, T...>(tpl, args);
}
Use boost's enable_if to make the places indicated only enabled in some cases, and probably the template arguments need some changes, but this is a start.

Related

Subset a Variadic template given a constexpr boolean selection function

Suppose we have a variadic templated class like
template<class...Ts>
class X{
template<size_t I>
constexpr bool shouldSelect();
std::tuple<TransformedTs...> mResults; // this is want I want eventually
};
where the implementation of shouldSelect is not provided, but what it does is that, given an index i referring to the ith element of the variadic Ts, tells you whether we should select it to the subset.
I want to do a transformation on Ts such that only classes Ts at indexes that results in shouldSelect returning true should be selected. Is there an easy way to do this?
For example, if shouldSelect returns true for I = 1,2,4, and Ts... = short, int, double, T1, T2, then I want to get a TransformedTs... that is made up of int, double, T2. Then I can use this TransformedTs... in the same class.
If you're able to use C++17, this is pretty easy to implement using a combination of if constexpr and expression folding.
Start with some helper types, one with parameters to track the arguments to X::shouldSelect<I>(), and the other with a type to test.
template <typename T, size_t I, typename...Ts>
struct Accumulator {
using Type = std::tuple<Ts...>;
};
template <typename T>
struct Next { };
Then an operator overload either adds the type to the accumulator, or not with if constexpr:
template <typename TAcc, size_t I, typename... Ts, typename TArg>
decltype(auto) operator +(Accumulator<TAcc, I, Ts...>, Next<TArg>) {
if constexpr (TAcc::template shouldSelect<I>()) {
return Accumulator<TAcc, I + 1, Ts..., TArg>{};
} else {
return Accumulator<TAcc, I + 1, Ts...>{};
}
}
Finally, you can put it all together with a fold expression and extract the type with decltype:
template <template <typename... Ts> class T, typename... Ts>
constexpr decltype(auto) FilterImpl(const T<Ts...>&) {
return (Accumulator<T<Ts...>, 0>{} + ... + Next<Ts>{});
}
template<typename T>
using FilterT = typename decltype(FilterImpl(std::declval<T>()))::Type;
Usage:
using Result = FilterT<X<int, double, bool, etc>>;
Demo: https://godbolt.org/z/9h89zG
If you don't have C++17 available to you, it's still possible. You can do the same sort of conditional type transfer using a recursive inheritance chain to iterate though each type in the parameter pack, and std::enable_if to do the conditional copy. Below is the same code, but working in C++11:
// Dummy type for copying parameter packs
template <typename... Ts>
struct Mule {};
/* Filter implementation */
template <typename T, typename Input, typename Output, size_t I, typename = void>
struct FilterImpl;
template <typename T, typename THead, typename... TTail, typename... OutputTs, size_t I>
struct FilterImpl<T, Mule<THead, TTail...>, Mule<OutputTs...>, I, typename std::enable_if<( T::template shouldSelect<I>() )>::type >
: FilterImpl<T, Mule<TTail...>, Mule<OutputTs..., THead>, (I + 1)>
{ };
template <typename T, typename THead, typename... TTail, typename... OutputTs, size_t I>
struct FilterImpl<T, Mule<THead, TTail...>, Mule<OutputTs...>, I, typename std::enable_if<( !T::template shouldSelect<I>() )>::type >
: FilterImpl<T, Mule<TTail...>, Mule<OutputTs...>, (I + 1)>
{ };
template <typename T, typename... OutputTs, size_t I>
struct FilterImpl<T, Mule<>, Mule<OutputTs...>, I>
{
using Type = std::tuple<OutputTs...>;
};
/* Helper types */
template <typename T>
struct Filter;
template <template <typename... Ts> class T, typename... Ts>
struct Filter<T<Ts...>> : FilterImpl<T<Ts...>, Mule<Ts...>, Mule<>, 0>
{ };
template <typename T>
using FilterT = typename Filter<T>::Type;
Demo: https://godbolt.org/z/esso4M

getting a value for any type in a constexpr environment without default constructibility [duplicate]

Is there a utility in the standard library to get the index of a given type in std::variant? Or should I make one for myself? That is, I want to get the index of B in std::variant<A, B, C> and have that return 1.
There is std::variant_alternative for the opposite operation. Of course, there could be many same types on std::variant's list, so this operation is not a bijection, but it isn't a problem for me (I can have first occurrence of type on list, or unique types on std::variant list).
Update a few years later: My answer here may be a cool answer, but this is the correct one. That is how I would solve this problem today.
We could take advantage of the fact that index() almost already does the right thing.
We can't arbitrarily create instances of various types - we wouldn't know how to do it, and arbitrary types might not be literal types. But we can create instances of specific types that we know about:
template <typename> struct tag { }; // <== this one IS literal
template <typename T, typename V>
struct get_index;
template <typename T, typename... Ts>
struct get_index<T, std::variant<Ts...>>
: std::integral_constant<size_t, std::variant<tag<Ts>...>(tag<T>()).index()>
{ };
That is, to find the index of B in variant<A, B, C> we construct a variant<tag<A>, tag<B>, tag<C>> with a tag<B> and find its index.
This only works with distinct types.
I found this answer for tuple and slightly modificated it:
template<typename VariantType, typename T, std::size_t index = 0>
constexpr std::size_t variant_index() {
static_assert(std::variant_size_v<VariantType> > index, "Type not found in variant");
if constexpr (index == std::variant_size_v<VariantType>) {
return index;
} else if constexpr (std::is_same_v<std::variant_alternative_t<index, VariantType>, T>) {
return index;
} else {
return variant_index<VariantType, T, index + 1>();
}
}
It works for me, but now I'm curious how to do it in old way without constexpr if, as a structure.
You can also do this with a fold expression:
template <typename T, typename... Ts>
constexpr size_t get_index(std::variant<Ts...> const&) {
size_t r = 0;
auto test = [&](bool b){
if (!b) ++r;
return b;
};
(test(std::is_same_v<T,Ts>) || ...);
return r;
}
The fold expression stops the first time we match a type, at which point we stop incrementing r. This works even with duplicate types. If a type is not found, the size is returned. This could be easily changed to not return in this case if that's preferable, since missing return in a constexpr function is ill-formed.
If you dont want to take an instance of variant, the argument here could instead be a tag<variant<Ts...>>.
With Boost.Mp11 this is a short, one-liner:
template<typename Variant, typename T>
constexpr size_t IndexInVariant = mp_find<Variant, T>::value;
Full example:
#include <variant>
#include <boost/mp11/algorithm.hpp>
using namespace boost::mp11;
template<typename Variant, typename T>
constexpr size_t IndexInVariant = mp_find<Variant, T>::value;
int main()
{
using V = std::variant<int,double, char, double>;
static_assert(IndexInVariant<V, int> == 0);
// for duplicates first idx is returned
static_assert(IndexInVariant<V, double> == 1);
static_assert(IndexInVariant<V, char> == 2);
// not found returns ".end()"/ or size of variant
static_assert(IndexInVariant<V, float> == 4);
// beware that const and volatile and ref are not stripped
static_assert(IndexInVariant<V, int&> == 4);
static_assert(IndexInVariant<V, const int> == 4);
static_assert(IndexInVariant<V, volatile int> == 4);
}
One fun way to do this is to take your variant<Ts...> and turn it into a custom class hierarchy that all implement a particular static member function with a different result that you can query.
In other words, given variant<A, B, C>, create a hierarchy that looks like:
struct base_A {
static integral_constant<int, 0> get(tag<A>);
};
struct base_B {
static integral_constant<int, 1> get(tag<B>);
};
struct base_C {
static integral_constant<int, 2> get(tag<C>);
};
struct getter : base_A, base_B, base_C {
using base_A::get, base_B::get, base_C::get;
};
And then, decltype(getter::get(tag<T>())) is the index (or doesn't compile). Hopefully that makes sense.
In real code, the above becomes:
template <typename T> struct tag { };
template <std::size_t I, typename T>
struct base {
static std::integral_constant<size_t, I> get(tag<T>);
};
template <typename S, typename... Ts>
struct getter_impl;
template <std::size_t... Is, typename... Ts>
struct getter_impl<std::index_sequence<Is...>, Ts...>
: base<Is, Ts>...
{
using base<Is, Ts>::get...;
};
template <typename... Ts>
struct getter : getter_impl<std::index_sequence_for<Ts...>, Ts...>
{ };
And once you establish a getter, actually using it is much more straightforward:
template <typename T, typename V>
struct get_index;
template <typename T, typename... Ts>
struct get_index<T, std::variant<Ts...>>
: decltype(getter<Ts...>::get(tag<T>()))
{ };
That only works in the case where the types are distinct. If you need it to work with independent types, then the best you can do is probably a linear search?
template <typename T, typename>
struct get_index;
template <size_t I, typename... Ts>
struct get_index_impl
{ };
template <size_t I, typename T, typename... Ts>
struct get_index_impl<I, T, T, Ts...>
: std::integral_constant<size_t, I>
{ };
template <size_t I, typename T, typename U, typename... Ts>
struct get_index_impl<I, T, U, Ts...>
: get_index_impl<I+1, T, Ts...>
{ };
template <typename T, typename... Ts>
struct get_index<T, std::variant<Ts...>>
: get_index_impl<0, T, Ts...>
{ };
My two cents solutions:
template <typename T, typename... Ts>
constexpr std::size_t variant_index_impl(std::variant<Ts...>**)
{
std::size_t i = 0; ((!std::is_same_v<T, Ts> && ++i) && ...); return i;
}
template <typename T, typename V>
constexpr std::size_t variant_index_v = variant_index_impl<T>(static_cast<V**>(nullptr));
template <typename T, typename V, std::size_t... Is>
constexpr std::size_t variant_index_impl(std::index_sequence<Is...>)
{
return ((std::is_same_v<T, std::variant_alternative_t<Is, V>> * Is) + ...);
}
template <typename T, typename V>
constexpr std::size_t variant_index_v = variant_index_impl<T, V>(std::make_index_sequence<std::variant_size_v<V>>{});
If you wish a hard error on lookups of not containing type or duplicate type - here are static asserts:
constexpr auto occurrences = (std::is_same_v<T, Ts> + ...);
static_assert(occurrences != 0, "The variant cannot have the type");
static_assert(occurrences <= 1, "The variant has duplicates of the type");
Another take on it:
#include <type_traits>
namespace detail {
struct count_index {
std::size_t value = 0;
bool found = false;
template <typename T, typename U>
constexpr count_index operator+(const std::is_same<T, U> &rhs)
{
if (found)
return *this;
return { value + !rhs, rhs};
}
};
}
template <typename Seq, typename T>
struct index_of;
template <template <typename...> typename Seq, typename... Ts, typename T>
struct index_of<Seq<Ts...>, T>: std::integral_constant<std::size_t, (detail::count_index{} + ... + std::is_same<T, Ts>{}).value> {
static_assert(index_of::value < sizeof...(Ts), "Sequence doesn't contain the type");
};
And then:
#include <variant>
struct A{};
struct B{};
struct C{};
using V = std::variant<A, B, C>;
static_assert(index_of<V, B>::value == 1);
Or:
static_assert(index_of<std::tuple<int, float, bool>, float>::value == 1);
See on godbolt: https://godbolt.org/z/7ob6veWGr

Get a new tuple containing all but first element of a tuple

Given a std::tuple<A, B, ...> foo is there any generic (templated) function or technique in C++14 to get a new tuple std::tuple<B, ...> bar which contains all but the first element of foo? Or, perhaps something in Boost?
I've written a helper function using parameter packs and some template metaprogramming to do this, but I'd love to throw all of that stuff away!
Here's what I'm currently doing. I define a helper function unshift_tuple() which returns a tuple containing all but the first element of the tuple passed to the function. The implementation of unshift_tuple() uses a helper function unshift_tuple_with_indices() which takes a parameter pack containing the tuple indices to extract; the sequential_integer_list helper type is used to generate the appropriate index list parameter pack using template metaprogramming. Ugly!
#include <tuple>
template <size_t... Integers>
struct integer_list {};
template <size_t N, size_t... Args>
struct sequential_integer_list : sequential_integer_list<N - 1, N - 1, Args...> {};
template <size_t... Args>
struct sequential_integer_list<0, Args...> { typedef integer_list<Args...> type; };
template <typename FirstElement, typename... Elements, size_t... Indices>
static std::tuple<Elements...> unshift_tuple_with_indices(
const std::tuple<FirstElement, Elements...>& tuple,
integer_list<Indices...> index_type)
{
return std::make_tuple(std::get<Indices + 1>(tuple)...);
}
template <typename FirstElement, typename... Elements>
std::tuple<Elements...>
unshift_tuple(const std::tuple<FirstElement, Elements...>& tuple)
{
return unshift_tuple_with_indices(tuple,
typename sequential_integer_list<sizeof...(Elements)>::type());
}
int main(int, char *[])
{
std::tuple<int, std::string, double> foo(42, "hello", 3.14);
std::tuple<std::string, double> bar = unshift_tuple(foo);
}
To be clear, this code works just fine. I just wish very much to delete it (or any portion of it) and use something built-in instead, if possible!
Edit
Jarod42 pointed out the existence of std::integer_list in C++14 which simplifies the implementation to something like:
#include <cstddef>
#include <tuple>
#include <utility>
template <typename T1, typename... T, size_t... Indices>
std::tuple<T...> unshift_tuple_with_indices(
const std::tuple<T1, T...>& tuple, std::index_sequence<Indices...>)
{
return std::make_tuple(std::get<Indices + 1>(tuple)...);
}
template <typename T1, typename... T> std::tuple<T...>
unshift_tuple(const std::tuple<T1, T...>& tuple)
{
return unshift_tuple_with_indices(tuple,
std::make_index_sequence<sizeof...(T)>());
}
In C++17, you might do
template <typename T1, typename... Ts>
std::tuple<Ts...> unshift_tuple(const std::tuple<T1, Ts...>& tuple)
{
return std::apply([](auto&&, const auto&... args) {return std::tie(args...);}, tuple);
}
std::apply might be implemented in C++14.
Else, in C++14, there is std::index_sequence which avoids to write your own version, which simplifies your code to something like:
namespace details
{
template <typename Tuple, size_t... Indices>
auto unshift_tuple_with_indices(
const Tuple& tuple,
std::index_sequence<Indices...> index_type)
{
return std::make_tuple(std::get<Indices + 1>(tuple)...);
}
}
template <typename T, typename... Ts>
std::tuple<Ts...> unshift_tuple(const std::tuple<T, Ts...>& tuple)
{
return details::unshift_tuple_with_indices(tuple, std::index_sequence_for<Ts...>());
}
In C++14, there is a class template called std::integer_sequence that does similar to what you are doing with sequential_integer_list. You can find the reference in here.
In light of your code, it is possible to reduce and rely on pure meta-programming.
template <typename First, typename ... Elements>
struct unshift_tuple_impl
{
using type = std::tuple<Elements...>;
};
template <typename First, typename ... Elements>
std::tuple<Elements...>
unshift_tuple(const std::tuple<First, Elements...>& tuple)
{
return typename unshift_tuple_impl<First, Elements...>::type{};
}

Transform typelist with function at runtime

I have a typelist. I would like to create a tuple with the results of calling a function on each type in that list and then use that as arguments to another functor. So something like this:
template<typename F>
struct function_traits;
template<typename T, typename R, typename... Args>
struct function_traits<R(T::*)(Args...) const> {
using return_type = R;
using param_types = std::tuple<Args...>;
};
template<typename T> struct function_traits : public
function_traits<decltype(&T::operator())> {};
template <typename T>
T* get_arg(int id)
{
// Actual implementation omitted. Uses the id parameter to
// do a lookup into a table and return an existing instance
// of type T.
return new T();
}
template <typename Func>
void call_func(Func&& func, int id)
{
using param_types = function_traits<Func>::param_types>;
func(*get_arg<param_types>(id)...); // <--- Problem is this line
}
call_func([](int& a, char& b) { }, 3);
The problem is that func(*get_arg<param_types>(id)...); doesn't actually compile since param_types is a tuple and not a parameter pack. The compiler generates this error: "there are no parameter packs available to expand". What I would liked to have happened is for that line to expand to:
func(*get_arg<int>(id), *get_arg<char>(id));
And to have that work for any number of arguments. Is there any way to get that result?
This question seems similar but does not solve my problem by itself: "unpacking" a tuple to call a matching function pointer. I have a type list and from that I want to generate a list of values to use as function arguments. If I had the list of values I could expand them and call the function as outlined in that question, but I do not.
Not sure that is what do you want.
I don't know how to expand, inside call_func(), the parameters pack of params_type but, if you afford the use of a helper struct and a compiler with C++14...
I've prepared the following example with support for return type.
#include <tuple>
template<typename F>
struct function_traits;
template<typename T, typename R, typename... Args>
struct function_traits<R(T::*)(Args...) const> {
using return_type = R;
using param_types = std::tuple<Args...>;
};
template<typename T> struct function_traits : public
function_traits<decltype(&T::operator())> {};
template <typename T, typename ... Args>
T get_arg (std::tuple<Args...> const & tpl)
{ return std::get<typename std::decay<T>::type>(tpl); }
template <typename ...>
struct call_func_helper;
template <typename Func, typename Ret, typename ... Args>
struct call_func_helper<Func, Ret, std::tuple<Args...>>
{
template <typename T, typename R = Ret>
static typename std::enable_if<false == std::is_same<void, R>::value, R>::type
fn (Func const & func, T const & t)
{ return func(get_arg<Args>(t)...); }
template <typename T, typename R = Ret>
static typename std::enable_if<true == std::is_same<void, R>::value, R>::type
fn (Func const & func, T const & t)
{ func(get_arg<Args>(t)...); }
};
template <typename Func,
typename T,
typename R = typename function_traits<Func>::return_type>
R call_func (Func const & func, T const & id)
{
using param_types = typename function_traits<Func>::param_types;
return call_func_helper<Func, R, param_types>::fn(func, id);
}
int main()
{
call_func([](int const & a, char const & b) { }, std::make_tuple(3, '6'));
return 0;
}
Hope this helps.

Interweave a VT unpack with a meta-sequence

template <int I> struct int_ {};
template < typename ... Pack >
struct thingy
{
void call()
{
f(???);
}
};
When instantiated it should end up being:
struct thingy<int,char,double>
{
void call()
{
f(int, int_<1>(), char, int_<2>(), double, int_<3>());
}
}
What you think, can it be done? How?
The only thing I can think of is to have overloads for thingy with N different parameters like so:
template < typename T0 > struct thingy<T0> { ... };
template < typename T0, typename T1 > struct thingy<T0,T1> { ... };
etc...
With a call implementation in each.
Can it be done
Yes, of course.
How ?
In several steps.
You need to be able to create a range of integers
You need to be able to interleave two sequences
Let us start with the range of integers.
template <size_t...>
struct IntegralPack {};
template <size_t A, size_t... N>
IntegralPack<N..., A> push_back(IntegralPack<N...>);
template <size_t A, size_t... N>
IntegralPack<A, N...> push_front(IntegralPack<N...>);
template <size_t L, size_t H>
struct IntegralRangeImpl {
typedef typename IntegralRangeImpl<L+1, H>::type Base;
typedef decltype(push_front<L>((Base()))) type;
};
template <size_t X>
struct IntegralRangeImpl<X, X> {
typedef IntegralPack<> type;
};
template <size_t L, size_t H>
struct IntegralRange {
static_assert(L <= H, "Incorrect range");
typedef typename IntegralRangeImpl<L, H>::type type;
};
The conversion step is easy enough (thankfully):
template <typename...>
struct TypePack {};
template <size_t... N>
TypePack<int_<N>...> to_int(IntegralPack<N...>);
So the next difficulty is the merge.
template <typename... As, typename... Bs>
TypePack<As..., Bs...> cat(TypePack<As...>, TypePack<Bs...>);
template <typename, typename> struct Interleaver;
template <>
struct Interleaver<TypePack<>, TypePack<>> {
typedef TypePack<> type;
};
template <typename A0, typename B0, typename... As, typename... Bs>
struct Interleaver<TypePack<A0, As...>, TypePack<B0, Bs...>> {
typedef typename Interleaver<TypePack<As...>, TypePack<Bs...>>::type Base;
typedef decltype(cat(TypePack<A0, B0>{}, Base{})) type;
};
Putting it altogether:
template <typename... Pack>
struct thingy {
typedef typename IntegralRange<1, sizeof...(Pack) + 1>::type Indexes;
typedef decltype(to_int(Indexes{})) Ints;
typedef typename Interleaver<TypePack<Pack...>, Ints>::type Types;
void call() { this->callImpl(Types{}); }
template <typename... Ts>
void callImpl(TypePack<Ts...>) {
f(Ts{}...);
}
};
Tadaam!
So the way I went about it is a little more specific to what I was actually doing. Turns out some information I thought was beside the point helped me out. I think though that a similar technique could be used for any case.
For one thing...in my case "thingy<>" actually has values in it and is passed to the invoker function. This actually helps a lot.
Also, since the object was to convert the stuff in thingy to serve as induces for another weird thingy, and the ints being passed in were to index the first thingy...the ints end up all being 1 when I do my recursion. So while what I was after was something like (simplified to remove the second tuple):
f(get(my_thingy, idx<1>), get(my_thingy, idx<2>), ...)
It turns out the recursion gets rid of idx<2>...idx:
template < typename Fun, typename H, typename ... T, typename ... Args >
auto call(Fun f, thingy<H,T...> const& t, Args&& ... args)
-> decltype(call(f,static_cast<thingy<T...>const&>(t), get(t,idx<1>), std::forward<Args>(args)...)
{
return call(f, static_cast<thingy<T...>const&>(t), get(t, idx<1>), args...);
}
template < typename Fun, typename ... Args >
auto call(Fun f, thingy<> const&, Args&& ... args)
-> decltype(f(std::forward<Args>(args)...))
{
return f(std::forward<Args>(args)...);
}
I have not been able to fully test thing because the get function fails on me for some reason when using const&...kinda pissing me off. I'm fairly confident that this does the trick though.
If the parameter to idx wasn't always 1 I think that could be forwarded along in a similar fashion.