assert_is_identifier.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // (C) Copyright Edward Diener 2011-2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_ASSERT_IS_IDENTIFIER_HPP)
  6. #define BOOST_VMD_ASSERT_IS_IDENTIFIER_HPP
  7. #include <boost/vmd/detail/setup.hpp>
  8. #if BOOST_PP_VARIADICS
  9. /*
  10. The succeeding comments in this file are in doxygen format.
  11. */
  12. /** \file
  13. */
  14. /** \def BOOST_VMD_ASSERT_IS_IDENTIFIER(...)
  15. \brief Asserts that the sequence is an identifier.
  16. The macro checks that the sequence is an identifier.
  17. If it is not an identifier, it forces a compiler error.
  18. The macro normally checks for an identifier only in
  19. debug mode. However an end-user can force the macro
  20. to check or not check by defining the macro
  21. BOOST_VMD_ASSERT_DATA to 1 or 0 respectively.
  22. ... = variadic parameters
  23. The variadic parameters are:
  24. sequence = A sequence to test as an identifier.
  25. ids (optional) = The data may take one of two forms:
  26. it is either one or more single identifiers
  27. or a single Boost PP tuple of identifiers.
  28. returns = Normally the macro returns nothing.
  29. If the sequence is an identifier, nothing is
  30. output. If optional ids are specified, for the
  31. sequence to be an identifier it must be an
  32. identifier that matches one of the optional
  33. ids.
  34. For VC++, because there is no sure way of forcing
  35. a compiler error from within a macro without producing
  36. output, if the sequence is not an identifier the
  37. macro forces a compiler error by outputting invalid C++.
  38. For all other compilers a compiler error is forced
  39. without producing output if the sequence is not an
  40. identifier.
  41. Identifiers are registered in VMD with:
  42. #define BOOST_VMD_REG_XXX (XXX) where XXX is a v-identifier.
  43. The identifier must be registered to be found.
  44. Identifiers are pre-detected in VMD with:
  45. #define BOOST_VMD_DETECT_XXX_XXX where XXX is an identifier.
  46. If you specify optional ids and have not specified the detection
  47. of an optional id, that id will never match an identifier.
  48. */
  49. /** \def BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...)
  50. \brief Asserts that the sequence is an identifier. Re-entrant version.
  51. The macro checks that the sequence is an identifier.
  52. If it is not an identifier, it forces a compiler error.
  53. The macro normally checks for an identifier only in
  54. debug mode. However an end-user can force the macro
  55. to check or not check by defining the macro
  56. BOOST_VMD_ASSERT_DATA to 1 or 0 respectively.
  57. d = The next available BOOST_PP_WHILE iteration.
  58. ... = variadic parameters
  59. The variadic parameters are:
  60. sequence = A sequence to test as an identifier.
  61. ids (optional) = The data may take one of two forms:
  62. it is either one or more single identifiers
  63. or a single Boost PP tuple of identifiers.
  64. returns = Normally the macro returns nothing.
  65. If the sequence is an identifier, nothing is
  66. output. If optional ids are specified, for the
  67. sequence to be an identifier it must be an
  68. identifier that matches one of the optional
  69. ids.
  70. For VC++, because there is no sure way of forcing
  71. a compiler error from within a macro without producing
  72. output, if the sequence is not an identifier the
  73. macro forces a compiler error by outputting invalid C++.
  74. For all other compilers a compiler error is forced
  75. without producing output if the sequence is not an
  76. identifier.
  77. Identifiers are registered in VMD with:
  78. #define BOOST_VMD_REG_XXX (XXX) where XXX is a v-identifier.
  79. The identifier must be registered to be found.
  80. Identifiers are pre-detected in VMD with:
  81. #define BOOST_VMD_DETECT_XXX_XXX where XXX is an identifier.
  82. If you specify optional ids and have not specified the detection
  83. of an optional id, that id will never match an identifier.
  84. */
  85. #if !BOOST_VMD_ASSERT_DATA
  86. #define BOOST_VMD_ASSERT_IS_IDENTIFIER(...)
  87. #define BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...)
  88. #else
  89. #include <boost/vmd/assert.hpp>
  90. #include <boost/vmd/is_identifier.hpp>
  91. #define BOOST_VMD_ASSERT_IS_IDENTIFIER(...) \
  92. BOOST_VMD_ASSERT \
  93. ( \
  94. BOOST_VMD_IS_IDENTIFIER(__VA_ARGS__), \
  95. BOOST_VMD_IDENTIFIER_ASSERT_ERROR \
  96. ) \
  97. /**/
  98. #define BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...) \
  99. BOOST_VMD_ASSERT \
  100. ( \
  101. BOOST_VMD_IS_IDENTIFIER_D(d,__VA_ARGS__), \
  102. BOOST_VMD_IDENTIFIER_ASSERT_ERROR \
  103. ) \
  104. /**/
  105. #endif // !BOOST_VMD_ASSERT_DATA
  106. #endif /* BOOST_PP_VARIADICS */
  107. #endif /* BOOST_VMD_ASSERT_IS_IDENTIFIER_HPP */