defaults.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #ifndef BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_HPP_
  7. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_HPP_
  8. #include <boost/local_function/detail/preprocessor/keyword/const_bind.hpp>
  9. #include <boost/local_function/detail/preprocessor/keyword/bind.hpp>
  10. #include <boost/local_function/detail/preprocessor/keyword/default.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/preprocessor/control/while.hpp>
  13. #include <boost/preprocessor/control/iif.hpp>
  14. #include <boost/preprocessor/control/if.hpp>
  15. #include <boost/preprocessor/facilities/expand.hpp>
  16. #include <boost/preprocessor/facilities/empty.hpp>
  17. #include <boost/preprocessor/facilities/is_empty.hpp>
  18. #include <boost/preprocessor/logical/bitand.hpp>
  19. #include <boost/preprocessor/logical/bitor.hpp>
  20. #include <boost/preprocessor/logical/not.hpp>
  21. #include <boost/preprocessor/comparison/less.hpp>
  22. #include <boost/preprocessor/arithmetic/inc.hpp>
  23. #include <boost/preprocessor/arithmetic/dec.hpp>
  24. #include <boost/preprocessor/tuple/eat.hpp>
  25. #include <boost/preprocessor/tuple/elem.hpp>
  26. #include <boost/preprocessor/list/size.hpp>
  27. #include <boost/preprocessor/list/at.hpp>
  28. // PRIVATE //
  29. #define \
  30. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_IS_UNBIND_( \
  31. sign) \
  32. /* PP_OR/PP_BITOR (instead of IIF) don't expand on MSVC */ \
  33. BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_IS_DEFAULT_FRONT(sign),\
  34. 0 \
  35. , BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_IS_CONST_BIND_FRONT( \
  36. sign), \
  37. 0 \
  38. , BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_IS_BIND_FRONT(sign), \
  39. 0 \
  40. , \
  41. 1 \
  42. )))
  43. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PREV_( \
  44. sign, index, error) \
  45. BOOST_PP_IIF( \
  46. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_IS_UNBIND_( \
  47. BOOST_PP_LIST_AT(sign, BOOST_PP_DEC(index))), \
  48. error /* no err, fwd existing one if any */ \
  49. , \
  50. BOOST_PP_CAT(BOOST_PP_CAT(ERROR_default_value_at_element_, \
  51. BOOST_PP_INC(index)), _must_follow_an_unbound_parameter) \
  52. BOOST_PP_EMPTY /* because error might not be present */ \
  53. )
  54. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_INDEX_( \
  55. sign, index, error) \
  56. BOOST_PP_IF(index, /* can't use IIF because index can be any number */ \
  57. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PREV_ \
  58. , \
  59. ERROR_default_value_cannot_be_specified_as_the_first_element \
  60. BOOST_PP_EMPTY /* because error might not be present */ \
  61. BOOST_PP_TUPLE_EAT(3) \
  62. )(sign, index, error)
  63. // While's operation.
  64. #define \
  65. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_OP_DATA_( \
  66. sign, index, error) \
  67. ( \
  68. sign \
  69. , \
  70. BOOST_PP_INC(index) \
  71. , \
  72. BOOST_PP_IIF(BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_IS_DEFAULT_FRONT( \
  73. BOOST_PP_LIST_AT(sign, index)), \
  74. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_INDEX_ \
  75. , \
  76. error BOOST_PP_TUPLE_EAT(3) /* no err, fwd existing one if any */\
  77. )(sign, index, error) \
  78. )
  79. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_OP_(d, \
  80. sign_index_error) \
  81. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_OP_DATA_( \
  82. BOOST_PP_TUPLE_ELEM(3, 0, sign_index_error), \
  83. BOOST_PP_TUPLE_ELEM(3, 1, sign_index_error), \
  84. BOOST_PP_TUPLE_ELEM(3, 2, sign_index_error))
  85. // While predicate.
  86. #define \
  87. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PRED_DATA_( \
  88. sign, index, error) \
  89. BOOST_PP_BITAND( \
  90. BOOST_PP_IS_EMPTY(error (/* expand empty */) ) \
  91. , BOOST_PP_LESS(index, BOOST_PP_LIST_SIZE(sign)) \
  92. )
  93. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PRED_( \
  94. d, sign_index_error) \
  95. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PRED_DATA_( \
  96. BOOST_PP_TUPLE_ELEM(3, 0, sign_index_error), \
  97. BOOST_PP_TUPLE_ELEM(3, 1, sign_index_error), \
  98. BOOST_PP_TUPLE_ELEM(3, 2, sign_index_error))
  99. // PUBLIC //
  100. // Validate parameters default values: `default ...` cannot be 1st element and
  101. // it must follow an unbind param. Expand to `EMPTY` if no error, or
  102. // `ERROR_message EMPTY` if error.
  103. #define BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS(sign) \
  104. BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_WHILE( \
  105. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_PRED_, \
  106. BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_SIGN_VALIDATE_DEFAULTS_OP_,\
  107. (sign, 0, BOOST_PP_EMPTY)))
  108. #endif // #include guard