Chris@102
|
1 /*//////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
2 Copyright (c) 2013 Jamboree
|
Chris@102
|
3
|
Chris@102
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
6 //////////////////////////////////////////////////////////////////////////////*/
|
Chris@102
|
7 #ifndef BOOST_FUSION_FLATTEN_VIEW_HPP_INCLUDED
|
Chris@102
|
8 #define BOOST_FUSION_FLATTEN_VIEW_HPP_INCLUDED
|
Chris@102
|
9
|
Chris@102
|
10
|
Chris@102
|
11 #include <boost/fusion/support/config.hpp>
|
Chris@102
|
12 #include <boost/mpl/bool.hpp>
|
Chris@102
|
13 #include <boost/mpl/single_view.hpp>
|
Chris@102
|
14 #include <boost/fusion/support/detail/access.hpp>
|
Chris@102
|
15 #include <boost/fusion/support/is_view.hpp>
|
Chris@102
|
16 #include <boost/fusion/support/category_of.hpp>
|
Chris@102
|
17 #include <boost/fusion/support/sequence_base.hpp>
|
Chris@102
|
18 #include <boost/fusion/sequence/intrinsic/begin.hpp>
|
Chris@102
|
19 #include <boost/fusion/sequence/intrinsic/end.hpp>
|
Chris@102
|
20 #include <boost/fusion/view/flatten_view/flatten_view_iterator.hpp>
|
Chris@102
|
21
|
Chris@102
|
22
|
Chris@102
|
23 namespace boost { namespace fusion
|
Chris@102
|
24 {
|
Chris@102
|
25 struct forward_traversal_tag;
|
Chris@102
|
26 struct flatten_view_tag;
|
Chris@102
|
27
|
Chris@102
|
28 template <typename Sequence>
|
Chris@102
|
29 struct flatten_view
|
Chris@102
|
30 : sequence_base<flatten_view<Sequence> >
|
Chris@102
|
31 {
|
Chris@102
|
32 typedef flatten_view_tag fusion_tag;
|
Chris@102
|
33 typedef fusion_sequence_tag tag; // this gets picked up by MPL
|
Chris@102
|
34 typedef mpl::true_ is_view;
|
Chris@102
|
35 typedef forward_traversal_tag category;
|
Chris@102
|
36
|
Chris@102
|
37 typedef Sequence sequence_type;
|
Chris@102
|
38 typedef typename result_of::begin<Sequence>::type first_type;
|
Chris@102
|
39 typedef typename result_of::end<Sequence>::type last_type;
|
Chris@102
|
40
|
Chris@102
|
41 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@102
|
42 explicit flatten_view(Sequence& seq)
|
Chris@102
|
43 : seq(seq)
|
Chris@102
|
44 {}
|
Chris@102
|
45
|
Chris@102
|
46 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@102
|
47 first_type first() const { return fusion::begin(seq); }
|
Chris@102
|
48 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@102
|
49 last_type last() const { return fusion::end(seq); }
|
Chris@102
|
50
|
Chris@102
|
51 typename mpl::if_<traits::is_view<Sequence>, Sequence, Sequence&>::type seq;
|
Chris@102
|
52 };
|
Chris@102
|
53 }}
|
Chris@102
|
54
|
Chris@102
|
55 namespace boost { namespace fusion { namespace extension
|
Chris@102
|
56 {
|
Chris@102
|
57 template<>
|
Chris@102
|
58 struct begin_impl<flatten_view_tag>
|
Chris@102
|
59 {
|
Chris@102
|
60 template<typename Sequence>
|
Chris@102
|
61 struct apply
|
Chris@102
|
62 {
|
Chris@102
|
63 typedef typename Sequence::first_type first_type;
|
Chris@102
|
64
|
Chris@102
|
65 typedef typename
|
Chris@102
|
66 result_of::begin<
|
Chris@102
|
67 mpl::single_view<
|
Chris@102
|
68 typename Sequence::sequence_type> >::type
|
Chris@102
|
69 root_iterator;
|
Chris@102
|
70
|
Chris@102
|
71 typedef
|
Chris@102
|
72 detail::seek_descent<root_iterator, first_type>
|
Chris@102
|
73 seek_descent;
|
Chris@102
|
74
|
Chris@102
|
75 typedef typename seek_descent::type type;
|
Chris@102
|
76
|
Chris@102
|
77 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@102
|
78 static inline
|
Chris@102
|
79 type call(Sequence& seq)
|
Chris@102
|
80 {
|
Chris@102
|
81 return seek_descent::apply(root_iterator(), seq.first());
|
Chris@102
|
82 }
|
Chris@102
|
83 };
|
Chris@102
|
84 };
|
Chris@102
|
85
|
Chris@102
|
86 template<>
|
Chris@102
|
87 struct end_impl<flatten_view_tag>
|
Chris@102
|
88 {
|
Chris@102
|
89 template<typename Sequence>
|
Chris@102
|
90 struct apply
|
Chris@102
|
91 {
|
Chris@102
|
92 typedef typename Sequence::last_type last_type;
|
Chris@102
|
93
|
Chris@102
|
94 typedef typename
|
Chris@102
|
95 result_of::end<
|
Chris@102
|
96 mpl::single_view<
|
Chris@102
|
97 typename Sequence::sequence_type> >::type
|
Chris@102
|
98 type;
|
Chris@102
|
99
|
Chris@102
|
100 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@102
|
101 static inline
|
Chris@102
|
102 type call(Sequence&)
|
Chris@102
|
103 {
|
Chris@102
|
104 return type();
|
Chris@102
|
105 }
|
Chris@102
|
106 };
|
Chris@102
|
107 };
|
Chris@102
|
108
|
Chris@102
|
109 template<>
|
Chris@102
|
110 struct size_impl<flatten_view_tag>
|
Chris@102
|
111 {
|
Chris@102
|
112 template <typename Sequence>
|
Chris@102
|
113 struct apply
|
Chris@102
|
114 : result_of::distance
|
Chris@102
|
115 <
|
Chris@102
|
116 typename result_of::begin<Sequence>::type
|
Chris@102
|
117 , typename result_of::end<Sequence>::type
|
Chris@102
|
118 >
|
Chris@102
|
119 {};
|
Chris@102
|
120 };
|
Chris@102
|
121
|
Chris@102
|
122 template<>
|
Chris@102
|
123 struct empty_impl<flatten_view_tag>
|
Chris@102
|
124 {
|
Chris@102
|
125 template <typename Sequence>
|
Chris@102
|
126 struct apply
|
Chris@102
|
127 : result_of::empty<typename Sequence::sequence_type>
|
Chris@102
|
128 {};
|
Chris@102
|
129 };
|
Chris@102
|
130 }}}
|
Chris@102
|
131
|
Chris@102
|
132
|
Chris@102
|
133 #endif
|