C++ Template Metaprogramming
Solutions to the exercises throughout the book
|
Chapter 1: Introduction | "You can think of this chapter as a warm-up for the rest of the book..." |
▼Chapter 2: Traits and Type Manipulation | "Metaprogramming as 'type computation'..." |
Exercise 2-0 | Define a metafunction to add const& |
Exercise 2-1 | Define a metafunction to replace types |
Exercise 2-2 | Rewrite boost::polymorphic_downcast |
Exercise 2-3 | Print data-types using Boost MPL |
Exercise 2-4 | Print data-types using a home-grown solution |
Exercise 2-5 | Describe a data-type in English |
▼Chapter 3: A Deeper Look at Metafunctions | "Adding static type checking to traditionally unchecked operations." |
Exercise 3-0 | Redefine the binary template to sanity-check its parameter |
Exercise 3-1 | Transform a vector by adding 1 to all its elements |
Exercise 3-2 | Square all elements in a sequence |
Exercise 3-3 | Manipulate pointers with the twice metafunction |
Exercise 3-4 | Iteratively call twice to add pointers to a type |
Exercise 3-5 | Add multiplication and division that honors units of measurement |
Exercise 3-6 | Rewrite twice as a lambda |
Exercise 3-8 | Add the ability to specify units |
▼Chapter 4: Integral Type Wappers and Operators | "How best to write metafunctions returning integral constants." |
Exercise 4-0 | Basic tests for MPL boolean operations |
Exercise 4-1 | Implement my own versions of Boost MPL boolean operations |
Exercise 4-2 | Implement my versions of MPL boolean operations with many arguments |
Exercise 4-3 | Weed out compile-time inefficiencies |
Exercise 4-4 | Implement some new type traits with existing MPL facilities |
Exercise 4-5 | Return different types based on parameter types |
▼Chapter 5: Sequences and Iterators | "Compile-time STL." |
Exercise 5-0 | Exercise the parts of tiny we've implemented |
Exercise 5-1 | Double the numbers in the first half of a RandomAccessSequence |
Exercise 5-10 | Write a tree structure with different view-based traversals |
Exercise 5-2 | Make push_front as strict as push_back |
Exercise 5-3 | Implement insert for tiny sequences |
Exercise 5-4 | Reducing push_back template instantiations |
Exercise 5-5 | Add algorithms for tiny |
Exercise 5-6 | Present array dimensions as a numerical sequence |
Exercise 5-7 | Provide bi-directional iterators to Exercise 5-6 |
Exercise 5-8 | Write Fibonacci sequences with Boost MPL's sequence APIs |
Exercise 5-9 | Limit the max number of elements in the Fibonacci sequence |
▼Chapter 6: Algorithms | All about the MPL algorithms |
Exercise 6-0 | Find the smallest type in a sequence with boost::mpl::copy |
Exercise 6-1 | Implement a binary to decimal converter as a sequence of binary digits |
Exercise 6-2 | Why is there no for_each ? |
Exercise 6-3 | Insert into a binary tree |
Exercise 6-4 | Search a binary tree structure using an inserter |
Exercise 6-5 | Differences between STL algorithms and MPL ones |
▼Chapter 7: Views and Iterators Adaptors | "This chapter covers the user of sequence views." |
Exercise 7-0 | Use zip_view |
Exercise 7-1 | Why use transform_view ? |
Exercise 7-2 | Modify zip_iterator category to be "least refined." |
Exercise 7-3 | Implement rotate_view sequence view |
Exercise 7-4 | Create permutation_iterator |
Exercise 7-5 | Change permutation_iterator traversal |
Exercise 7-6 | Create permutation_view from permutation_iterator |
Exercise 7-7 | Create a reverse view and iterator |
Exercise 7-8 | Create crossproduct_view |