1 | /*============================================================================= |
---|---|
2 | Copyright (c) 2006 Eric Niebler |
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 | #if !defined(BOOST_FUSION_SEGMENTS_04052005_1141) |
8 | #define BOOST_FUSION_SEGMENTS_04052005_1141 |
9 | |
10 | #include <boost/fusion/support/config.hpp> |
11 | #include <boost/type_traits/is_const.hpp> |
12 | #include <boost/utility/enable_if.hpp> |
13 | #include <boost/fusion/sequence/intrinsic_fwd.hpp> |
14 | #include <boost/fusion/support/tag_of.hpp> |
15 | |
16 | namespace boost { namespace fusion |
17 | { |
18 | // Special tags: |
19 | struct sequence_facade_tag; |
20 | struct iterator_range_tag; |
21 | |
22 | // segments: returns a sequence of sequences |
23 | namespace extension |
24 | { |
25 | template <typename Tag> |
26 | struct segments_impl |
27 | { |
28 | template <typename Sequence> |
29 | struct apply {}; |
30 | }; |
31 | |
32 | template <> |
33 | struct segments_impl<sequence_facade_tag> |
34 | { |
35 | template <typename Sequence> |
36 | struct apply : Sequence::template segments<Sequence> {}; |
37 | }; |
38 | |
39 | template <> |
40 | struct segments_impl<iterator_range_tag>; |
41 | } |
42 | |
43 | namespace result_of |
44 | { |
45 | template <typename Sequence> |
46 | struct segments |
47 | { |
48 | typedef typename traits::tag_of<Sequence>::type tag_type; |
49 | |
50 | typedef typename |
51 | extension::segments_impl<tag_type>::template apply<Sequence>::type |
52 | type; |
53 | }; |
54 | } |
55 | |
56 | template <typename Sequence> |
57 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
58 | inline typename |
59 | lazy_disable_if< |
60 | is_const<Sequence> |
61 | , result_of::segments<Sequence> |
62 | >::type |
63 | segments(Sequence& seq) |
64 | { |
65 | typedef typename traits::tag_of<Sequence>::type tag_type; |
66 | return extension::segments_impl<tag_type>::template apply<Sequence>::call(seq); |
67 | } |
68 | |
69 | template <typename Sequence> |
70 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
71 | inline typename result_of::segments<Sequence const>::type |
72 | segments(Sequence const& seq) |
73 | { |
74 | typedef typename traits::tag_of<Sequence const>::type tag_type; |
75 | return extension::segments_impl<tag_type>::template apply<Sequence const>::call(seq); |
76 | } |
77 | }} |
78 | |
79 | #endif |
80 |