nview.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*=============================================================================
  2. Copyright (c) 2009 Hartmut Kaiser
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_FUSION_NVIEW_SEP_23_2009_0948PM)
  7. #define BOOST_FUSION_NVIEW_SEP_23_2009_0948PM
  8. #include <boost/fusion/support/config.hpp>
  9. #include <boost/mpl/if.hpp>
  10. #include <boost/type_traits/add_reference.hpp>
  11. #include <boost/type_traits/add_const.hpp>
  12. #include <boost/fusion/support/is_view.hpp>
  13. #include <boost/fusion/support/sequence_base.hpp>
  14. #include <boost/fusion/container/vector.hpp>
  15. #include <boost/fusion/sequence/intrinsic/size.hpp>
  16. #include <boost/fusion/view/transform_view.hpp>
  17. #include <boost/config.hpp>
  18. namespace boost { namespace fusion
  19. {
  20. namespace detail
  21. {
  22. struct addref
  23. {
  24. template<typename Sig>
  25. struct result;
  26. template<typename U>
  27. struct result<addref(U)> : add_reference<U> {};
  28. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  29. template <typename T>
  30. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  31. typename add_reference<T>::type
  32. operator()(T& x) const
  33. {
  34. return x;
  35. }
  36. #else
  37. template <typename T>
  38. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  39. typename result<addref(T)>::type
  40. operator()(T&& x) const
  41. {
  42. return x;
  43. }
  44. #endif
  45. };
  46. struct addconstref
  47. {
  48. template<typename Sig>
  49. struct result;
  50. template<typename U>
  51. struct result<addconstref(U)>
  52. : add_reference<typename add_const<U>::type>
  53. {};
  54. template <typename T>
  55. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  56. typename add_reference<typename add_const<T>::type>::type
  57. operator()(T& x) const
  58. {
  59. return x;
  60. }
  61. template <typename T>
  62. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  63. typename add_reference<typename add_const<T>::type>::type
  64. operator()(T const& x) const
  65. {
  66. return x;
  67. }
  68. };
  69. }
  70. struct nview_tag;
  71. struct random_access_traversal_tag;
  72. struct fusion_sequence_tag;
  73. template<typename Sequence, typename Indicies>
  74. struct nview
  75. : sequence_base<nview<Sequence, Indicies> >
  76. {
  77. typedef nview_tag fusion_tag;
  78. typedef fusion_sequence_tag tag; // this gets picked up by MPL
  79. typedef random_access_traversal_tag category;
  80. typedef mpl::true_ is_view;
  81. typedef Indicies index_type;
  82. typedef typename result_of::size<Indicies>::type size;
  83. typedef typename mpl::if_<
  84. is_const<Sequence>, detail::addconstref, detail::addref
  85. >::type transform_type;
  86. typedef transform_view<Sequence, transform_type> transform_view_type;
  87. typedef typename result_of::as_vector<transform_view_type>::type
  88. sequence_type;
  89. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  90. explicit nview(Sequence& val)
  91. : seq(sequence_type(transform_view_type(val, transform_type())))
  92. {}
  93. sequence_type seq;
  94. };
  95. }}
  96. // define the nview() generator functions
  97. #include <boost/fusion/view/nview/detail/nview_impl.hpp>
  98. #endif