nview_impl.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #define BOOST_PP_ITERATION_PARAMS_1 \
  17. (3, (1, FUSION_MAX_VECTOR_SIZE, \
  18. "boost/fusion/view/nview/detail/nview_impl.hpp")) \
  19. /**/
  20. ///////////////////////////////////////////////////////////////////////////////
  21. namespace boost { namespace fusion { namespace result_of
  22. {
  23. template <typename Sequence
  24. , BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(FUSION_MAX_VECTOR_SIZE, int I, INT_MAX)>
  25. struct as_nview
  26. {
  27. typedef mpl::vector_c<
  28. int, BOOST_PP_ENUM_PARAMS(FUSION_MAX_VECTOR_SIZE, I)
  29. > index_type;
  30. typedef nview<Sequence, index_type> type;
  31. };
  32. }}}
  33. #include BOOST_PP_ITERATE()
  34. #endif
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // Preprocessor vertical repetition code
  37. ///////////////////////////////////////////////////////////////////////////////
  38. #else // defined(BOOST_PP_IS_ITERATING)
  39. #define N BOOST_PP_ITERATION()
  40. #if N < FUSION_MAX_VECTOR_SIZE
  41. namespace boost { namespace fusion { namespace result_of
  42. {
  43. template <typename Sequence, BOOST_PP_ENUM_PARAMS(N, int I)>
  44. struct as_nview<Sequence, BOOST_PP_ENUM_PARAMS(N, I)>
  45. {
  46. typedef mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> index_type;
  47. typedef nview<Sequence, index_type> type;
  48. };
  49. }}}
  50. #endif
  51. namespace boost { namespace fusion
  52. {
  53. template<BOOST_PP_ENUM_PARAMS(N, int I), typename Sequence>
  54. inline nview<Sequence, mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> >
  55. as_nview(Sequence& s)
  56. {
  57. typedef mpl::vector_c<int, BOOST_PP_ENUM_PARAMS(N, I)> index_type;
  58. return nview<Sequence, index_type>(s);
  59. }
  60. }}
  61. #undef N
  62. #endif