Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7 #if !defined(FUSION_ERASE_07232005_0534)
|
Chris@16
|
8 #define FUSION_ERASE_07232005_0534
|
Chris@16
|
9
|
Chris@16
|
10 #include <boost/fusion/iterator/equal_to.hpp>
|
Chris@16
|
11 #include <boost/fusion/iterator/mpl/convert_iterator.hpp>
|
Chris@16
|
12 #include <boost/fusion/container/vector/vector10.hpp>
|
Chris@16
|
13 #include <boost/fusion/view/joint_view/joint_view.hpp>
|
Chris@16
|
14 #include <boost/fusion/view/iterator_range/iterator_range.hpp>
|
Chris@16
|
15 #include <boost/fusion/support/detail/as_fusion_element.hpp>
|
Chris@16
|
16 #include <boost/fusion/sequence/intrinsic/begin.hpp>
|
Chris@16
|
17 #include <boost/fusion/sequence/intrinsic/end.hpp>
|
Chris@16
|
18 #include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
|
Chris@16
|
19 #include <boost/fusion/support/is_sequence.hpp>
|
Chris@16
|
20 #include <boost/utility/enable_if.hpp>
|
Chris@16
|
21 #include <boost/mpl/if.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost { namespace fusion
|
Chris@16
|
24 {
|
Chris@16
|
25 namespace result_of
|
Chris@16
|
26 {
|
Chris@16
|
27 template <typename Sequence, typename First>
|
Chris@16
|
28 struct compute_erase_last // put this in detail!!!
|
Chris@16
|
29 {
|
Chris@16
|
30 typedef typename result_of::end<Sequence>::type seq_last_type;
|
Chris@16
|
31 typedef typename convert_iterator<First>::type first_type;
|
Chris@16
|
32 typedef typename
|
Chris@16
|
33 mpl::if_<
|
Chris@16
|
34 result_of::equal_to<first_type, seq_last_type>
|
Chris@16
|
35 , first_type
|
Chris@16
|
36 , typename result_of::next<first_type>::type
|
Chris@16
|
37 >::type
|
Chris@16
|
38 type;
|
Chris@16
|
39
|
Chris@16
|
40 static type
|
Chris@16
|
41 call(First const& first, mpl::false_)
|
Chris@16
|
42 {
|
Chris@16
|
43 return fusion::next(convert_iterator<First>::call(first));
|
Chris@16
|
44 }
|
Chris@16
|
45
|
Chris@16
|
46 static type
|
Chris@16
|
47 call(First const& first, mpl::true_)
|
Chris@16
|
48 {
|
Chris@16
|
49 return convert_iterator<First>::call(first);
|
Chris@16
|
50 }
|
Chris@16
|
51
|
Chris@16
|
52 static type
|
Chris@16
|
53 call(First const& first)
|
Chris@16
|
54 {
|
Chris@16
|
55 return call(first, result_of::equal_to<first_type, seq_last_type>());
|
Chris@16
|
56 }
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 struct use_default;
|
Chris@16
|
60
|
Chris@16
|
61 template <class T, class Default>
|
Chris@16
|
62 struct fusion_default_help
|
Chris@16
|
63 : mpl::if_<
|
Chris@16
|
64 is_same<T, use_default>
|
Chris@16
|
65 , Default
|
Chris@16
|
66 , T
|
Chris@16
|
67 >
|
Chris@16
|
68 {
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71 template <
|
Chris@16
|
72 typename Sequence
|
Chris@16
|
73 , typename First
|
Chris@16
|
74 , typename Last = use_default>
|
Chris@16
|
75 struct erase
|
Chris@16
|
76 {
|
Chris@16
|
77 typedef typename result_of::begin<Sequence>::type seq_first_type;
|
Chris@16
|
78 typedef typename result_of::end<Sequence>::type seq_last_type;
|
Chris@16
|
79 BOOST_STATIC_ASSERT((!result_of::equal_to<seq_first_type, seq_last_type>::value));
|
Chris@16
|
80
|
Chris@16
|
81 typedef First FirstType;
|
Chris@16
|
82 typedef typename
|
Chris@16
|
83 fusion_default_help<
|
Chris@16
|
84 Last
|
Chris@16
|
85 , typename compute_erase_last<Sequence, First>::type
|
Chris@16
|
86 >::type
|
Chris@16
|
87 LastType;
|
Chris@16
|
88
|
Chris@16
|
89 typedef typename convert_iterator<FirstType>::type first_type;
|
Chris@16
|
90 typedef typename convert_iterator<LastType>::type last_type;
|
Chris@16
|
91 typedef iterator_range<seq_first_type, first_type> left_type;
|
Chris@16
|
92 typedef iterator_range<last_type, seq_last_type> right_type;
|
Chris@16
|
93 typedef joint_view<left_type, right_type> type;
|
Chris@16
|
94 };
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 template <typename Sequence, typename First>
|
Chris@16
|
98 typename
|
Chris@16
|
99 lazy_enable_if<
|
Chris@16
|
100 traits::is_sequence<Sequence>
|
Chris@16
|
101 , typename result_of::erase<Sequence const, First>
|
Chris@16
|
102 >::type
|
Chris@16
|
103 erase(Sequence const& seq, First const& first)
|
Chris@16
|
104 {
|
Chris@16
|
105 typedef result_of::erase<Sequence const, First> result_of;
|
Chris@16
|
106 typedef typename result_of::left_type left_type;
|
Chris@16
|
107 typedef typename result_of::right_type right_type;
|
Chris@16
|
108 typedef typename result_of::type result_type;
|
Chris@16
|
109
|
Chris@16
|
110 left_type left(
|
Chris@16
|
111 fusion::begin(seq)
|
Chris@16
|
112 , convert_iterator<First>::call(first));
|
Chris@16
|
113 right_type right(
|
Chris@16
|
114 fusion::result_of::compute_erase_last<Sequence const, First>::call(first)
|
Chris@16
|
115 , fusion::end(seq));
|
Chris@16
|
116 return result_type(left, right);
|
Chris@16
|
117 }
|
Chris@16
|
118
|
Chris@16
|
119 template <typename Sequence, typename First, typename Last>
|
Chris@16
|
120 typename result_of::erase<Sequence const, First, Last>::type
|
Chris@16
|
121 erase(Sequence const& seq, First const& first, Last const& last)
|
Chris@16
|
122 {
|
Chris@16
|
123 typedef result_of::erase<Sequence const, First, Last> result_of;
|
Chris@16
|
124 typedef typename result_of::left_type left_type;
|
Chris@16
|
125 typedef typename result_of::right_type right_type;
|
Chris@16
|
126 typedef typename result_of::type result_type;
|
Chris@16
|
127
|
Chris@16
|
128 left_type left(fusion::begin(seq), first);
|
Chris@16
|
129 right_type right(last, fusion::end(seq));
|
Chris@16
|
130 return result_type(left, right);
|
Chris@16
|
131 }
|
Chris@16
|
132 }}
|
Chris@16
|
133
|
Chris@16
|
134 #endif
|
Chris@16
|
135
|