C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
exercise-5-8.hpp
Go to the documentation of this file.
1// ===-- chapter-5/exercise-5-8.hpp ----------------------- -*- C++ -*- --=== //
9#ifndef EXERCISE_5_8
10#define EXERCISE_5_8
11
12#include <boost/static_assert.hpp>
13
14#include <boost/mpl/advance.hpp>
15#include <boost/mpl/begin_end.hpp>
16#include <boost/mpl/deref.hpp>
17#include <boost/mpl/iterator_tags.hpp>
18#include <boost/mpl/next_prior.hpp>
19
20
44namespace exercise_5_8 {
45
48
58template <size_t N, size_t LastN>
60{
61 typedef boost::mpl::forward_iterator_tag category;
62};
63
66{
68};
69
70} // namespace exercise_5_8
71
72
73namespace boost {
74namespace mpl {
75
78
80template <>
81struct begin_impl<exercise_5_8::fibonacci_series_tag>
82{
83 template <typename S>
84 struct apply
85 {
87 };
88};
89
91template <size_t N, size_t LastN>
92struct next< exercise_5_8::fibonacci_series_iterator<N,LastN> >
93{
95};
96
98template <size_t N, size_t LastN>
99struct deref< exercise_5_8::fibonacci_series_iterator<N,LastN> >
100 : boost::mpl::int_<N> { };
101
103
104} // namespace mpl
105} // namespace boost
106
107#endif // EXERCISE_5_8
Exists to inject functionality into the Boost MPL namespace.
Exists to inject functionality into the Boost namespace.
Encapsulate solution for Exercise 5-8.
exercise_5_8::fibonacci_series_iterator< 0, 1 > type
exercise_5_8::fibonacci_series_iterator< N+LastN, N > type
Iterator for moving through Fibonacci series sequence.
boost::mpl::forward_iterator_tag category
A tag for tag-dispatched sequence metafunctions.
The Fibonacci series for use with Boost MPL sequences.
fibonacci_series_tag tag