Home > database >  How to convert tuple into initializer list
How to convert tuple into initializer list

Time:09-24

I make large tuple with std::make_tuple function.

something like this

template <class ...T>
QCborArray array(const T&... args) {
    return {args...};
}

but with tuple instead of parameter pack

CodePudding user response:

You can use std::apply and a variadic lambda to do this. That would look like

template <class Tuple>
QCborArray array(Tuple&& tuple) {
    return std::apply([](auto&&... args) { return QCborArray{args...}; },
                      std::forward<Tuple>(tuple));
}
  • Related