is.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_IS_HPP_
  7. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_HPP_
  8. // Boost.Preprocessor author P. Mensodines confirmed on an Boost email thread
  9. // (subject ``check if a token is a keyword (was "BOOST_PP_IS_UNARY()")'')
  10. // that it is OK to used `PP_IS_UNARY()` to check if tokens match predefined
  11. // "keyword" as it is done by the macros below (even if `PP_IS_UNARY()` is
  12. // technically only part of Boost.Preprocessor private API).
  13. #include <boost/preprocessor/detail/is_unary.hpp>
  14. #include <boost/preprocessor/cat.hpp>
  15. #include <boost/preprocessor/control/iif.hpp>
  16. #include <boost/preprocessor/tuple/eat.hpp>
  17. // PRIVATE //
  18. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_(a, b) \
  19. BOOST_PP_IS_UNARY(BOOST_PP_CAT(a, b))
  20. // PUBLIC //
  21. // `checking_prefix ## tokens` expand to unary (e.g., `(1)`) iff `tokens` start
  22. // with keyword to check.
  23. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_FRONT( \
  24. tokens, checking_prefix) \
  25. BOOST_PP_IIF(BOOST_PP_IS_UNARY(tokens), \
  26. /* on MSVC this check works even if tokens already unary but on */ \
  27. /* C++03 (including GCC) this check on non-unary tokens gives */ \
  28. /* a concatenation error -- so return false is tokens is not unary */ \
  29. 0 BOOST_PP_TUPLE_EAT(2) \
  30. , \
  31. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_ \
  32. )(checking_prefix, tokens)
  33. // `token ## checking_postfix` expand to unary (e.g., `(1)`) iff `token` is the
  34. // keyword to check. This check only works if `token` is a single token, it
  35. // will always expand to 0 if token is multiple tokens (e.g., `const *this`).
  36. // This check will expand to 0 with no error if `token` starts with a
  37. // non-alphanumeric symbol (e.g., `*this`).
  38. #define BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_BACK( \
  39. token, checking_postfix) \
  40. BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_FACILITY_IS_(token, checking_postfix)
  41. #endif // #include guard