Can I do such parameter unpacking in C++? This code doesn't compile, but I think it is possible.
template <typename Container, typename... Args>
void foo(Container& container, Args&&... args){
tuple<typename Container::value_type, typename Args::value_type...> values;
...
}
Args&&... args
is a forwarding reference. If you pass an lvalue to it, the corresponding type in Args
will be deduced as an lvalue reference.
typename Args::value_type
is only valid if Args
is a class type, not a reference-to-class. Thus you need to strip the reference-ness from the types:
typename std::remove_reference_t<Args>::value_type...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With