#include #include #include #include using namespace std ; // 1. Base Case: Called when only one argument is left template T print_all(T last) { cout << last << endl; return last; } // 2. Recursive Case: Unpacks the first item and passes the rest forward template void print_all(First first, Rest... rest) { cout << first << ", "; // Recursive call with the remaining parameter pack print_all(rest...); } // Helper to unpack the tuple template void unpack_helper(const Tuple& t, index_sequence object1 ) { print_all( get(t)... ) ; } template void unpack_and_print( const Tuple& tupleObject ) { // Generate indices based on the size of the tuple constexpr auto size = tuple_size_v ; //creates a sort of list of numbers up to the size of the tuple //auto indexSequenceObject1 = make_index_sequence{} ; //index_sequence unpack_helper( tupleObject, make_index_sequence{} ) ; } // Helper for the recursive step template constexpr auto array_to_tuple_impl(const std::array& arr, Ts&&... args) { if constexpr (Index == N) { return std::make_tuple(std::forward(args)...); } else { return array_to_tuple_impl( arr, std::forward(args)..., arr[Index] ); } } // Entry point function template constexpr auto array2tuple(const std::array& arr) { return array_to_tuple_impl(arr); } int main() { std::array arr1 = { 10, 2, 5 } ; auto tupleFromArray = array2tuple( arr1 ) ; cout << get<0>(tupleFromArray) << endl ; cout << get<1>(tupleFromArray) << endl ; cout << "-----" << endl ; unpack_and_print( tupleFromArray ) ; return 0; }