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