lib_a_inlined.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_
  2. #define BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. #include "lib_a.hpp"
  8. #include <boost/contract.hpp> // All headers so test ODR for entire lib.
  9. #ifdef BOOST_CONTRACT_HEADER_ONLY
  10. #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE inline
  11. #else
  12. #define BOOST_CONTRACT_TEST_LIB_A_DECLINLINE /* nothing */
  13. #endif
  14. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  15. void a::static_invariant() {
  16. using boost::contract::test::detail::out;
  17. out("a::static_inv\n");
  18. }
  19. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  20. void a::invariant() const {
  21. using boost::contract::test::detail::out;
  22. out("a::inv\n");
  23. }
  24. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  25. int a::f(x_type& x) {
  26. using boost::contract::test::detail::out;
  27. int result;
  28. boost::contract::old_ptr<x_type> old_x =
  29. BOOST_CONTRACT_OLDOF(x_type::eval(x));
  30. boost::contract::check c = boost::contract::public_function(this)
  31. // Capturing [&] so out() visible in MSVC10 lambdas.
  32. .precondition([&] { out("a::f::pre\n"); })
  33. .old([&] { out("a::f::old\n"); })
  34. .postcondition([&] {
  35. out("a::f::post\n");
  36. BOOST_CONTRACT_ASSERT(x.value == -old_x->value);
  37. BOOST_CONTRACT_ASSERT(result == old_x->value);
  38. })
  39. ;
  40. out("a::f::body\n");
  41. result = x.value;
  42. x.value = -x.value;
  43. return result;
  44. }
  45. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  46. void a::disable_pre_failure() {
  47. using boost::contract::test::detail::out;
  48. boost::contract::set_precondition_failure([] (boost::contract::from)
  49. { out("a::pre_failure\n"); });
  50. }
  51. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  52. void a::disable_post_failure() {
  53. using boost::contract::test::detail::out;
  54. boost::contract::set_postcondition_failure([] (boost::contract::from)
  55. { out("a::post_failure\n"); });
  56. }
  57. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  58. void a::disable_entry_inv_failure() {
  59. using boost::contract::test::detail::out;
  60. boost::contract::set_entry_invariant_failure([] (boost::contract::from)
  61. { out("a::entry_inv_failure\n"); });
  62. }
  63. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  64. void a::disable_exit_inv_failure() {
  65. using boost::contract::test::detail::out;
  66. boost::contract::set_exit_invariant_failure([] (boost::contract::from)
  67. { out("a::exit_inv_failure\n"); });
  68. }
  69. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  70. void a::disable_inv_failure() {
  71. using boost::contract::test::detail::out;
  72. boost::contract::set_invariant_failure([] (boost::contract::from)
  73. { out("a::inv_failure\n"); });
  74. }
  75. BOOST_CONTRACT_TEST_LIB_A_DECLINLINE
  76. void a::disable_failure() {
  77. using boost::contract::test::detail::out;
  78. boost::contract::set_precondition_failure(
  79. boost::contract::set_postcondition_failure(
  80. boost::contract::set_except_failure(
  81. boost::contract::set_old_failure(
  82. boost::contract::set_invariant_failure(
  83. [] (boost::contract::from) { out("a::failure\n"); }
  84. )))));
  85. }
  86. #endif // #include guard