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_INSERT_07222005_0730)
|
Chris@16
|
8 #define FUSION_INSERT_07222005_0730
|
Chris@16
|
9
|
Chris@101
|
10 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
11 #include <boost/fusion/support/detail/as_fusion_element.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/single_view/single_view.hpp>
|
Chris@16
|
16 #include <boost/fusion/view/iterator_range/iterator_range.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
|
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 Position, typename T>
|
Chris@16
|
28 struct insert
|
Chris@16
|
29 {
|
Chris@16
|
30 typedef typename detail::as_fusion_element<T>::type element_type;
|
Chris@16
|
31 typedef typename convert_iterator<Position>::type pos_type;
|
Chris@16
|
32 typedef typename result_of::begin<Sequence>::type first_type;
|
Chris@16
|
33 typedef typename result_of::end<Sequence>::type last_type;
|
Chris@16
|
34
|
Chris@16
|
35 typedef iterator_range<first_type, pos_type> left_type;
|
Chris@16
|
36 typedef iterator_range<pos_type, last_type> right_type;
|
Chris@16
|
37 typedef fusion::single_view<element_type> single_view;
|
Chris@16
|
38 typedef joint_view<left_type, single_view const> left_insert_type;
|
Chris@16
|
39 typedef joint_view<left_insert_type, right_type> type;
|
Chris@16
|
40 };
|
Chris@16
|
41 }
|
Chris@16
|
42
|
Chris@16
|
43 template <typename Sequence, typename Position, typename T>
|
Chris@101
|
44 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
45 inline typename
|
Chris@16
|
46 lazy_enable_if<
|
Chris@16
|
47 traits::is_sequence<Sequence>
|
Chris@16
|
48 , result_of::insert<Sequence const, Position, T>
|
Chris@16
|
49 >::type
|
Chris@16
|
50 insert(Sequence const& seq, Position const& pos, T const& x)
|
Chris@16
|
51 {
|
Chris@16
|
52 typedef result_of::insert<
|
Chris@16
|
53 Sequence const, Position, T>
|
Chris@16
|
54 result_of;
|
Chris@16
|
55 typedef typename result_of::left_type left_type;
|
Chris@16
|
56 typedef typename result_of::right_type right_type;
|
Chris@16
|
57 typedef typename result_of::single_view single_view;
|
Chris@16
|
58 typedef typename result_of::left_insert_type left_insert_type;
|
Chris@16
|
59 typedef typename result_of::type result;
|
Chris@16
|
60
|
Chris@16
|
61 left_type left(fusion::begin(seq), convert_iterator<Position>::call(pos));
|
Chris@16
|
62 right_type right(convert_iterator<Position>::call(pos), fusion::end(seq));
|
Chris@16
|
63 single_view insert(x);
|
Chris@16
|
64 left_insert_type left_insert(left, insert);
|
Chris@16
|
65 return result(left_insert, right);
|
Chris@16
|
66 }
|
Chris@16
|
67 }}
|
Chris@16
|
68
|
Chris@16
|
69 #endif
|
Chris@16
|
70
|