1 /*============================================================================= 2 Copyright (c) 2009 Hartmut Kaiser 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 8 #if !defined(BOOST_FUSION_NVIEW_SEP_23_2009_0948PM) 9 #define BOOST_FUSION_NVIEW_SEP_23_2009_0948PM 10 11 #include <boost/fusion/support/config.hpp> 12 #include <boost/mpl/size.hpp> 13 #include <boost/mpl/if.hpp> 14 #include <boost/mpl/vector_c.hpp> 15 #include <boost/utility/result_of.hpp> 16 17 #include <boost/type_traits/remove_reference.hpp> 18 #include <boost/type_traits/add_reference.hpp> 19 #include <boost/type_traits/add_const.hpp> 20 21 #include <boost/fusion/support/is_view.hpp> 22 #include <boost/fusion/support/category_of.hpp> 23 #include <boost/fusion/support/sequence_base.hpp> 24 #include <boost/fusion/container/vector.hpp> 25 #include <boost/fusion/view/transform_view.hpp> 26 27 #include <boost/config.hpp> 28 29 namespace boost { namespace fusion 30 { 31 namespace detail 32 { 33 struct addref 34 { 35 template<typename Sig> 36 struct result; 37 38 template<typename U> 39 struct result<addref(U)> : add_reference<U> {}; 40 41 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES 42 template <typename T> 43 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 44 typename add_reference<T>::type operator ()boost::fusion::detail::addref45 operator()(T& x) const 46 { 47 return x; 48 } 49 #else 50 template <typename T> 51 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 52 typename result<addref(T)>::type operator ()boost::fusion::detail::addref53 operator()(T&& x) const 54 { 55 return x; 56 } 57 #endif 58 }; 59 60 struct addconstref 61 { 62 template<typename Sig> 63 struct result; 64 65 template<typename U> 66 struct result<addconstref(U)> 67 : add_reference<typename add_const<U>::type> 68 {}; 69 70 template <typename T> 71 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 72 typename add_reference<typename add_const<T>::type>::type operator ()boost::fusion::detail::addconstref73 operator()(T& x) const 74 { 75 return x; 76 } 77 78 template <typename T> 79 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED 80 typename add_reference<typename add_const<T>::type>::type operator ()boost::fusion::detail::addconstref81 operator()(T const& x) const 82 { 83 return x; 84 } 85 }; 86 } 87 88 struct nview_tag; 89 struct random_access_traversal_tag; 90 struct fusion_sequence_tag; 91 92 template<typename Sequence, typename Indicies> 93 struct nview 94 : sequence_base<nview<Sequence, Indicies> > 95 { 96 typedef nview_tag fusion_tag; 97 typedef fusion_sequence_tag tag; // this gets picked up by MPL 98 typedef random_access_traversal_tag category; 99 100 typedef mpl::true_ is_view; 101 typedef Indicies index_type; 102 typedef typename mpl::size<Indicies>::type size; 103 104 typedef typename mpl::if_< 105 is_const<Sequence>, detail::addconstref, detail::addref 106 >::type transform_type; 107 typedef transform_view<Sequence, transform_type> transform_view_type; 108 typedef typename result_of::as_vector<transform_view_type>::type 109 sequence_type; 110 111 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED nviewboost::fusion::nview112 explicit nview(Sequence& val) 113 : seq(sequence_type(transform_view_type(val, transform_type()))) 114 {} 115 116 sequence_type seq; 117 }; 118 119 }} 120 121 // define the nview() generator functions 122 #include <boost/fusion/view/nview/detail/nview_impl.hpp> 123 124 #endif 125 126 127