identity.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_IDENTITY_HPP)
  6. #define BOOST_VMD_IDENTITY_HPP
  7. #include <boost/vmd/detail/setup.hpp>
  8. #if BOOST_PP_VARIADICS
  9. #if BOOST_VMD_MSVC
  10. #include <boost/preprocessor/cat.hpp>
  11. #endif
  12. #include <boost/vmd/empty.hpp>
  13. /*
  14. The succeeding comments in this file are in doxygen format.
  15. */
  16. /** \file
  17. */
  18. /** \def BOOST_VMD_IDENTITY(item)
  19. \brief Macro which expands to its argument when invoked with any number of parameters.
  20. item = any single argument
  21. When BOOST_VMD_IDENTITY(item) is subsequently invoked with any number of parameters it expands
  22. to 'item'. Subsequently invoking the macro is done as 'BOOST_VMD_IDENTITY(item)(zero_or_more_arguments)'.
  23. The macro is equivalent to the Boost PP macro BOOST_PP_IDENTITY(item) with the difference
  24. being that BOOST_PP_IDENTITY(item) is always invoked with no arguments, as in
  25. 'BOOST_VMD_IDENTITY(item)()' whereas BOOST_VMD_IDENTITY can be invoked with any number of
  26. arguments.
  27. The macro is meant to be used in BOOST_PP_IF and BOOST_PP_IIF statements when only one
  28. of the clauses needs to be invoked with calling another macro and the other is meant to
  29. return an 'item'.
  30. returns = the macro as 'BOOST_VMD_IDENTITY(item)', when invoked with any number of parameters
  31. as in '(zero_or_more_arguments)', returns 'item'. The macro itself returns
  32. 'item BOOST_VMD_EMPTY'.
  33. */
  34. #define BOOST_VMD_IDENTITY(item) item BOOST_VMD_EMPTY
  35. /** \def BOOST_VMD_IDENTITY_RESULT(result)
  36. \brief Macro which wraps any result which can return its value using BOOST_VMD_IDENTITY or 'item BOOST_VMD_EMPTY'.
  37. result = any single result returned when BOOST_VMD_IDENTITY is used or 'item BOOST_VMD_EMPTY'.
  38. The reason for this macro is to smooth over a problem when using VC++ with BOOST_VMD_IDENTITY.
  39. If your BOOST_VMD_IDENTITY macro can be used where VC++ is the compiler then you need to
  40. surround your macro code which could return a result with this macro in order that VC++ handles
  41. BOOST_VMD_IDENTITY correctly.
  42. If you are not using VC++ you do not have to use this macro, but doing so does no harm.
  43. */
  44. #if BOOST_VMD_MSVC
  45. #define BOOST_VMD_IDENTITY_RESULT(result) BOOST_PP_CAT(result,)
  46. #else
  47. #define BOOST_VMD_IDENTITY_RESULT(result) result
  48. #endif
  49. #endif /* BOOST_PP_VARIADICS */
  50. #endif /* BOOST_VMD_IDENTITY_HPP */