Challenge: Dynamic Tuple Creation

Put your skills to the test, and leverage modern C++ features to create dynamic tuples.

We'll cover the following

Problem statement

In the ever-evolving domain of programming, crafting a dynamically adaptable solution is paramount. Your job is to engineer a flexible container class named dynamicTuple that can dynamically hold elements of different types. This container should support adding new elements, accessing values by index, and applying functions to its elements. Additionally, you need to implement a function to access the private members of the dynamicTuple class.

Note: Your implementation should utilize modern C++ features such as variadic templates, forwarding reference, and friendship in templates to achieve the required functionality.

Analysis

We can extract the following information from the problem statement:

  • The dynamicTuple class: A variadic template class that takes a variable number of arguments of different types. The constructor should accept any number of arguments and construct the internal storage to hold these elements. You can use std::tuple class for this purpose.

  • The get_value function: Implement a member function that returns the value at a specific index in the dynamicTuple.

  • The append function: Implement a member function that appends new elements to the existing dynamicTuple and returns a new instance of the modified tuple.

  • The apply_function function: Implement a member function that applies a given function to each element of the dynamicTuple. You can use the following declaration as the starting point:

Get hands-on with 1200+ tech skills courses.