Appearance
Simple Tuple Implementation
A tuple is a fixed-size collection of elements of different types.
Your Task
Implement a simple tuple class that supports the following operations:
- A constructor that accepts any number of arguments and stores them in the tuple.
- A
get<N>()method that returns the Nth element of the tuple. - A
size()method that returns the number of elements in the tuple.
Example
cpp
int num = 1;
Tuple<int, double, std::string> tuple(num, 2.0, "Hello"); // works with both lvalues and rvalues
std::cout << tuple.get<0>() << std::endl; // 1
std::cout << tuple.get<1>() << std::endl; // 2.0
std::cout << tuple.get<2>() << std::endl; // Hello
std::cout << tuple.size() << std::endl; // 3Implement a simple tuple class template that can store any number of values of different types. The tuple should have a constructor that uses perfect forwarding to accept the values, and a get() method to retrieve the Nth element (0-indexed). Use variadic templates and perfect forwarding.
cpp
#include <utility>
// TODO: Implement a simple tuple class template that can store any number of values of different types.
// The tuple should have:
// 1. A constructor that uses perfect forwarding to accept the values
// 2. A get<N>() method to retrieve the Nth element (0-indexed)
// 3. Use variadic templates and perfect forwarding
// Your implementation here
template<typename... Types>
class Tuple;