boost_no_variadic_macros.ipp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2010 Edward Diener
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_NO_CXX11_VARIADIC_MACROS
  7. // TITLE: C++0x variadic macros unavailable
  8. // DESCRIPTION: The compiler does not support C++0x variadic macros
  9. // This is a simple test
  10. #define TEST_VARIADIC_MACRO_SIMPLE(avalue,...) __VA_ARGS__
  11. /*
  12. This is a more complicated test, which Steve Watanabe graciously
  13. supplied, when I asked if it were possible to strip the parantheses
  14. from a macro argument. I have changed the names somewhat to prevent
  15. any common clashes with other macros in the config testing suite
  16. by prepending to each macro name TEST_VARIADIC_MACRO_.
  17. You may find this test overdone and may want to remove it.
  18. */
  19. #define TEST_VARIADIC_MACRO_CAT(x, y) TEST_VARIADIC_MACRO_CAT_I(x, y)
  20. #define TEST_VARIADIC_MACRO_CAT_I(x, y) x ## y
  21. #define TEST_VARIADIC_MACRO_APPLY(macro, args) TEST_VARIADIC_MACRO_APPLY_I(macro, args)
  22. #define TEST_VARIADIC_MACRO_APPLY_I(macro, args) macro args
  23. #define TEST_VARIADIC_MACRO_STRIP_PARENS(x) TEST_VARIADIC_MACRO_EVAL((TEST_VARIADIC_MACRO_STRIP_PARENS_I x), x)
  24. #define TEST_VARIADIC_MACRO_STRIP_PARENS_I(...) 1,1
  25. #define TEST_VARIADIC_MACRO_EVAL(test, x) TEST_VARIADIC_MACRO_EVAL_I(test, x)
  26. #define TEST_VARIADIC_MACRO_EVAL_I(test, x) TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS(TEST_VARIADIC_MACRO_TEST_ARITY test, x)
  27. #define TEST_VARIADIC_MACRO_TEST_ARITY(...) TEST_VARIADIC_MACRO_APPLY(TEST_VARIADIC_MACRO_TEST_ARITY_I, (__VA_ARGS__, 2, 1))
  28. #define TEST_VARIADIC_MACRO_TEST_ARITY_I(a,b,c,...) c
  29. #define TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS(cond, x) TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_I(cond, x)
  30. #define TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_I(cond, x) TEST_VARIADIC_MACRO_CAT(TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_, cond)(x)
  31. #define TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_1(x) x
  32. #define TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_2(x) TEST_VARIADIC_MACRO_APPLY(TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_2_I, x)
  33. #define TEST_VARIADIC_MACRO_MAYBE_STRIP_PARENS_2_I(...) __VA_ARGS__
  34. namespace boost_no_cxx11_variadic_macros {
  35. void quiet_warning(int){}
  36. template<TEST_VARIADIC_MACRO_STRIP_PARENS((typename T,int))> struct test_variadic_macro_class {};
  37. int test()
  38. {
  39. int x = TEST_VARIADIC_MACRO_STRIP_PARENS(3);
  40. quiet_warning(x);
  41. return 0;
  42. }
  43. }