go to start Ex W7
|home |print view |recent changes |changed April 11, 2018 |
|You are <- set your identity!

Sections: Line Iterator | Fibonacci Iterator | TESTAT 2: BoundedBuffer with iterators (const and non-const) and allowing non-default-constructible elements | Iterator for Dynamic Bounded Buffer | Non-Default-Constructible Elements |

Line Iterator ^

In many of the exercises in the CPlusPlus module you had to process input line by line. It would have been convenient to have a line iterator in order to use standard algorithms instead of the while loops used:

You can use boost to simplify your solution.

Fibonacci Iterator ^

In this first exercise you will implement a simple iterator similar to the iterator for integers from the lecture.

Instead of just counting your iterator will iterate through the Fibonacci numbers (https://en.wikipedia.org/wiki/Fibonacci_number). The given test cases expect your Fibonacci sequence to start with the value 0 for the zeroth number, 1 for the first number, 1 for the second number, and so on.

You need to implement the following members of the Fibonacci iterator:

We suggest you store the index (ith number) and not the Fibonacci value itself.

Here are the test cases: https:files/Test.cpp

You shall implement two versions of this iterator:

  1. Implement all operators yourself.
  2. Use the facilities of boost iterators (i.e. based on a counting iterator).

Note: Don't worry about efficiency in this exercise.

TESTAT 2: BoundedBuffer with iterators (const and non-const) and allowing non-default-constructible elements ^

Due date: Tuesday 1. May 2018 23:59 (CEST)

Iterator for Dynamic Bounded Buffer ^

Note: The task of this exercise will be part of Testat 2 (next week). Last week you have implemented a dynamic version of the bounded buffer. Finish that exercise first if you have not already completed it.

In this exercise you have to implement begin and end for your dynamic bounded buffer. This requires your own iterator type, which can cope with the non-consecutive nature of the elements in your heap memory. The implementation of your iterator must be robust, i.e. accesses outside the range specified by begin (inclusive) and end (exclusive) have to throw exceptions. It is not allowed to increment/decrement your iterator beyond these points (begin/end).

Create constant and non-constant iterators. Const iterators provide read-only access to the elements, while the non-const iterators allow changing the elements through the iterator. Don’t just copy-waste your const iterator implementation! Try to find a smart way to reuse the parts of your implementation and let the compiler do the work of duplicating your code.


Here are some test cases as suggestion to verify the functionality of your iterators. Note: It is just the suite for iterators, which you need to register in the Test.cpp file first:


If you struggle to get it all up and running at once, try to satisfy one test case after another. Comment out all test contents first. Add the contents of the first test (start at the top of the tests), make it compile, make it green, repeat with the next tests.

Non-Default-Constructible Elements ^

Adapt your dynamic bounded buffer to allow non-default-constructible types as element type. Use the approach you have seen in the lecture last week (allocating a std::byte[size] array and use placement new to move/copy the elements to the corresponding location).

Make sure that elements in the buffer get destructed exactly once (no undestroyed elements and no double deletes)!

Since you do not allocate arrays of the element type anymore the test cases for new and delete change, i.e. those operators of the element type are not used anymore. The bounded_buffer_heap_memory_suite has been adapted accordingly.

Here are the test cases: https:files/NonDefaultConstructibleTypeTests.zip


|home |print view |recent changes |changed April 11, 2018 |
|You are <- set your identity!

Ex W7
go to start