is_integral.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # /* Copyright (C) 2002
  2. # * Housemarque Oy
  3. # * http://www.housemarque.com
  4. # *
  5. # * Distributed under the Boost Software License, Version 1.0. (See
  6. # * accompanying file LICENSE_1_0.txt or copy at
  7. # * http://www.boost.org/LICENSE_1_0.txt)
  8. # */
  9. #
  10. # /* Revised by Paul Mensonides (2002) */
  11. #
  12. # /* See http://www.boost.org for most recent version. */
  13. #
  14. # /* This example demonstrates the usage of preprocessor lists for generating C++ code. */
  15. #
  16. # include <boost/preprocessor/facilities/empty.hpp>
  17. # include <boost/preprocessor/list/at.hpp>
  18. # include <boost/preprocessor/list/for_each_product.hpp>
  19. # include <boost/preprocessor/tuple/elem.hpp>
  20. # include <boost/preprocessor/tuple/to_list.hpp>
  21. #
  22. # /* List of integral types. (Strictly speaking, wchar_t should be on the list.) */
  23. # define INTEGRAL_TYPES \
  24. BOOST_PP_TUPLE_TO_LIST( \
  25. 9, (char, signed char, unsigned char, short, unsigned short, int, unsigned, long, unsigned long) \
  26. ) \
  27. /**/
  28. #
  29. # /* List of invokeable cv-qualifiers */
  30. # define CV_QUALIFIERS \
  31. BOOST_PP_TUPLE_TO_LIST( \
  32. 4, (BOOST_PP_EMPTY, const BOOST_PP_EMPTY, volatile BOOST_PP_EMPTY, const volatile BOOST_PP_EMPTY) \
  33. ) \
  34. /**/
  35. #
  36. # /* Template for testing whether a type is an integral type. */
  37. template<class T> struct is_integral {
  38. enum { value = false };
  39. };
  40. # /* Macro for defining a specialization of is_integral<> template. */
  41. # define IS_INTEGRAL_SPECIALIZATION(R, L) \
  42. template<> struct is_integral<BOOST_PP_TUPLE_ELEM(2, 0, L)() BOOST_PP_TUPLE_ELEM(2, 1, L)> { \
  43. enum { value = true }; \
  44. }; \
  45. /**/
  46. BOOST_PP_LIST_FOR_EACH_PRODUCT(IS_INTEGRAL_SPECIALIZATION, 2, (CV_QUALIFIERS, INTEGRAL_TYPES))