catch_builtin.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 lists and BOOST_PP_LIST_FOR_EACH(). */
  15. #
  16. # include <iostream>
  17. # include <typeinfo>
  18. #
  19. # include <boost/preprocessor/list/for_each.hpp>
  20. # include <boost/preprocessor/tuple/to_list.hpp>
  21. #
  22. # /* List of built-in types. (Strictly speaking wchar_t should be on the list.) */
  23. #
  24. # define BUILTIN_TYPES \
  25. BOOST_PP_TUPLE_TO_LIST( \
  26. 13, \
  27. ( \
  28. bool, \
  29. char, signed char, unsigned char, \
  30. unsigned short, short, \
  31. int, unsigned, \
  32. long, unsigned long, \
  33. float, \
  34. double, long double \
  35. ) \
  36. ) \
  37. /**/
  38. #
  39. # define CATCH(R, _, T) \
  40. catch (T t) { \
  41. std::cerr << "Caught an " << typeid(t).name() << " = " << t; \
  42. } \
  43. /**/
  44. int main() {
  45. try {
  46. throw 10;
  47. }
  48. BOOST_PP_LIST_FOR_EACH(CATCH, _, BUILTIN_TYPES)
  49. return 0;
  50. }