|
C++ Template Metaprogramming
Solutions to the exercises throughout the book
|
Write Fibonacci sequences with Boost MPL's sequence APIs. More...
Files | |
| file | exercise-5-8.hpp |
| Solution to Exercise 5-8. | |
Namespaces | |
| namespace | test_5_8 |
| Tests functionality from Exercise 5-8. | |
| namespace | exercise_5_8 |
| Encapsulate solution for Exercise 5-8. | |
Classes | |
| struct | boost::mpl::begin_impl< exercise_5_8::fibonacci_series_tag > |
| Start with 1 in the "last" position so we don't waste time with 0+0. More... | |
| struct | boost::mpl::next< exercise_5_8::fibonacci_series_iterator< N, LastN > > |
| Make the new N the sum of both numbers; save the old N. More... | |
| struct | boost::mpl::deref< exercise_5_8::fibonacci_series_iterator< N, LastN > > |
| Give us N. More... | |
Write Fibonacci sequences with Boost MPL's sequence APIs.
5-8. Write a fibonacci_series class that represents an infinite forward
sequence of Fibonacci numbers:
typedef mpl::advance_c<
mpl::begin<fibonacci_series>::type, 6 >::type i;
BOOST_STATIC_ASSERT( mpl::deref<i>::type::value == 8 );
typedef mpl::advance_c< i, 4 >::type j;
BOOST_STATIC_ASSERT( mpl::deref<j>::type::value == 55 );
Each element of the Fibonacci series is the sum of the previous two
elements. The series begins 0, 1, 1, 2, 3, 5, 8, 13....