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