nview_impl.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifndef BOOST_PP_IS_ITERATING
  7. #if !defined(BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM)
  8. #define BOOST_FUSION_NVIEW_IMPL_SEP_23_2009_1017PM
  9. #include <climits>
  10. #include <boost/preprocessor/cat.hpp>
  11. #include <boost/preprocessor/repeat.hpp>
  12. #include <boost/preprocessor/iterate.hpp>
  13. #include <boost/preprocessor/repetition/enum_params.hpp>
  14. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  15. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  16. #include <boost/mpl/vector_c.hpp>
  17. #include <boost/fusion/adapted/mpl.hpp>
  18. #include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
  19. #define BOOST_PP_ITERATION_PARAMS_1 \
  20. (3, (1, FUSION_MAX_VECTOR_SIZE, \
  21. "boost/fusion/view/nview/detail/cpp03/nview_impl.hpp")) \
  22. /**/
  23. ///////////////////////////////////////////////////////////////////////////////
  24. namespace boost { namespace fusion { namespace result_of
  25. {
  26. template <typename Sequence
  27. , BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(FUSION_MAX_VECTOR_SIZE, int I, INT_MAX)>
  28. struct as_nview
  29. {
  30. typedef mpl::vector_c<
  31. int, BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, I)
  32. > index_type;
  33. typedef nview<Sequence, index_type> type;
  34. };
  35. }}}
  36. #include BOOST_PP_ITERATE()
  37. #endif
  38. ///////////////////////////////////////////////////////////////////////////////
  39. // Preprocessor vertical repetition code
  40. ///////////////////////////////////////////////////////////////////////////////
  41. #else // defined(BOOST_PP_IS_ITERATING)
  42. #define N BOOST_PP_ITERATION()
  43. #if N < FUSION_MAX_VECTOR_SIZE
  44. namespace boost { namespace fusion { namespace result_of
  45. {
  46. template <typename Sequence, BOOST_PP_ENUM_PARAMS(N, int I)>
  47. struct as_nview<Sequence, BOOST_PP_ENUM_PARAMS(N, I)>
  48. {
  49. typedef mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> index_type;
  50. typedef nview<Sequence, index_type> type;
  51. };
  52. }}}
  53. #endif
  54. namespace boost { namespace fusion
  55. {
  56. template<BOOST_PP_ENUM_PARAMS(N, int I), typename Sequence>
  57. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  58. inline nview<Sequence, mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> >
  59. as_nview(Sequence& s)
  60. {
  61. typedef mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> index_type;
  62. return nview<Sequence, index_type>(s);
  63. }
  64. }}
  65. #undef N
  66. #endif