Generative Software Development: C++ (week 5 2006)
© Performance Engineering Laboratory

Exercises for Wednesday 1 February 2006

You are welcome to do these exercises in groups of 2-3 people.

The starting point for these exercises is a routine, called it X, available at the C++ standard library. You will get X from Jyrki.

The only tools you need are a text editor (e.g. emacs) and a C++ compiler (e.g. g++).

1. Write a small test program that tests the correctness of routine X in the standard library shipped with your compiler. You can take inspiration from the small test programs given in the book by Austern (Jyrki has a copy with him). However, your program should not provide any output if everything is okay. Use #include cassert and assertions to do that.

2. Implement routine X by yourself. You can find the specification of X, for example, from Austern's book.

3. Use your test program developed in exercise 1 to test the functionality of your version of X from exercise 2. If you feel that your program works fine, you can send your solution to exercises 1 and 2 to Jyrki so he will put the programs to the CPH STL.

4. Consider the following template program taken from [Veldhuizen 2000]:

template<int N> 
void foo() {
  foo<N - 1>();
}

template<>
void foo<0>() {
}

int main () {
  //add a call to foo
}

Test this code snippet with various values of N. How long should it take to instantiate fooN? Try to estimate the actual compilation time as a function of N (e.g. using time shell command).

5. If you fell that you are too experienced to do the exercises 1-4, or if you have already done them, you can take part in a collaborative software-development experience and write a piece of the CPH STL priority queue, the development of which we started this morning.