to_array.hpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # /* **************************************************************************
  2. # * *
  3. # * (C) Copyright Paul Mensonides 2011.
  4. # * (C) Copyright Edward Diener 2011,2014.
  5. # * Distributed under the Boost Software License, Version 1.0. (See
  6. # * accompanying file LICENSE_1_0.txt or copy at
  7. # * http://www.boost.org/LICENSE_1_0.txt)
  8. # * *
  9. # ************************************************************************** */
  10. #
  11. # /* See http://www.boost.org for most recent version. */
  12. #
  13. # ifndef BOOST_PREPROCESSOR_LIST_TO_ARRAY_HPP
  14. # define BOOST_PREPROCESSOR_LIST_TO_ARRAY_HPP
  15. #
  16. # include <boost/preprocessor/arithmetic/dec.hpp>
  17. # include <boost/preprocessor/arithmetic/inc.hpp>
  18. # include <boost/preprocessor/config/config.hpp>
  19. # include <boost/preprocessor/control/while.hpp>
  20. # include <boost/preprocessor/list/adt.hpp>
  21. # include <boost/preprocessor/tuple/elem.hpp>
  22. # include <boost/preprocessor/tuple/rem.hpp>
  23. # if BOOST_PP_VARIADICS_MSVC && (_MSC_VER <= 1400)
  24. # include <boost/preprocessor/control/iif.hpp>
  25. # endif
  26. #
  27. # /* BOOST_PP_LIST_TO_ARRAY */
  28. #
  29. # if BOOST_PP_VARIADICS_MSVC && (_MSC_VER <= 1400)
  30. # define BOOST_PP_LIST_TO_ARRAY(list) \
  31. BOOST_PP_IIF \
  32. ( \
  33. BOOST_PP_LIST_IS_NIL(list), \
  34. BOOST_PP_LIST_TO_ARRAY_VC8ORLESS_EMPTY, \
  35. BOOST_PP_LIST_TO_ARRAY_VC8ORLESS_DO \
  36. ) \
  37. (list) \
  38. /**/
  39. # define BOOST_PP_LIST_TO_ARRAY_VC8ORLESS_EMPTY(list) (0,())
  40. # define BOOST_PP_LIST_TO_ARRAY_VC8ORLESS_DO(list) BOOST_PP_LIST_TO_ARRAY_I(BOOST_PP_WHILE, list)
  41. # else
  42. # define BOOST_PP_LIST_TO_ARRAY(list) BOOST_PP_LIST_TO_ARRAY_I(BOOST_PP_WHILE, list)
  43. # endif
  44. # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MSVC()
  45. # define BOOST_PP_LIST_TO_ARRAY_I(w, list) \
  46. BOOST_PP_LIST_TO_ARRAY_II(((BOOST_PP_TUPLE_REM_CTOR( \
  47. 3, \
  48. w(BOOST_PP_LIST_TO_ARRAY_P, BOOST_PP_LIST_TO_ARRAY_O, (list, 1, (~))) \
  49. )))) \
  50. /**/
  51. # define BOOST_PP_LIST_TO_ARRAY_II(p) BOOST_PP_LIST_TO_ARRAY_II_B(p)
  52. # define BOOST_PP_LIST_TO_ARRAY_II_B(p) BOOST_PP_LIST_TO_ARRAY_II_C ## p
  53. # define BOOST_PP_LIST_TO_ARRAY_II_C(p) BOOST_PP_LIST_TO_ARRAY_III p
  54. # else
  55. # define BOOST_PP_LIST_TO_ARRAY_I(w, list) \
  56. BOOST_PP_LIST_TO_ARRAY_II(BOOST_PP_TUPLE_REM_CTOR( \
  57. 3, \
  58. w(BOOST_PP_LIST_TO_ARRAY_P, BOOST_PP_LIST_TO_ARRAY_O, (list, 1, (~))) \
  59. )) \
  60. /**/
  61. # define BOOST_PP_LIST_TO_ARRAY_II(im) BOOST_PP_LIST_TO_ARRAY_III(im)
  62. # endif
  63. # define BOOST_PP_LIST_TO_ARRAY_III(list, size, tuple) (BOOST_PP_DEC(size), BOOST_PP_LIST_TO_ARRAY_IV tuple)
  64. # define BOOST_PP_LIST_TO_ARRAY_IV(_, ...) (__VA_ARGS__)
  65. # define BOOST_PP_LIST_TO_ARRAY_P(d, state) BOOST_PP_LIST_IS_CONS(BOOST_PP_TUPLE_ELEM(3, 0, state))
  66. # define BOOST_PP_LIST_TO_ARRAY_O(d, state) BOOST_PP_LIST_TO_ARRAY_O_I state
  67. # define BOOST_PP_LIST_TO_ARRAY_O_I(list, size, tuple) (BOOST_PP_LIST_REST(list), BOOST_PP_INC(size), (BOOST_PP_TUPLE_REM(size) tuple, BOOST_PP_LIST_FIRST(list)))
  68. #
  69. # /* BOOST_PP_LIST_TO_ARRAY_D */
  70. #
  71. # if BOOST_PP_VARIADICS_MSVC && (_MSC_VER <= 1400)
  72. # define BOOST_PP_LIST_TO_ARRAY_D(d, list) \
  73. BOOST_PP_IIF \
  74. ( \
  75. BOOST_PP_LIST_IS_NIL(list), \
  76. BOOST_PP_LIST_TO_ARRAY_D_VC8ORLESS_EMPTY, \
  77. BOOST_PP_LIST_TO_ARRAY_D_VC8ORLESS_DO \
  78. ) \
  79. (d, list) \
  80. /**/
  81. # define BOOST_PP_LIST_TO_ARRAY_D_VC8ORLESS_EMPTY(d, list) (0,())
  82. # define BOOST_PP_LIST_TO_ARRAY_D_VC8ORLESS_DO(d, list) BOOST_PP_LIST_TO_ARRAY_I(BOOST_PP_WHILE_ ## d, list)
  83. # else
  84. # define BOOST_PP_LIST_TO_ARRAY_D(d, list) BOOST_PP_LIST_TO_ARRAY_I(BOOST_PP_WHILE_ ## d, list)
  85. # endif
  86. #
  87. # endif /* BOOST_PREPROCESSOR_LIST_TO_ARRAY_HPP */