make_vector.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  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. #include <boost/version.hpp>
  7. // This is the same as the one in fusion in Boost 1.41. This is provided
  8. // for compatibility with Boost 1.40 and below.
  9. #if (BOOST_VERSION > 104000)
  10. #include <boost/fusion/include/make_vector.hpp>
  11. namespace boost { namespace spirit { namespace detail
  12. {
  13. namespace result_of
  14. {
  15. using fusion::result_of::make_vector;
  16. }
  17. using fusion::make_vector;
  18. }}}
  19. #else
  20. #ifndef BOOST_PP_IS_ITERATING
  21. #if !defined(SPIRIT_MAKE_VECTOR_07162005_0243)
  22. #define SPIRIT_MAKE_VECTOR_07162005_0243
  23. #include <boost/preprocessor/iterate.hpp>
  24. #include <boost/preprocessor/repetition/enum_params.hpp>
  25. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  26. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  27. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  28. #include <boost/fusion/container/vector/vector.hpp>
  29. #include <boost/fusion/support/detail/as_fusion_element.hpp>
  30. namespace boost { namespace fusion
  31. {
  32. struct void_;
  33. }}
  34. namespace boost { namespace spirit { namespace detail
  35. {
  36. namespace result_of
  37. {
  38. template <
  39. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
  40. FUSION_MAX_VECTOR_SIZE, typename T, fusion::void_)
  41. , typename Extra = fusion::void_
  42. >
  43. struct make_vector;
  44. template <>
  45. struct make_vector<>
  46. {
  47. typedef fusion::vector0 type;
  48. };
  49. }
  50. inline fusion::vector0
  51. make_vector()
  52. {
  53. return fusion::vector0();
  54. }
  55. #define BOOST_FUSION_AS_FUSION_ELEMENT(z, n, data) \
  56. typename fusion::detail::as_fusion_element<BOOST_PP_CAT(T, n)>::type
  57. #define BOOST_PP_FILENAME_1 <boost/spirit/home/support/detail/make_vector.hpp>
  58. #define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_VECTOR_SIZE)
  59. #include BOOST_PP_ITERATE()
  60. #undef BOOST_FUSION_AS_FUSION_ELEMENT
  61. }}}
  62. #endif
  63. #else // defined(BOOST_PP_IS_ITERATING)
  64. ///////////////////////////////////////////////////////////////////////////////
  65. //
  66. // Preprocessor vertical repetition code
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. #define N BOOST_PP_ITERATION()
  70. namespace result_of
  71. {
  72. template <BOOST_PP_ENUM_PARAMS(N, typename T)>
  73. #if defined(BOOST_NO_PARTIAL_SPECIALIZATION_IMPLICIT_DEFAULT_ARGS)
  74. #define TEXT(z, n, text) , text
  75. struct make_vector< BOOST_PP_ENUM_PARAMS(N, T) BOOST_PP_REPEAT_FROM_TO(BOOST_PP_DEC(N), FUSION_MAX_VECTOR_SIZE, TEXT, fusion::void_) >
  76. #undef TEXT
  77. #else
  78. struct make_vector<BOOST_PP_ENUM_PARAMS(N, T)>
  79. #endif
  80. {
  81. typedef BOOST_PP_CAT(fusion::vector, N)<BOOST_PP_ENUM(N, BOOST_FUSION_AS_FUSION_ELEMENT, _)> type;
  82. };
  83. }
  84. template <BOOST_PP_ENUM_PARAMS(N, typename T)>
  85. inline BOOST_PP_CAT(fusion::vector, N)<BOOST_PP_ENUM(N, BOOST_FUSION_AS_FUSION_ELEMENT, _)>
  86. make_vector(BOOST_PP_ENUM_BINARY_PARAMS(N, T, const& _))
  87. {
  88. return BOOST_PP_CAT(fusion::vector, N)<BOOST_PP_ENUM(N, BOOST_FUSION_AS_FUSION_ELEMENT, _)>(
  89. BOOST_PP_ENUM_PARAMS(N, _));
  90. }
  91. #undef N
  92. #endif // defined(BOOST_PP_IS_ITERATING)
  93. #endif // (BOOST_VERSION > 103800)