remove.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_DETAIL_PP_KEYWORD_FACILITY_REMOVE_HPP_
  7. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_HPP_
  8. #include <boost/preprocessor/control/iif.hpp>
  9. #include <boost/preprocessor/tuple/eat.hpp>
  10. #include <boost/preprocessor/config/config.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. // PRIVATE //
  13. // From PP_EXPAND (my own reentrant version).
  14. #if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MWCC() && \
  15. ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_DMC()
  16. # define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_(x) \
  17. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_I_(x)
  18. #else
  19. # define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_(x) \
  20. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_OO_((x))
  21. # define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_OO_( \
  22. par) \
  23. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_I_ ## par
  24. #endif
  25. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_I_(x) x
  26. // PUBLIC //
  27. // `is_front_macro(tokens)` is 1 if `tokens` start with keyword to remove.
  28. // `removing_prefix ## <keyword-to-remove>` must expand to nothing, else 0.
  29. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_FRONT( \
  30. tokens, is_front_macro, removing_prefix) \
  31. /* without EXPAND doesn't expand on MSVC */ \
  32. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_EXPAND_( \
  33. BOOST_PP_IIF(is_front_macro(tokens), \
  34. BOOST_PP_CAT \
  35. , \
  36. tokens BOOST_PP_TUPLE_EAT(2) \
  37. )(removing_prefix, tokens) \
  38. )
  39. // `is_back_macro(tokens)` is 1 iff `tokens` end with keyword to remove.
  40. // `<keyword-to-remove> ## removing_postfix` must expand to nothing, else 0.
  41. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_REMOVE_BACK( \
  42. tokens, is_back_macro, removing_prefix) \
  43. BOOST_PP_IIF(is_back_macro(tokens), \
  44. BOOST_PP_CAT \
  45. , \
  46. tokens BOOST_PP_TUPLE_EAT(2) \
  47. )(tokens, removing_postfix)
  48. #endif // #include guard