assert_is_identifier.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. <br/>
  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. @code
  29. returns = Normally the macro returns nothing.
  30. If the sequence is an identifier, nothing is
  31. output. If optional ids are specified, for the
  32. sequence to be an identifier it must be an
  33. identifier that matches one of the optional
  34. ids.
  35. For VC++, because there is no sure way of forcing
  36. a compiler error from within a macro without producing
  37. output, if the sequence is not an identifier the
  38. macro forces a compiler error by outputting invalid C++.
  39. For all other compilers a compiler error is forced
  40. without producing output if the sequence is not an
  41. identifier.
  42. @endcode
  43. Identifiers are registered in VMD with:
  44. @code
  45. #define BOOST_VMD_REG_XXX (XXX) where XXX is a v-identifier.
  46. @endcode
  47. The identifier must be registered to be found.
  48. Identifiers are pre-detected in VMD with:
  49. @code
  50. #define BOOST_VMD_DETECT_XXX_XXX where XXX is an identifier.
  51. @endcode
  52. If you specify optional ids and have not specified the detection
  53. of an optional id, that id will never match an identifier.
  54. */
  55. /** \def BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...)
  56. \brief Asserts that the sequence is an identifier. Re-entrant version.
  57. The macro checks that the sequence is an identifier.
  58. If it is not an identifier, it forces a compiler error.
  59. The macro normally checks for an identifier only in
  60. debug mode. However an end-user can force the macro
  61. to check or not check by defining the macro
  62. BOOST_VMD_ASSERT_DATA to 1 or 0 respectively.
  63. d = The next available BOOST_PP_WHILE iteration. <br/>
  64. ... = variadic parameters
  65. The variadic parameters are:
  66. sequence = A sequence to test as an identifier. <br/>
  67. ids (optional) = The data may take one of two forms:
  68. it is either one or more single identifiers
  69. or a single Boost PP tuple of identifiers.
  70. @code
  71. returns = Normally the macro returns nothing.
  72. If the sequence is an identifier, nothing is
  73. output. If optional ids are specified, for the
  74. sequence to be an identifier it must be an
  75. identifier that matches one of the optional
  76. ids.
  77. For VC++, because there is no sure way of forcing
  78. a compiler error from within a macro without producing
  79. output, if the sequence is not an identifier the
  80. macro forces a compiler error by outputting invalid C++.
  81. For all other compilers a compiler error is forced
  82. without producing output if the sequence is not an
  83. identifier.
  84. @endcode
  85. Identifiers are registered in VMD with:
  86. @code
  87. #define BOOST_VMD_REG_XXX (XXX) where XXX is a v-identifier.
  88. @endcode
  89. The identifier must be registered to be found.
  90. Identifiers are pre-detected in VMD with:
  91. @code
  92. #define BOOST_VMD_DETECT_XXX_XXX where XXX is an identifier.
  93. @endcode
  94. If you specify optional ids and have not specified the detection
  95. of an optional id, that id will never match an identifier.
  96. */
  97. #if !BOOST_VMD_ASSERT_DATA
  98. #define BOOST_VMD_ASSERT_IS_IDENTIFIER(...)
  99. #define BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...)
  100. #else
  101. #include <boost/vmd/assert.hpp>
  102. #include <boost/vmd/is_identifier.hpp>
  103. #define BOOST_VMD_ASSERT_IS_IDENTIFIER(...) \
  104. BOOST_VMD_ASSERT \
  105. ( \
  106. BOOST_VMD_IS_IDENTIFIER(__VA_ARGS__), \
  107. BOOST_VMD_IDENTIFIER_ASSERT_ERROR \
  108. ) \
  109. /**/
  110. #define BOOST_VMD_ASSERT_IS_IDENTIFIER_D(d,...) \
  111. BOOST_VMD_ASSERT \
  112. ( \
  113. BOOST_VMD_IS_IDENTIFIER_D(d,__VA_ARGS__), \
  114. BOOST_VMD_IDENTIFIER_ASSERT_ERROR \
  115. ) \
  116. /**/
  117. #endif // !BOOST_VMD_ASSERT_DATA
  118. #endif /* BOOST_PP_VARIADICS */
  119. #endif /* BOOST_VMD_ASSERT_IS_IDENTIFIER_HPP */