]>
Commit | Line | Data |
---|---|---|
1 | /*============================================================================= | |
2 | Copyright (c) 2001-2011 Joel de Guzman | |
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(FUSION_INSERT_07222005_0730) | |
8 | #define FUSION_INSERT_07222005_0730 | |
9 | ||
10 | #include <boost/fusion/support/config.hpp> | |
11 | #include <boost/fusion/support/detail/as_fusion_element.hpp> | |
12 | #include <boost/fusion/iterator/mpl/convert_iterator.hpp> | |
13 | #include <boost/fusion/view/joint_view/joint_view.hpp> | |
14 | #include <boost/fusion/view/single_view/single_view.hpp> | |
15 | #include <boost/fusion/view/iterator_range/iterator_range.hpp> | |
16 | #include <boost/fusion/sequence/intrinsic/begin.hpp> | |
17 | #include <boost/fusion/sequence/intrinsic/end.hpp> | |
18 | #include <boost/fusion/adapted/mpl/mpl_iterator.hpp> | |
19 | #include <boost/fusion/support/is_sequence.hpp> | |
20 | #include <boost/utility/enable_if.hpp> | |
21 | ||
22 | namespace boost { namespace fusion | |
23 | { | |
24 | namespace result_of | |
25 | { | |
26 | template <typename Sequence, typename Position, typename T> | |
27 | struct insert | |
28 | { | |
29 | typedef typename detail::as_fusion_element<T>::type element_type; | |
30 | typedef typename convert_iterator<Position>::type pos_type; | |
31 | typedef typename result_of::begin<Sequence>::type first_type; | |
32 | typedef typename result_of::end<Sequence>::type last_type; | |
33 | ||
34 | typedef iterator_range<first_type, pos_type> left_type; | |
35 | typedef iterator_range<pos_type, last_type> right_type; | |
36 | typedef fusion::single_view<element_type> single_view; | |
37 | typedef joint_view<left_type, single_view const> left_insert_type; | |
38 | typedef joint_view<left_insert_type, right_type> type; | |
39 | }; | |
40 | } | |
41 | ||
42 | template <typename Sequence, typename Position, typename T> | |
43 | BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED | |
44 | inline typename | |
45 | lazy_enable_if< | |
46 | traits::is_sequence<Sequence> | |
47 | , result_of::insert<Sequence const, Position, T> | |
48 | >::type | |
49 | insert(Sequence const& seq, Position const& pos, T const& x) | |
50 | { | |
51 | typedef result_of::insert< | |
52 | Sequence const, Position, T> | |
53 | result_of; | |
54 | typedef typename result_of::left_type left_type; | |
55 | typedef typename result_of::right_type right_type; | |
56 | typedef typename result_of::single_view single_view; | |
57 | typedef typename result_of::left_insert_type left_insert_type; | |
58 | typedef typename result_of::type result; | |
59 | ||
60 | left_type left(fusion::begin(seq), convert_iterator<Position>::call(pos)); | |
61 | right_type right(convert_iterator<Position>::call(pos), fusion::end(seq)); | |
62 | single_view insert(x); | |
63 | left_insert_type left_insert(left, insert); | |
64 | return result(left_insert, right); | |
65 | } | |
66 | }} | |
67 | ||
68 | #endif | |
69 |