Examine the program [`iterations.cpp`](task04/iterations.cpp) and think about the expected output.
Compile the program and run it.
What do you notice?
Did you expect this behaviour?
Did you get any compiler warnings?
Investigate what is actually happening (consider using `valgrind` or a debugger).
How can such errors be prevented?
Look for tools (e.g. static code analysers) which help discovering such faulty code.
**Note:** If you run the executable and everything seems normal, try changing the initial content of `xs`, using different optimisation flags, or a different compiler.
The actual behaviour of this executable depends on various factors.
See [Undefined Behaviour](https://en.cppreference.com/w/cpp/language/ub) and [Defining the undefinedness of C](https://dl.acm.org/citation.cfm?id=2737979).
Have a look at [this](https://bollu.github.io/mathemagic/declarative/index.html).
Now, do that in C++!
Utilize lambdas, `std::function`, and/or structs with call operators.
Critically think about ownership and minimize the amount of heap allocations.
## Task 11
Take a look at [Boost's chat server example](https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/examples/cpp11_examples.html#boost_asio.examples.cpp11_examples.chat).
Try to understand how the session's lifetime is managed by the server.
Focus on `std::enable_shared_from_this` in combination with lambda captures.
Think about taking the argument by value instead of taking it by const reference.
## Task 14
Implement your own version of `std::vector` without using any of the provided containers — use *regular arrays* (`new[]` / `delete[]`) to house your elements.
The focus of this task lies on the use of templates and implementation of iterators.
You do not have to concern yourself with custom allocators.
Test your implementation with different types (`int`, `double`, and a custom struct).
Take your vector from task 1 and implement iterators.
You might want to read through the respective documentation.
Write some tests utilising algorithms provided by the standard library to check if your iterators behave correctly.
## Task 15
Take your vector implementation from Task 14 and instantiate it with a big number of unique types.
Inspect the relationship between the number of unique instantiates and compile time.
Furthermore, look at the compiled object file using `nm`.