C++ Template Metaprogramming
Solutions to the exercises throughout the book
Loading...
Searching...
No Matches
chapter-7-permutation_view.hpp
Go to the documentation of this file.
1// ===-- chapter-7/chapter-7-permutation_view.hpp --------- -*- C++ -*- --=== //
10#ifndef CHAPTER_7_PERMUTATION_VIEW
11#define CHAPTER_7_PERMUTATION_VIEW
12
13#include <boost/mpl/advance.hpp>
14#include <boost/mpl/begin_end.hpp>
15#include <boost/mpl/deref.hpp>
16#include <boost/mpl/iterator_tags.hpp>
17#include <boost/mpl/iterator_category.hpp>
18#include <boost/mpl/next_prior.hpp>
19
20
23namespace chapter7 {
24
39template <typename CurIdxIter, typename SeqBegin>
41{
42 typedef CurIdxIter current_index_iter;
43 typedef SeqBegin sequence_begin;
44
45 typedef typename boost::mpl::iterator_category<CurIdxIter>::type category;
47};
48
51
72template <typename Indices, typename Sequence>
74{
75 typedef Indices indices;
76 typedef Sequence orig_sequence;
77
79};
80
81} // namespace chapter7
82
83
84namespace boost {
85namespace mpl {
86
89
91template <>
92struct begin_impl<chapter7::permutation_view_tag>
93{
94 // Maybe I should just use duck typing instead of disallowing anything but
95 // permutation_view (i.e., use Sequence::indices, etc.)
96 template <typename Sequence> struct apply { };
97
98 template <typename Indices, typename Sequence>
99 struct apply< chapter7::permutation_view<Indices, Sequence> >
101 typename begin<Indices>::type, typename begin<Sequence>::type>
102 { };
103};
104
107template <>
108struct end_impl<chapter7::permutation_view_tag>
109{
110 // Maybe I should only really allow permutation_view here...
111 template <typename Sequence>
112 struct apply
114 typename end<typename Sequence::indices>::type,
115 typename begin<typename Sequence::orig_sequence>::type>
116 { };
117};
118
120template <typename CurIdxIter, typename SeqBegin>
121struct deref< chapter7::permutation_iterator<CurIdxIter, SeqBegin> >
122 : deref<typename advance<SeqBegin, typename deref<CurIdxIter>::type>::type>
123{ };
124
126template <typename CurIdxIter, typename SeqBegin>
127struct next< chapter7::permutation_iterator<CurIdxIter, SeqBegin> >
128 : chapter7::permutation_iterator<typename next<CurIdxIter>::type, SeqBegin>
129{ };
130
132template <typename CurIdxIter, typename SeqBegin>
133struct prior< chapter7::permutation_iterator<CurIdxIter, SeqBegin> >
134 : chapter7::permutation_iterator<typename prior<CurIdxIter>::type, SeqBegin>
135{ };
136
138
139} // namespace mpl
140} // namespace boost
141
142#endif // CHAPTER_7_PERMUTATION_VIEW
Exists to inject functionality into the Boost MPL namespace.
Exists to inject functionality into the Boost namespace.
Provide utilities availble to all Chapter 7 solutions.
Iterates across a seqence in an order defined by another sequence.
permutation_iterator< CurIdxIter, SeqBegin > type
boost::mpl::iterator_category< CurIdxIter >::type category
Type for tag-based implementation of algorithms below.
Alter the order sequence traversal using a sequence of positions.