| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | Copyright (c) 2006 Dan Marsden |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | ==============================================================================*/ |
| 8 | #if !defined(FUSION_END_IMPL_20060123_2208) |
| 9 | #define FUSION_END_IMPL_20060123_2208 |
| 10 | |
| 11 | #include <boost/fusion/support/config.hpp> |
| 12 | #include <boost/fusion/view/zip_view/zip_view_iterator_fwd.hpp> |
| 13 | #include <boost/fusion/sequence/intrinsic/end.hpp> |
| 14 | #include <boost/fusion/sequence/intrinsic/begin.hpp> |
| 15 | #include <boost/fusion/sequence/intrinsic/size.hpp> |
| 16 | #include <boost/fusion/sequence/intrinsic/front.hpp> |
| 17 | #include <boost/fusion/iterator/advance.hpp> |
| 18 | #include <boost/fusion/algorithm/transformation/transform.hpp> |
| 19 | #include <boost/type_traits/remove_reference.hpp> |
| 20 | #include <boost/type_traits/is_reference.hpp> |
| 21 | #include <boost/mpl/assert.hpp> |
| 22 | #include <boost/mpl/min.hpp> |
| 23 | |
| 24 | #include <boost/mpl/eval_if.hpp> |
| 25 | #include <boost/mpl/identity.hpp> |
| 26 | #include <boost/type_traits/is_same.hpp> |
| 27 | |
| 28 | namespace boost { namespace fusion { |
| 29 | |
| 30 | struct zip_view_tag; |
| 31 | |
| 32 | namespace detail |
| 33 | { |
| 34 | template<typename SeqRef, typename M> |
| 35 | struct get_endpoint |
| 36 | { |
| 37 | typedef typename remove_reference<SeqRef>::type Seq; |
| 38 | typedef typename result_of::begin<Seq>::type begin; |
| 39 | typedef typename result_of::advance<begin, M>::type type; |
| 40 | }; |
| 41 | |
| 42 | template<typename M> |
| 43 | struct endpoints |
| 44 | { |
| 45 | template<typename T> |
| 46 | struct result; |
| 47 | |
| 48 | template<typename M1, typename SeqRef> |
| 49 | struct result<endpoints<M1>(SeqRef)> |
| 50 | : mpl::eval_if<is_same<SeqRef, unused_type const&>, |
| 51 | mpl::identity<unused_type>, |
| 52 | get_endpoint<SeqRef, M> > |
| 53 | { |
| 54 | BOOST_MPL_ASSERT((is_reference<SeqRef>)); |
| 55 | }; |
| 56 | |
| 57 | template<typename Seq> |
| 58 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 59 | typename result<endpoints(Seq&)>::type |
| 60 | operator()(Seq& seq) const |
| 61 | { |
| 62 | return fusion::advance<M>(fusion::begin(seq)); |
| 63 | } |
| 64 | |
| 65 | template<typename Seq> |
| 66 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 67 | typename result<endpoints(Seq const&)>::type |
| 68 | operator()(Seq const& seq) const |
| 69 | { |
| 70 | return fusion::advance<M>(fusion::begin(seq)); |
| 71 | } |
| 72 | |
| 73 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 74 | unused_type operator()(unused_type const&) const |
| 75 | { |
| 76 | return unused_type(); |
| 77 | } |
| 78 | }; |
| 79 | } |
| 80 | |
| 81 | namespace extension |
| 82 | { |
| 83 | template<typename Tag> |
| 84 | struct end_impl; |
| 85 | |
| 86 | template<> |
| 87 | struct end_impl<zip_view_tag> |
| 88 | { |
| 89 | template<typename Sequence> |
| 90 | struct apply |
| 91 | { |
| 92 | typedef zip_view_iterator< |
| 93 | typename result_of::transform<typename Sequence::sequences, detail::endpoints<typename Sequence::size> >::type, |
| 94 | typename Sequence::category> type; |
| 95 | |
| 96 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 97 | static type |
| 98 | call(Sequence& sequence) |
| 99 | { |
| 100 | return type( |
| 101 | fusion::transform(sequence.sequences_, detail::endpoints<typename Sequence::size>())); |
| 102 | } |
| 103 | }; |
| 104 | }; |
| 105 | } |
| 106 | }} |
| 107 | |
| 108 | #endif |
| 109 | |