In this exercise, we will take the tuple
implementation from the slides
and extend it step by step to make the example code in main
compile.
Feel free to comment out parts of main to test parts of your implementation sooner.
All instructions are given in more detail in the source code as well, especially inside main
.
This example neglects const correctness so there is less code to write. Making it const correct would require adding several overloads with almost the same code as the non-const version. You can try this is a bonus exercise at the end!
- make
tuple
default-constructible - avoid implicit construction from a single value
- write
head(tuple)
, which returns the first element of a tuple - implement
get<I>(tuple)
- specialize
std::tuple_size
- specialize
std::tuple_element
- implement a binary
tuple_cat(tuple, tuple)
- implement
sum(tuple)
- implement
operator<<
, producing comma separated output