#include #include using namespace std ; /* make_integer_sequence - creates a sequence of 0, ..., N - 1 with type T. index_sequence_for - converts a template parameter pack into an integer sequence. index_sequence is simply a specialized alias for integer_sequence print any tuple */ // 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 ; constexpr size_t size = std::tuple_size::value; //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{} ) ; } int main() { // auto my_tuple = make_tuple(1, 3.14, 'A') ; tuple my_tuple = make_tuple(1, 3.14, 'A') ; //We want to print all the elements of the tuple //but we don't know how many elements are in our tuple // const size_t sizeOfMyTuple = tuple_size_v< decltype(my_tuple) > ; //cout << get<0>(my_tuple) << endl ; //cout << get<1>(my_tuple) << endl ; //However if we don't know the size // beforehand we cannot just run a for loop //We need a compile time constant /* for( int i1=0 ; i1 < sizeOfMyTuple ; i1++ ) { cout << get(my_tuple) << endl ; } //for */ unpack_and_print( my_tuple ) ; return 0; }