I'm trying to implement something like std::bind()
from scratch. Over in How does std::bind take variadic arguments by value, even with its universal reference? I asked how it would be possible to store variadic arguments in a tuple by value, while using perfect forwarding. I learned about std::decay_t<T>
which lets me do just this. I have a partial implementation of my Bind()
function in http://coliru.stacked-crooked.com/a/2655a48fe82f0d4c which you can see.
I can't seem to apply a function on the unpacked arguments however, if any of the arguments are move-only. I think this is really useful behavior but I can't quite figure out how to achieve it. The easiest way to apply a function to a tuple of variadic arguments would be to simply call std::apply(f_, args_);
, as my example does, however this of course breaks with move-only args.
So I attempted to use an std::index_sequence
and another method InvokeImpl
to accept the moved tuple and the variadic index sequence -- it ony-by-one unpacks the arguments and forwards them to be invoked by the functor. This actually works for move-only types, but fails for types passed by value or std::ref()
, which is of course now what I'm looking for. Is there a way to get this to work for all kinds of types?