sequence_apply.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef BOOST_METAPARSE_V1_SEQUENCE_APPLY_HPP
  2. #define BOOST_METAPARSE_V1_SEQUENCE_APPLY_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/letter.hpp>
  8. #include <boost/metaparse/v1/sequence.hpp>
  9. #include <boost/metaparse/limit_sequence_size.hpp>
  10. #include <boost/mpl/at.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  13. #include <boost/preprocessor/repetition/enum.hpp>
  14. #include <boost/preprocessor/repetition/enum_params.hpp>
  15. #include <boost/preprocessor/tuple/eat.hpp>
  16. namespace boost
  17. {
  18. namespace metaparse
  19. {
  20. namespace v1
  21. {
  22. #ifdef BOOST_METAPARSE_SEQUENCE_APPLY_ARG
  23. # error BOOST_METAPARSE_SEQUENCE_APPLY_ARG already defined
  24. #endif
  25. #define BOOST_METAPARSE_SEQUENCE_APPLY_ARG(z, n, container) \
  26. typename boost::mpl::at_c<container, n>::type
  27. #ifdef BOOST_METAPARSE_SEQUENCE_APPLY
  28. # error BOOST_METAPARSE_SEQUENCE_APPLY already defined
  29. #endif
  30. #define BOOST_METAPARSE_SEQUENCE_APPLY(z, n, unused) \
  31. namespace impl \
  32. { \
  33. template < \
  34. template <BOOST_PP_ENUM(n, class BOOST_PP_TUPLE_EAT(3), ~)> class T \
  35. > \
  36. struct BOOST_PP_CAT(sequence_apply_transform, n) \
  37. { \
  38. typedef BOOST_PP_CAT(sequence_apply_transform, n) type; \
  39. \
  40. template <class V> \
  41. struct apply \
  42. { \
  43. typedef T<BOOST_PP_ENUM(n, BOOST_METAPARSE_SEQUENCE_APPLY_ARG, V)> type; \
  44. }; \
  45. }; \
  46. } \
  47. \
  48. template < \
  49. template <BOOST_PP_ENUM(n, class BOOST_PP_TUPLE_EAT(3), ~)> class T, \
  50. BOOST_PP_ENUM_PARAMS(n, class P) \
  51. > \
  52. struct BOOST_PP_CAT(sequence_apply, n) : \
  53. transform< \
  54. sequence<BOOST_PP_ENUM_PARAMS(n, P)>, \
  55. BOOST_PP_CAT(impl::sequence_apply_transform, n)<T> \
  56. > \
  57. {};
  58. BOOST_PP_REPEAT_FROM_TO(
  59. 1,
  60. BOOST_METAPARSE_LIMIT_SEQUENCE_SIZE,
  61. BOOST_METAPARSE_SEQUENCE_APPLY,
  62. ~
  63. )
  64. #undef BOOST_METAPARSE_SEQUENCE_APPLY
  65. #undef BOOST_METAPARSE_SEQUENCE_APPLY_ARG
  66. }
  67. }
  68. }
  69. #endif