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_TRANSFORM_VIEW_07162005_1037)
8#define FUSION_TRANSFORM_VIEW_07162005_1037
9
10#include <boost/fusion/support/config.hpp>
11#include <boost/static_assert.hpp>
12#include <boost/fusion/support/detail/access.hpp>
13#include <boost/fusion/support/is_view.hpp>
14#include <boost/fusion/support/category_of.hpp>
15#include <boost/fusion/view/transform_view/transform_view_iterator.hpp>
16#include <boost/fusion/view/transform_view/transform_view_fwd.hpp>
17#include <boost/fusion/view/transform_view/detail/begin_impl.hpp>
18#include <boost/fusion/view/transform_view/detail/end_impl.hpp>
19#include <boost/fusion/view/transform_view/detail/at_impl.hpp>
20#include <boost/fusion/view/transform_view/detail/value_at_impl.hpp>
21#include <boost/fusion/view/detail/strictest_traversal.hpp>
22#include <boost/fusion/container/vector/vector10.hpp>
23#include <boost/fusion/sequence/intrinsic/size.hpp>
24#include <boost/fusion/support/sequence_base.hpp>
25#include <boost/fusion/sequence/intrinsic/begin.hpp>
26#include <boost/fusion/sequence/intrinsic/end.hpp>
27#include <boost/fusion/sequence/intrinsic/size.hpp>
28#include <boost/mpl/bool.hpp>
29
30#ifdef _MSC_VER
31# pragma warning(push)
32# pragma warning(disable: 4512) // assignment operator could not be generated.
33#endif
34
35namespace boost { namespace fusion
36{
37 struct void_;
38 struct transform_view_tag;
39 struct transform_view2_tag;
40 struct fusion_sequence_tag;
41
42 // Binary Version
43 template <typename Sequence1, typename Sequence2, typename F>
44 struct transform_view : sequence_base<transform_view<Sequence1, Sequence2, F> >
45 {
46 BOOST_STATIC_ASSERT(result_of::size<Sequence1>::value == result_of::size<Sequence2>::value);
47 typedef transform_view2_tag fusion_tag;
48 typedef fusion_sequence_tag tag; // this gets picked up by MPL
49 typedef mpl::true_ is_view;
50
51 typedef typename traits::category_of<Sequence1>::type category1;
52 typedef typename traits::category_of<Sequence2>::type category2;
53 typedef typename detail::strictest_traversal<
54 fusion::vector2<Sequence1, Sequence2> >::type category;
55 typedef typename result_of::begin<Sequence1>::type first1_type;
56 typedef typename result_of::begin<Sequence2>::type first2_type;
57 typedef typename result_of::end<Sequence1>::type last1_type;
58 typedef typename result_of::end<Sequence2>::type last2_type;
59 typedef typename result_of::size<Sequence1>::type size;
60 typedef Sequence1 sequence1_type;
61 typedef Sequence2 sequence2_type;
62 typedef F transform_type;
63
64 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
65 transform_view(Sequence1& in_seq1, Sequence2& in_seq2, F const& binop)
66 : f(binop)
67 , seq1(in_seq1)
68 , seq2(in_seq2)
69 {}
70
71 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
72 first1_type first1() const { return fusion::begin(seq1); }
73 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
74 first2_type first2() const { return fusion::begin(seq2); }
75 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
76 last1_type last1() const { return fusion::end(seq1); }
77 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
78 last2_type last2() const { return fusion::end(seq2); }
79
80 transform_type f;
81 typename mpl::if_<traits::is_view<Sequence1>, Sequence1, Sequence1&>::type seq1;
82 typename mpl::if_<traits::is_view<Sequence2>, Sequence2, Sequence2&>::type seq2;
83 };
84
85 // Unary Version
86 template <typename Sequence, typename F>
87#if defined(BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS)
88 struct transform_view<Sequence, F, void_> : sequence_base<transform_view<Sequence, F, void_> >
89#else
90 struct transform_view<Sequence, F> : sequence_base<transform_view<Sequence, F> >
91#endif
92 {
93 typedef transform_view_tag fusion_tag;
94 typedef fusion_sequence_tag tag; // this gets picked up by MPL
95 typedef mpl::true_ is_view;
96
97 typedef typename traits::category_of<Sequence>::type category;
98 typedef typename result_of::begin<Sequence>::type first_type;
99 typedef typename result_of::end<Sequence>::type last_type;
100 typedef typename result_of::size<Sequence>::type size;
101 typedef Sequence sequence_type;
102 typedef F transform_type;
103
104 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
105 transform_view(Sequence& in_seq, F const& in_f)
106 : seq(in_seq)
107 , f(in_f)
108 {}
109
110 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
111 first_type first() const { return fusion::begin(seq); }
112 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
113 last_type last() const { return fusion::end(seq); }
114 typename mpl::if_<traits::is_view<Sequence>, Sequence, Sequence&>::type seq;
115 transform_type f;
116 };
117}}
118
119#ifdef _MSC_VER
120# pragma warning(pop)
121#endif
122
123#endif
124
125
126