Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3 Copyright (c) 2006 Dan Marsden
|
Chris@16
|
4
|
Chris@16
|
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 ==============================================================================*/
|
Chris@16
|
8 #if !defined(FUSION_ZIP_VIEW_23012006_0813)
|
Chris@16
|
9 #define FUSION_ZIP_VIEW_23012006_0813
|
Chris@16
|
10
|
Chris@16
|
11 #include <boost/fusion/support/sequence_base.hpp>
|
Chris@16
|
12 #include <boost/fusion/support/unused.hpp>
|
Chris@16
|
13 #include <boost/fusion/iterator/equal_to.hpp>
|
Chris@16
|
14 #include <boost/fusion/view/detail/strictest_traversal.hpp>
|
Chris@16
|
15 #include <boost/fusion/view/zip_view/detail/begin_impl.hpp>
|
Chris@16
|
16 #include <boost/fusion/view/zip_view/detail/end_impl.hpp>
|
Chris@16
|
17 #include <boost/fusion/view/zip_view/detail/size_impl.hpp>
|
Chris@16
|
18 #include <boost/fusion/view/zip_view/detail/at_impl.hpp>
|
Chris@16
|
19 #include <boost/fusion/view/zip_view/detail/value_at_impl.hpp>
|
Chris@16
|
20 #include <boost/fusion/container/vector/convert.hpp>
|
Chris@16
|
21 #include <boost/fusion/algorithm/query/find_if.hpp>
|
Chris@16
|
22 #include <boost/fusion/sequence/intrinsic/end.hpp>
|
Chris@16
|
23 #include <boost/fusion/sequence/intrinsic/size.hpp>
|
Chris@16
|
24 #include <boost/fusion/mpl.hpp>
|
Chris@16
|
25 #include <boost/fusion/algorithm/transformation/remove.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/mpl/assert.hpp>
|
Chris@16
|
28 #include <boost/mpl/not.hpp>
|
Chris@16
|
29 #include <boost/mpl/placeholders.hpp>
|
Chris@16
|
30 #include <boost/mpl/transform_view.hpp>
|
Chris@16
|
31 #include <boost/mpl/at.hpp>
|
Chris@16
|
32 #include <boost/mpl/find_if.hpp>
|
Chris@16
|
33 #include <boost/mpl/equal_to.hpp>
|
Chris@16
|
34 #include <boost/mpl/bool.hpp>
|
Chris@16
|
35 #include <boost/mpl/eval_if.hpp>
|
Chris@16
|
36
|
Chris@16
|
37 #include <boost/type_traits/remove_reference.hpp>
|
Chris@16
|
38 #include <boost/type_traits/is_reference.hpp>
|
Chris@16
|
39
|
Chris@16
|
40 #include <boost/config.hpp>
|
Chris@16
|
41
|
Chris@16
|
42 namespace boost { namespace fusion {
|
Chris@16
|
43
|
Chris@16
|
44 namespace detail
|
Chris@16
|
45 {
|
Chris@16
|
46 template<typename Sequences>
|
Chris@16
|
47 struct all_references
|
Chris@16
|
48 : fusion::result_of::equal_to<typename fusion::result_of::find_if<Sequences, mpl::not_<is_reference<mpl::_> > >::type, typename fusion::result_of::end<Sequences>::type>
|
Chris@16
|
49 {};
|
Chris@16
|
50
|
Chris@16
|
51 struct seq_ref_size
|
Chris@16
|
52 {
|
Chris@16
|
53 template<typename Params>
|
Chris@16
|
54 struct result;
|
Chris@16
|
55
|
Chris@16
|
56 template<typename Seq>
|
Chris@16
|
57 struct result<seq_ref_size(Seq)>
|
Chris@16
|
58 {
|
Chris@16
|
59 static int const high_int = static_cast<int>(
|
Chris@16
|
60 (static_cast<unsigned>(~0) >> 1) - 1);
|
Chris@16
|
61
|
Chris@16
|
62 typedef typename remove_reference<Seq>::type SeqClass;
|
Chris@16
|
63
|
Chris@16
|
64 typedef typename mpl::eval_if<
|
Chris@16
|
65 traits::is_forward<SeqClass>,
|
Chris@16
|
66 result_of::size<SeqClass>,
|
Chris@16
|
67 mpl::int_<high_int> >::type type;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 // never called, but needed for decltype-based result_of (C++0x)
|
Chris@16
|
71 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
72 template<typename Seq>
|
Chris@16
|
73 typename result<seq_ref_size(Seq)>::type
|
Chris@16
|
74 operator()(Seq&&) const;
|
Chris@16
|
75 #endif
|
Chris@16
|
76 };
|
Chris@16
|
77
|
Chris@16
|
78 struct poly_min
|
Chris@16
|
79 {
|
Chris@16
|
80 template<typename T>
|
Chris@16
|
81 struct result;
|
Chris@16
|
82
|
Chris@16
|
83 template<typename Lhs, typename Rhs>
|
Chris@16
|
84 struct result<poly_min(Lhs, Rhs)>
|
Chris@16
|
85 {
|
Chris@16
|
86 typedef typename remove_reference<Lhs>::type lhs;
|
Chris@16
|
87 typedef typename remove_reference<Rhs>::type rhs;
|
Chris@16
|
88 typedef typename mpl::min<lhs, rhs>::type type;
|
Chris@16
|
89 };
|
Chris@16
|
90
|
Chris@16
|
91 // never called, but needed for decltype-based result_of (C++0x)
|
Chris@16
|
92 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@16
|
93 template<typename Lhs, typename Rhs>
|
Chris@16
|
94 typename result<poly_min(Lhs, Rhs)>::type
|
Chris@16
|
95 operator()(Lhs&&, Rhs&&) const;
|
Chris@16
|
96 #endif
|
Chris@16
|
97 };
|
Chris@16
|
98
|
Chris@16
|
99 template<typename Sequences>
|
Chris@16
|
100 struct min_size
|
Chris@16
|
101 {
|
Chris@16
|
102 typedef typename result_of::transform<Sequences, detail::seq_ref_size>::type sizes;
|
Chris@16
|
103 typedef typename result_of::fold<sizes, typename result_of::front<sizes>::type, detail::poly_min>::type type;
|
Chris@16
|
104 };
|
Chris@16
|
105 }
|
Chris@16
|
106
|
Chris@16
|
107 struct zip_view_tag;
|
Chris@16
|
108 struct fusion_sequence_tag;
|
Chris@16
|
109
|
Chris@16
|
110 template<typename Sequences>
|
Chris@16
|
111 struct zip_view : sequence_base< zip_view<Sequences> >
|
Chris@16
|
112 {
|
Chris@16
|
113 typedef typename result_of::remove<Sequences, unused_type const&>::type real_sequences;
|
Chris@16
|
114 BOOST_MPL_ASSERT((detail::all_references<Sequences>));
|
Chris@16
|
115 typedef typename detail::strictest_traversal<real_sequences>::type category;
|
Chris@16
|
116 typedef zip_view_tag fusion_tag;
|
Chris@16
|
117 typedef fusion_sequence_tag tag; // this gets picked up by MPL
|
Chris@16
|
118 typedef mpl::true_ is_view;
|
Chris@16
|
119 typedef typename fusion::result_of::as_vector<Sequences>::type sequences;
|
Chris@16
|
120 typedef typename detail::min_size<real_sequences>::type size;
|
Chris@16
|
121
|
Chris@16
|
122 zip_view(
|
Chris@16
|
123 const Sequences& seqs)
|
Chris@16
|
124 : sequences_(seqs)
|
Chris@16
|
125 {};
|
Chris@16
|
126
|
Chris@16
|
127 sequences sequences_;
|
Chris@16
|
128 };
|
Chris@16
|
129 }}
|
Chris@16
|
130
|
Chris@16
|
131 #endif
|