repetition.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # /* **************************************************************************
  2. # * *
  3. # * (C) Copyright Paul Mensonides 2002.
  4. # * Distributed under the Boost Software License, Version 1.0. (See
  5. # * accompanying file LICENSE_1_0.txt or copy at
  6. # * http://www.boost.org/LICENSE_1_0.txt)
  7. # * *
  8. # ************************************************************************** */
  9. #
  10. # /* See http://www.boost.org for most recent version. */
  11. #
  12. # include <boost/preprocessor/arithmetic/inc.hpp>
  13. # include <boost/preprocessor/cat.hpp>
  14. # include <boost/preprocessor/comparison/equal.hpp>
  15. # include <boost/preprocessor/comparison/not_equal.hpp>
  16. # include <boost/preprocessor/facilities/intercept.hpp>
  17. # include <boost/preprocessor/repetition.hpp>
  18. # include <libs/preprocessor/test/test.h>
  19. # define MAX 10
  20. # define NTH(z, n, data) data ## n
  21. int add(BOOST_PP_ENUM_PARAMS(MAX, int x)) {
  22. return BOOST_PP_REPEAT(MAX, NTH, + x);
  23. }
  24. const int r = add(BOOST_PP_ENUM_PARAMS(MAX, 1 BOOST_PP_INTERCEPT));
  25. # define CONSTANT(z, n, text) BOOST_PP_CAT(text, n) = n
  26. const int BOOST_PP_ENUM(MAX, CONSTANT, default_param_);
  27. # define TEST(n) \
  28. void BOOST_PP_CAT(test_enum_params, n)(BOOST_PP_ENUM_PARAMS(n, int x)); \
  29. void BOOST_PP_CAT(test_enum_params_with_a_default, n)(BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(n, int x, 0)); \
  30. void BOOST_PP_CAT(test_enum_params_with_defaults, n)(BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(n, int x, default_param_));
  31. TEST(0)
  32. TEST(MAX)
  33. template<BOOST_PP_ENUM_PARAMS(MAX, class T)> struct no_rescan;
  34. # define F1(z, n, p) p n
  35. BEGIN 1 + (4+5+6) BOOST_PP_REPEAT_FROM_TO(4, 7, F1, -) END
  36. # define PRED(r, state) BOOST_PP_NOT_EQUAL(state, BOOST_PP_INC(MAX))
  37. # define OP(r, state) BOOST_PP_INC(state)
  38. # define MACRO(r, state) BOOST_PP_COMMA_IF(BOOST_PP_NOT_EQUAL(state, 1)) BOOST_PP_CAT(class T, state)
  39. template<BOOST_PP_FOR(1, PRED, OP, MACRO)> struct for_test;