max_bases.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2008-2018 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  3. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  4. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  5. // Test with max possible number of bases.
  6. #include <boost/contract/public_function.hpp>
  7. #include <boost/contract/base_types.hpp>
  8. #include <boost/contract/check.hpp>
  9. #include <boost/contract/override.hpp>
  10. #include <boost/preprocessor/repetition/repeat.hpp>
  11. #include <boost/preprocessor/repetition/enum.hpp>
  12. #include <boost/preprocessor/cat.hpp>
  13. // Limited by max size of current impl of Boost.MPL vector.
  14. #ifndef BOOST_CONTRACT_TEST_CONFIG_MAX_BASES
  15. #define BOOST_CONTRACT_TEST_CONFIG_MAX_BASES 20
  16. #endif
  17. #define BOOST_CONTRACT_TEST_base_decl(z, n, unused) \
  18. struct BOOST_PP_CAT(b, n) { \
  19. virtual void f(boost::contract::virtual_* v = 0) { \
  20. boost::contract::check c = boost::contract::public_function( \
  21. v, this); \
  22. } \
  23. };
  24. BOOST_PP_REPEAT(BOOST_CONTRACT_TEST_CONFIG_MAX_BASES,
  25. BOOST_CONTRACT_TEST_base_decl, ~)
  26. #define BOOST_CONTRACT_TEST_public_base(z, n, unused) public BOOST_PP_CAT(b, n)
  27. struct a
  28. #define BASES \
  29. BOOST_PP_ENUM(BOOST_CONTRACT_TEST_CONFIG_MAX_BASES, \
  30. BOOST_CONTRACT_TEST_public_base, ~)
  31. : BASES
  32. {
  33. typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
  34. #undef BASES
  35. void f(boost::contract::virtual_* v = 0) /* override */ {
  36. boost::contract::check c = boost::contract::public_function<override_f>(
  37. v, &a::f, this);
  38. }
  39. BOOST_CONTRACT_OVERRIDE(f)
  40. };
  41. int main() {
  42. a aa;
  43. aa.f();
  44. return 0;
  45. }
  46. #undef BOOST_CONTRACT_TEST_base_decl
  47. #undef BOOST_CONTRACT_TEST_public_base