I miss the last part of the answer where I did not manage to arrange correctly 2 parameter pack expansions but I may hope to get it correctly in the future (thus I also did not take into account the efficiency and the potential number of copies performed)
Also I do not know if in your example you wanted
- a tuple of 2 members ( the first one being the array )
- a N+p dimensional tuple ( where N is the dimension of the array and p the dimension of other potential tuple members ).
I choose to try the second one as it is the most difficult answer. Otherwise you can convert your plain old array T arr[N] to std::array<T,N> as it is described in cpp reference std::integer_sequence which was a source of inspiration ( Indices{} )
Another source of inspiration is Bartolomiej Filipek blog article on tuple iteration
#include <iostream>
#include <tuple>
template <typename U, size_t N, size_t... Is, typename Others> auto makeTupleN_impl(const U (&arr)[N], std::index_sequence<Is...>, Others others) {
return std::tuple_cat(std::tie(arr[Is]... ), others);
}
template <typename U, size_t N, typename Indices = std::make_index_sequence<N>, typename... Others> auto makeMyTuple(const U (&arr)[N], Others... others) {
return makeTupleN_impl(arr,Indices{},std::make_tuple(others...));
}
int main()
{
char arr[] = {31, 32, 33, 34, 35, 36, 37, 38};
auto c = makeMyTuple(arr,-11,-222);
std::cout << (int)std::get<7>(c) << " " << (int)std::get<8>(c) << " " << (int)std::get<9>(c) <<"\n";
return 0;
}
Printout is : 38 -11 -222