remove_typename.hpp 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //==============================================================================
  2. // Copyright 2003 - 2011 LASMEA UMR 6602 CNRS/Univ. Clermont II
  3. // Copyright 2009 - 2011 LRI UMR 8623 CNRS/Univ Paris Sud XI
  4. // Copyright 2011 Eric Niebler
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //==============================================================================
  10. #ifndef BOOST_PROTO_PREPROCESSOR_REMOVE_TYPENAME_HPP_INCLUDED
  11. #define BOOST_PROTO_PREPROCESSOR_REMOVE_TYPENAME_HPP_INCLUDED
  12. /*!
  13. * \file
  14. * \brief Defines the BOOST_PROTO_REMOVE_TYPENAME macro
  15. */
  16. #include <boost/preprocessor/cat.hpp>
  17. #include <boost/preprocessor/expand.hpp>
  18. #include <boost/preprocessor/tuple/eat.hpp>
  19. #include <boost/preprocessor/control/iif.hpp>
  20. #include <boost/preprocessor/detail/is_unary.hpp>
  21. //==============================================================================
  22. // Boost.Preprocessor author P. Mensodines confirmed on an Boost email thread
  23. // (subject ``check if a token is a keyword (was "BOOST_PP_IS_UNARY()")'')
  24. // that it is OK to used `PP_IS_UNARY()` to check if tokens match predefined
  25. // "keyword" as it is done by the macros below (even if `PP_IS_UNARY()` is
  26. // technically only part of Boost.Preprocessor private API).
  27. //==============================================================================
  28. //==============================================================================
  29. // `checking_prefix ## tokens` expand to unary (e.g., `(1)`) iff `tokens` start
  30. // with keyword to check.
  31. //==============================================================================
  32. #define BOOST_PROTO_DETAILS_KEYWORD_FACILITY_IS_FRONT(T, CHECKING_PREFIX) \
  33. BOOST_PP_IS_UNARY(BOOST_PP_CAT(CHECKING_PREFIX, T)) \
  34. /**/
  35. //==============================================================================
  36. // `is_front_macro(tokens)` is 1 iff `tokens` start with keyword to remove.
  37. // `removing_prefix ## <keyword-to-remove>` must expand to nothing.
  38. //==============================================================================
  39. #define BOOST_PROTO_DETAILS_KEYWORD_FACILITY_REMOVE_FRONT(TOKENS, IS_FRONT_MACRO, REMOVING_PREFIX) \
  40. BOOST_PP_EXPAND( /* without EXPAND doesn't expand on MSVC */ \
  41. BOOST_PP_IIF( \
  42. IS_FRONT_MACRO(TOKENS) \
  43. , BOOST_PP_CAT \
  44. , TOKENS BOOST_PP_TUPLE_EAT(2) \
  45. )(REMOVING_PREFIX, TOKENS) \
  46. ) \
  47. /**/
  48. #define BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_IS_typename (1) /* unary */
  49. #define typename_BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_IS (1) /* unary */
  50. #define BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_REMOVE_typename /* nothing */
  51. #define typename_BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_REMOVE /* nothing */
  52. #define BOOST_PROTO_DETAILS_KEYWORD_IS_TYPENAME_FRONT(TOKENS) \
  53. BOOST_PROTO_DETAILS_KEYWORD_FACILITY_IS_FRONT(TOKENS, BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_IS_) \
  54. /**/
  55. //==============================================================================
  56. /*!
  57. * \ingroup preprocessor
  58. * For any symbol \c X, this macro returns the same symbol from which a potential
  59. * leading \c typename keyword has been removed. If no typename keyword is present,
  60. * this macros evaluates to \c X itself without error.
  61. *
  62. * The original implementation of this macro is from Lorenzo Caminiti.
  63. *
  64. * \param X Symbol to remove \c typename from
  65. */
  66. //==============================================================================
  67. #define BOOST_PROTO_REMOVE_TYPENAME(X) \
  68. BOOST_PROTO_DETAILS_KEYWORD_FACILITY_REMOVE_FRONT( \
  69. X \
  70. , BOOST_PROTO_DETAILS_KEYWORD_IS_TYPENAME_FRONT \
  71. , BOOST_PROTO_DETAILS_KEYWORD_TYPENAME_REMOVE_ \
  72. ) \
  73. /**/
  74. #endif