From 914e7bdcec96725065c19e36d5863224acc88122 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Mon, 4 Sep 2017 16:30:13 -0700 Subject: [PATCH] cleaning master to prep for release tags --- COPYRIGHT.txt | 4 - Jamroot | 110 -- LICENSE_1_0.txt | 23 - README.txt | 19 - boost.png | Bin 6308 -> 0 bytes build/Jamfile.v2 | 10 - build/boost_contract_no.jam | 141 --- build/boost_contract_no.jam-gen.py | 41 - doc/Jamfile.v2 | 63 -- doc/acknowledgments.qbk | 30 - doc/advanced.qbk | 484 --------- doc/bibliography.qbk | 112 -- doc/contract_programming_overview.qbk | 679 ------------ doc/examples.qbk | 172 ---- doc/extras.qbk | 612 ----------- doc/full_table_of_contents.qbk | 75 -- doc/getting_started.qbk | 214 ---- doc/introduction.qbk | 80 -- doc/main.qbk | 155 --- doc/release_notes.qbk | 171 ---- doc/src/boost.xml | 105 -- doc/src/boostbook.css | 700 ------------- doc/src/docutils.css | 275 ----- doc/src/images/alert.png | Bin 603 -> 0 bytes doc/src/images/blank.png | Bin 374 -> 0 bytes doc/src/images/callouts/1.png | Bin 391 -> 0 bytes doc/src/images/callouts/1.svg | 15 - doc/src/images/callouts/10.png | Bin 485 -> 0 bytes doc/src/images/callouts/10.svg | 18 - doc/src/images/callouts/11.png | Bin 410 -> 0 bytes doc/src/images/callouts/11.svg | 16 - doc/src/images/callouts/12.png | Bin 488 -> 0 bytes doc/src/images/callouts/12.svg | 18 - doc/src/images/callouts/13.png | Bin 509 -> 0 bytes doc/src/images/callouts/13.svg | 20 - doc/src/images/callouts/14.png | Bin 499 -> 0 bytes doc/src/images/callouts/14.svg | 17 - doc/src/images/callouts/15.png | Bin 507 -> 0 bytes doc/src/images/callouts/15.svg | 19 - doc/src/images/callouts/16.svg | 20 - doc/src/images/callouts/17.svg | 17 - doc/src/images/callouts/18.svg | 21 - doc/src/images/callouts/19.svg | 20 - doc/src/images/callouts/2.png | Bin 446 -> 0 bytes doc/src/images/callouts/2.svg | 17 - doc/src/images/callouts/20.svg | 20 - doc/src/images/callouts/21.svg | 18 - doc/src/images/callouts/22.svg | 20 - doc/src/images/callouts/23.svg | 22 - doc/src/images/callouts/24.svg | 19 - doc/src/images/callouts/25.svg | 21 - doc/src/images/callouts/26.svg | 22 - doc/src/images/callouts/27.svg | 19 - doc/src/images/callouts/28.svg | 23 - doc/src/images/callouts/29.svg | 22 - doc/src/images/callouts/3.png | Bin 431 -> 0 bytes doc/src/images/callouts/3.svg | 19 - doc/src/images/callouts/30.svg | 22 - doc/src/images/callouts/4.png | Bin 441 -> 0 bytes doc/src/images/callouts/4.svg | 16 - doc/src/images/callouts/5.png | Bin 423 -> 0 bytes doc/src/images/callouts/5.svg | 18 - doc/src/images/callouts/6.png | Bin 431 -> 0 bytes doc/src/images/callouts/6.svg | 19 - doc/src/images/callouts/7.png | Bin 397 -> 0 bytes doc/src/images/callouts/7.svg | 16 - doc/src/images/callouts/8.png | Bin 434 -> 0 bytes doc/src/images/callouts/8.svg | 20 - doc/src/images/callouts/9.png | Bin 420 -> 0 bytes doc/src/images/callouts/9.svg | 19 - doc/src/images/caution.png | Bin 1250 -> 0 bytes doc/src/images/caution.svg | 68 -- doc/src/images/draft.png | Bin 17454 -> 0 bytes doc/src/images/home.png | Bin 358 -> 0 bytes doc/src/images/home.svg | 26 - doc/src/images/important.png | Bin 722 -> 0 bytes doc/src/images/important.svg | 25 - doc/src/images/next.png | Bin 336 -> 0 bytes doc/src/images/next.svg | 19 - doc/src/images/next_disabled.png | Bin 1110 -> 0 bytes doc/src/images/note.png | Bin 490 -> 0 bytes doc/src/images/note.svg | 33 - doc/src/images/prev.png | Bin 334 -> 0 bytes doc/src/images/prev.svg | 19 - doc/src/images/prev_disabled.png | Bin 1109 -> 0 bytes doc/src/images/smiley.png | Bin 867 -> 0 bytes doc/src/images/tip.png | Bin 449 -> 0 bytes doc/src/images/tip.svg | 84 -- doc/src/images/toc-blank.png | Bin 318 -> 0 bytes doc/src/images/toc-minus.png | Bin 259 -> 0 bytes doc/src/images/toc-plus.png | Bin 264 -> 0 bytes doc/src/images/up.png | Bin 370 -> 0 bytes doc/src/images/up.svg | 19 - doc/src/images/up_disabled.png | Bin 1115 -> 0 bytes doc/src/images/warning.png | Bin 1241 -> 0 bytes doc/src/images/warning.svg | 23 - doc/src/minimal.css | 22 - doc/src/reference.css | 11 - doc/tutorial.qbk | 848 --------------- example/Jamfile.v2 | 85 -- example/cline90/calendar.cpp | 93 -- example/cline90/stack.cpp | 92 -- example/cline90/vector.hpp | 100 -- example/cline90/vector_axx.hpp | 100 -- example/cline90/vector_main.cpp | 23 - example/cline90/vstack.cpp | 237 ----- example/features/access.cpp | 97 -- example/features/assertion_level.cpp | 135 --- example/features/base_types.cpp | 188 ---- example/features/base_types_no_macro.cpp | 188 ---- example/features/call_if_cxx14.cpp | 101 -- example/features/check.cpp | 46 - example/features/code_block.cpp | 41 - example/features/condition_if.cpp | 58 -- example/features/friend.cpp | 67 -- example/features/friend_invariant.cpp | 59 -- example/features/ifdef.cpp | 213 ---- example/features/ifdef_macro.cpp | 149 --- example/features/introduction.cpp | 34 - example/features/introduction_comments.cpp | 24 - example/features/introduction_public.cpp | 89 -- example/features/lambda.cpp | 43 - example/features/loop.cpp | 40 - example/features/move.cpp | 201 ---- example/features/named_override.cpp | 104 -- example/features/no_lambdas.cpp | 84 -- example/features/no_lambdas.hpp | 74 -- example/features/no_lambdas_local_func.cpp | 113 -- example/features/non_member.cpp | 40 - example/features/old.cpp | 41 - example/features/old_if_copyable.cpp | 133 --- example/features/old_no_macro.cpp | 46 - example/features/optional_result.cpp | 41 - example/features/optional_result_virtual.cpp | 88 -- example/features/overload.cpp | 202 ---- example/features/private_protected.cpp | 77 -- .../features/private_protected_virtual.cpp | 145 --- .../private_protected_virtual_multi.cpp | 209 ---- example/features/public.cpp | 183 ---- example/features/pure_virtual_public.cpp | 89 -- example/features/separate_body.cpp | 38 - example/features/separate_body.hpp | 78 -- example/features/static_public.cpp | 69 -- example/features/throw_on_failure.cpp | 141 --- example/features/union.cpp | 136 --- example/features/volatile.cpp | 102 -- example/meyer97/stack3.cpp | 192 ---- example/meyer97/stack4.e | 201 ---- example/meyer97/stack4.hpp | 201 ---- example/meyer97/stack4_main.cpp | 30 - example/mitchell02/counter/counter.hpp | 70 -- .../mitchell02/counter/decrement_button.hpp | 92 -- example/mitchell02/counter/push_button.hpp | 86 -- example/mitchell02/counter_main.cpp | 79 -- example/mitchell02/courier.cpp | 204 ---- example/mitchell02/customer_manager.cpp | 137 --- example/mitchell02/dictionary.cpp | 128 --- example/mitchell02/name_list.cpp | 143 --- example/mitchell02/observer/observer.hpp | 59 -- example/mitchell02/observer/subject.hpp | 165 --- example/mitchell02/observer_main.cpp | 115 --- example/mitchell02/simple_queue.cpp | 219 ---- example/mitchell02/stack.cpp | 138 --- example/n1962/circle.cpp | 78 -- example/n1962/equal.cpp | 51 - example/n1962/factorial.cpp | 39 - example/n1962/sqrt.cpp | 32 - example/n1962/sqrt.d | 32 - example/n1962/sum.cpp | 30 - example/n1962/vector.cpp | 725 ------------- example/n1962/vector_n1962.hpp | 725 ------------- include/boost/contract.hpp | 44 - include/boost/contract/assert.hpp | 131 --- include/boost/contract/base_types.hpp | 180 ---- include/boost/contract/call_if.hpp | 615 ----------- include/boost/contract/check.hpp | 300 ------ include/boost/contract/constructor.hpp | 73 -- include/boost/contract/core/access.hpp | 166 --- include/boost/contract/core/check_macro.hpp | 123 --- include/boost/contract/core/config.hpp | 714 ------------- .../core/constructor_precondition.hpp | 97 -- include/boost/contract/core/exception.hpp | 966 ------------------ include/boost/contract/core/specify.hpp | 632 ------------ include/boost/contract/core/virtual.hpp | 161 --- include/boost/contract/destructor.hpp | 72 -- include/boost/contract/detail/assert.hpp | 28 - include/boost/contract/detail/auto_ptr.hpp | 53 - include/boost/contract/detail/check.hpp | 48 - include/boost/contract/detail/checking.hpp | 76 -- .../contract/detail/condition/cond_base.hpp | 153 --- .../contract/detail/condition/cond_inv.hpp | 232 ----- .../contract/detail/condition/cond_post.hpp | 88 -- .../detail/condition/cond_subcontracting.hpp | 472 --------- include/boost/contract/detail/config.hpp | 29 - include/boost/contract/detail/debug.hpp | 20 - include/boost/contract/detail/decl.hpp | 129 --- include/boost/contract/detail/declspec.hpp | 30 - include/boost/contract/detail/inlined.hpp | 14 - .../detail/inlined/core/exception.hpp | 374 ------- .../detail/inlined/detail/checking.hpp | 46 - include/boost/contract/detail/name.hpp | 26 - include/boost/contract/detail/none.hpp | 26 - include/boost/contract/detail/noop.hpp | 19 - .../contract/detail/operation/constructor.hpp | 95 -- .../contract/detail/operation/destructor.hpp | 102 -- .../contract/detail/operation/function.hpp | 82 -- .../detail/operation/public_function.hpp | 161 --- .../operation/static_public_function.hpp | 103 -- .../contract/detail/operator_safe_bool.hpp | 73 -- .../detail/preprocessor/keyword/private.hpp | 35 - .../detail/preprocessor/keyword/protected.hpp | 36 - .../detail/preprocessor/keyword/public.hpp | 35 - .../preprocessor/keyword/utility/is.hpp | 30 - .../detail/preprocessor/keyword/virtual.hpp | 35 - include/boost/contract/detail/tvariadic.hpp | 190 ---- .../type_traits/member_function_types.hpp | 72 -- .../contract/detail/type_traits/mirror.hpp | 111 -- .../contract/detail/type_traits/optional.hpp | 42 - include/boost/contract/function.hpp | 63 -- include/boost/contract/old.hpp | 752 -------------- include/boost/contract/override.hpp | 187 ---- include/boost/contract/public_function.hpp | 610 ----------- include/boost/contract_macro.hpp | 895 ---------------- index.html | 15 - src/contract.cpp | 12 - test/Jamfile.v2 | 347 ------- test/call_if/equal_to.cpp | 80 -- test/call_if/equal_to_cxx14.cpp | 62 -- test/call_if/false_.cpp | 62 -- test/call_if/false_void.cpp | 52 - test/call_if/no_equal_call_if.cpp | 64 -- test/call_if/no_equal_condition_if.cpp | 65 -- test/call_if/no_equal_error.cpp | 43 - test/call_if/true_.cpp | 64 -- test/call_if/true_void.cpp | 61 -- test/check/audit.cpp | 9 - test/check/audit.hpp | 35 - test/check/audit_disabled.cpp | 8 - test/check/audit_disabled_error.cpp | 9 - test/check/audit_error.cpp | 9 - test/check/axiom.cpp | 8 - test/check/axiom.hpp | 23 - test/check/axiom_error.cpp | 9 - test/check/decl.hpp | 65 -- test/check/decl_class.cpp | 11 - test/check/decl_macro.cpp | 11 - test/check/ifdef.cpp | 89 -- test/check/ifdef_macro.cpp | 62 -- test/constructor/access.cpp | 136 --- test/constructor/decl.hpp | 170 --- .../constructor/decl_entry_static_inv_all.cpp | 218 ---- .../decl_entry_static_inv_ends.cpp | 208 ---- .../constructor/decl_entry_static_inv_mid.cpp | 203 ---- .../decl_entry_static_inv_none.cpp | 124 --- test/constructor/decl_exit_inv_all.cpp | 200 ---- test/constructor/decl_exit_inv_ends.cpp | 194 ---- test/constructor/decl_exit_inv_mid.cpp | 188 ---- test/constructor/decl_exit_inv_none.cpp | 115 --- test/constructor/decl_exit_static_inv_all.cpp | 223 ---- .../constructor/decl_exit_static_inv_ends.cpp | 212 ---- test/constructor/decl_exit_static_inv_mid.cpp | 201 ---- .../constructor/decl_exit_static_inv_none.cpp | 123 --- test/constructor/decl_post_all.cpp | 185 ---- test/constructor/decl_post_ends.cpp | 167 --- test/constructor/decl_post_mid.cpp | 159 --- test/constructor/decl_post_none.cpp | 109 -- test/constructor/decl_pre_all.cpp | 177 ---- test/constructor/decl_pre_ends.cpp | 171 ---- test/constructor/decl_pre_mid.cpp | 163 --- test/constructor/decl_pre_none.cpp | 114 --- test/constructor/ifdef.cpp | 133 --- test/constructor/ifdef_macro.cpp | 157 --- test/constructor/pre_error.cpp | 24 - test/constructor/smoke.cpp | 410 -------- test/constructor/throwing_body.cpp | 145 --- test/constructor/throwing_old.cpp | 158 --- test/constructor/throwing_post.cpp | 164 --- test/constructor/throwing_pre.cpp | 164 --- test/destructor/access.cpp | 122 --- test/destructor/decl.hpp | 145 --- test/destructor/decl_entry_inv_all.cpp | 221 ---- test/destructor/decl_entry_inv_ends.cpp | 205 ---- test/destructor/decl_entry_inv_mid.cpp | 193 ---- test/destructor/decl_entry_inv_none.cpp | 109 -- test/destructor/decl_entry_static_inv_all.cpp | 230 ----- .../destructor/decl_entry_static_inv_ends.cpp | 215 ---- test/destructor/decl_entry_static_inv_mid.cpp | 202 ---- .../destructor/decl_entry_static_inv_none.cpp | 118 --- test/destructor/decl_exit_static_inv_all.cpp | 221 ---- test/destructor/decl_exit_static_inv_ends.cpp | 210 ---- test/destructor/decl_exit_static_inv_mid.cpp | 202 ---- test/destructor/decl_exit_static_inv_none.cpp | 118 --- test/destructor/decl_post_all.cpp | 199 ---- test/destructor/decl_post_ends.cpp | 190 ---- test/destructor/decl_post_mid.cpp | 181 ---- test/destructor/decl_post_none.cpp | 103 -- test/destructor/ifdef.cpp | 111 -- test/destructor/ifdef_macro.cpp | 142 --- test/destructor/pre_error.cpp | 24 - test/destructor/smoke.cpp | 302 ------ test/destructor/throwing_body.cpp | 144 --- test/destructor/throwing_old.cpp | 150 --- test/destructor/throwing_post.cpp | 153 --- test/detail/counter.hpp | 56 - test/detail/oteststream.hpp | 79 -- test/detail/out.hpp | 23 - test/detail/out_inlined.hpp | 33 - test/detail/unprotected_commas.hpp | 25 - .../always_disable_post_except_lib.cpp | 75 -- .../assertions_disable_assertions_lib.cpp | 10 - .../assertions_disable_assertions_prog.cpp | 10 - test/disable/audit.cpp | 9 - test/disable/audit.hpp | 32 - test/disable/audit_disabled.cpp | 8 - test/disable/audit_disabled_error.cpp | 9 - test/disable/audit_error.cpp | 9 - test/disable/axiom.cpp | 8 - test/disable/axiom.hpp | 23 - test/disable/axiom_error.cpp | 9 - test/disable/lib_a.cpp | 13 - test/disable/lib_a.hpp | 50 - test/disable/lib_a_inlined.hpp | 88 -- test/disable/lib_ab.hpp | 164 --- test/disable/lib_b.cpp | 9 - test/disable/lib_b.hpp | 41 - test/disable/lib_b_inlined.hpp | 126 --- test/disable/lib_x.cpp | 30 - test/disable/lib_x.hpp | 30 - test/disable/lib_y.cpp | 24 - test/disable/lib_y.hpp | 40 - .../disable/pre_disable_no_assertion_prog.cpp | 11 - test/disable/prog.hpp | 13 - test/function/decl.hpp | 40 - test/function/decl_post_all.cpp | 63 -- test/function/decl_post_none.cpp | 38 - test/function/decl_pre_all.cpp | 72 -- test/function/decl_pre_none.cpp | 38 - test/function/except_throw.cpp | 56 - test/function/ifdef.cpp | 58 -- test/function/ifdef_macro.cpp | 95 -- test/function/smoke.cpp | 99 -- test/function/throwing_body.cpp | 55 - test/function/throwing_old.cpp | 59 -- test/function/throwing_post.cpp | 62 -- test/function/throwing_pre.cpp | 63 -- test/invariant/decl.hpp | 840 --------------- test/invariant/decl_const.cpp | 13 - test/invariant/decl_cv.cpp | 13 - test/invariant/decl_cv_const.cpp | 13 - test/invariant/decl_nothing.cpp | 13 - test/invariant/decl_static.cpp | 13 - test/invariant/decl_static_const.cpp | 13 - test/invariant/decl_static_cv.cpp | 13 - test/invariant/decl_static_cv_const.cpp | 13 - test/invariant/ifdef.cpp | 174 ---- test/invariant/ifdef_macro.cpp | 170 --- test/invariant/mutable.hpp | 28 - test/invariant/mutable_error.cpp | 14 - test/invariant/mutable_permissive.cpp | 11 - test/invariant/static.hpp | 28 - test/invariant/static_const.hpp | 28 - test/invariant/static_const_error.cpp | 14 - test/invariant/static_const_permissive.cpp | 11 - test/invariant/static_cv.hpp | 28 - test/invariant/static_cv_error.cpp | 14 - test/invariant/static_cv_permissive.cpp | 11 - test/invariant/static_error.cpp | 14 - test/invariant/static_mutable.hpp | 28 - test/invariant/static_mutable_error.cpp | 14 - test/invariant/static_mutable_permissive.cpp | 11 - test/invariant/static_permissive.cpp | 11 - test/invariant/static_volatile.hpp | 28 - test/invariant/static_volatile_error.cpp | 14 - test/invariant/static_volatile_permissive.cpp | 11 - test/invariant/volatile.hpp | 28 - test/invariant/volatile_error.cpp | 14 - test/invariant/volatile_permissive.cpp | 11 - test/old/auto.cpp | 42 - test/old/copyable_traits.cpp | 106 -- test/old/if_copyable.cpp | 133 --- test/old/if_copyable.hpp | 45 - test/old/if_copyable_error.cpp | 43 - test/old/if_copyable_macro.cpp | 172 ---- test/old/no_macro.cpp | 9 - test/old/no_macro.hpp | 190 ---- test/old/no_macro_if_copyable.cpp | 9 - test/old/no_make_old_error.cpp | 9 - test/old/no_make_old_error.hpp | 21 - test/old/no_make_old_if_copyable_error.cpp | 9 - test/public_function/access.cpp | 136 --- test/public_function/decl.hpp | 162 --- test/public_function/decl_entry_inv_all.cpp | 184 ---- test/public_function/decl_entry_inv_ends.cpp | 178 ---- test/public_function/decl_entry_inv_mid.cpp | 171 ---- test/public_function/decl_entry_inv_none.cpp | 105 -- .../decl_entry_static_inv_all.cpp | 182 ---- .../decl_entry_static_inv_ends.cpp | 197 ---- .../decl_entry_static_inv_mid.cpp | 168 --- .../decl_entry_static_inv_none.cpp | 104 -- test/public_function/decl_exit_inv_all.cpp | 195 ---- test/public_function/decl_exit_inv_ends.cpp | 188 ---- test/public_function/decl_exit_inv_mid.cpp | 186 ---- test/public_function/decl_exit_inv_none.cpp | 109 -- .../decl_exit_static_inv_all.cpp | 194 ---- .../decl_exit_static_inv_ends.cpp | 190 ---- .../decl_exit_static_inv_mid.cpp | 189 ---- .../decl_exit_static_inv_none.cpp | 109 -- test/public_function/decl_post_all.cpp | 162 --- test/public_function/decl_post_ends.cpp | 157 --- test/public_function/decl_post_mid.cpp | 153 --- test/public_function/decl_post_none.cpp | 90 -- test/public_function/decl_pre_all.cpp | 153 --- test/public_function/decl_pre_ends.cpp | 158 --- test/public_function/decl_pre_mid.cpp | 165 --- test/public_function/decl_pre_none.cpp | 90 -- test/public_function/friend.cpp | 107 -- test/public_function/ifdef.cpp | 122 --- test/public_function/ifdef_macro.cpp | 171 ---- test/public_function/max_args.cpp | 10 - test/public_function/max_args.hpp | 194 ---- test/public_function/max_args0.cpp | 11 - test/public_function/max_args0_no_tva.cpp | 12 - test/public_function/max_args1.cpp | 11 - test/public_function/max_args1_no_tva.cpp | 12 - test/public_function/max_args2.cpp | 11 - test/public_function/max_args2_no_tva.cpp | 12 - test/public_function/max_args_no_tva.cpp | 11 - test/public_function/max_bases.cpp | 59 -- test/public_function/old_virtual.cpp | 214 ---- test/public_function/overload.cpp | 10 - test/public_function/overload.hpp | 343 ------- test/public_function/overload_no_tva.cpp | 11 - test/public_function/override.hpp | 41 - test/public_function/override_error.cpp | 14 - test/public_function/override_permissive.cpp | 11 - test/public_function/protected.cpp | 88 -- test/public_function/protected_error.cpp | 52 - test/public_function/smoke.cpp | 104 -- test/public_function/smoke.hpp | 261 ----- test/public_function/static.cpp | 82 -- test/public_function/static_ifdef.cpp | 74 -- test/public_function/static_ifdef_macro.cpp | 90 -- test/public_function/static_throwing_body.cpp | 67 -- test/public_function/static_throwing_old.cpp | 71 -- test/public_function/static_throwing_post.cpp | 73 -- test/public_function/static_throwing_pre.cpp | 74 -- test/public_function/throwing_body.cpp | 106 -- .../public_function/throwing_body_virtual.cpp | 108 -- .../throwing_body_virtual_branch.cpp | 94 -- test/public_function/throwing_old.cpp | 149 --- test/public_function/throwing_post.cpp | 157 --- test/public_function/throwing_pre.cpp | 154 --- test/public_function/virtual.cpp | 106 -- test/public_function/virtual_access.cpp | 220 ---- test/public_function/virtual_access_multi.cpp | 283 ----- test/public_function/virtual_branch.cpp | 90 -- test/public_function/virtual_sparse.cpp | 418 -------- test/result/mixed_optional.cpp | 10 - test/result/mixed_optional.hpp | 410 -------- test/result/mixed_optional_ref.cpp | 11 - test/result/type_mismatch_error.cpp | 50 - test/specify/auto_error.cpp | 15 - test/specify/auto_pre_error.cpp | 17 - test/specify/auto_pre_old_error.cpp | 18 - test/specify/auto_pre_old_post_error.cpp | 19 - .../auto_pre_old_post_except_error.cpp | 20 - test/specify/except.cpp | 37 - test/specify/except_old_error.cpp | 23 - test/specify/except_post_error.cpp | 23 - test/specify/except_pre_error.cpp | 23 - test/specify/missing_check.cpp | 41 - test/specify/nothing.cpp | 32 - test/specify/old.cpp | 39 - test/specify/old_except.cpp | 41 - test/specify/old_post.cpp | 44 - test/specify/old_post_except.cpp | 45 - test/specify/old_pre_error.cpp | 23 - test/specify/post.cpp | 39 - test/specify/post_except.cpp | 41 - test/specify/post_old_error.cpp | 23 - test/specify/post_pre_error.cpp | 23 - test/specify/pre.cpp | 39 - test/specify/pre_except.cpp | 41 - test/specify/pre_old.cpp | 44 - test/specify/pre_old_except.cpp | 45 - test/specify/pre_old_post.cpp | 48 - test/specify/pre_old_post_except.cpp | 49 - test/specify/pre_post.cpp | 44 - test/specify/pre_post_except.cpp | 45 - 489 files changed, 49305 deletions(-) delete mode 100644 COPYRIGHT.txt delete mode 100644 Jamroot delete mode 100644 LICENSE_1_0.txt delete mode 100644 README.txt delete mode 100644 boost.png delete mode 100644 build/Jamfile.v2 delete mode 100644 build/boost_contract_no.jam delete mode 100644 build/boost_contract_no.jam-gen.py delete mode 100644 doc/Jamfile.v2 delete mode 100644 doc/acknowledgments.qbk delete mode 100644 doc/advanced.qbk delete mode 100644 doc/bibliography.qbk delete mode 100644 doc/contract_programming_overview.qbk delete mode 100644 doc/examples.qbk delete mode 100644 doc/extras.qbk delete mode 100644 doc/full_table_of_contents.qbk delete mode 100644 doc/getting_started.qbk delete mode 100644 doc/introduction.qbk delete mode 100644 doc/main.qbk delete mode 100644 doc/release_notes.qbk delete mode 100644 doc/src/boost.xml delete mode 100644 doc/src/boostbook.css delete mode 100644 doc/src/docutils.css delete mode 100644 doc/src/images/alert.png delete mode 100644 doc/src/images/blank.png delete mode 100644 doc/src/images/callouts/1.png delete mode 100644 doc/src/images/callouts/1.svg delete mode 100644 doc/src/images/callouts/10.png delete mode 100644 doc/src/images/callouts/10.svg delete mode 100644 doc/src/images/callouts/11.png delete mode 100644 doc/src/images/callouts/11.svg delete mode 100644 doc/src/images/callouts/12.png delete mode 100644 doc/src/images/callouts/12.svg delete mode 100644 doc/src/images/callouts/13.png delete mode 100644 doc/src/images/callouts/13.svg delete mode 100644 doc/src/images/callouts/14.png delete mode 100644 doc/src/images/callouts/14.svg delete mode 100644 doc/src/images/callouts/15.png delete mode 100644 doc/src/images/callouts/15.svg delete mode 100644 doc/src/images/callouts/16.svg delete mode 100644 doc/src/images/callouts/17.svg delete mode 100644 doc/src/images/callouts/18.svg delete mode 100644 doc/src/images/callouts/19.svg delete mode 100644 doc/src/images/callouts/2.png delete mode 100644 doc/src/images/callouts/2.svg delete mode 100644 doc/src/images/callouts/20.svg delete mode 100644 doc/src/images/callouts/21.svg delete mode 100644 doc/src/images/callouts/22.svg delete mode 100644 doc/src/images/callouts/23.svg delete mode 100644 doc/src/images/callouts/24.svg delete mode 100644 doc/src/images/callouts/25.svg delete mode 100644 doc/src/images/callouts/26.svg delete mode 100644 doc/src/images/callouts/27.svg delete mode 100644 doc/src/images/callouts/28.svg delete mode 100644 doc/src/images/callouts/29.svg delete mode 100644 doc/src/images/callouts/3.png delete mode 100644 doc/src/images/callouts/3.svg delete mode 100644 doc/src/images/callouts/30.svg delete mode 100644 doc/src/images/callouts/4.png delete mode 100644 doc/src/images/callouts/4.svg delete mode 100644 doc/src/images/callouts/5.png delete mode 100644 doc/src/images/callouts/5.svg delete mode 100644 doc/src/images/callouts/6.png delete mode 100644 doc/src/images/callouts/6.svg delete mode 100644 doc/src/images/callouts/7.png delete mode 100644 doc/src/images/callouts/7.svg delete mode 100644 doc/src/images/callouts/8.png delete mode 100644 doc/src/images/callouts/8.svg delete mode 100644 doc/src/images/callouts/9.png delete mode 100644 doc/src/images/callouts/9.svg delete mode 100644 doc/src/images/caution.png delete mode 100644 doc/src/images/caution.svg delete mode 100644 doc/src/images/draft.png delete mode 100644 doc/src/images/home.png delete mode 100644 doc/src/images/home.svg delete mode 100644 doc/src/images/important.png delete mode 100644 doc/src/images/important.svg delete mode 100644 doc/src/images/next.png delete mode 100644 doc/src/images/next.svg delete mode 100644 doc/src/images/next_disabled.png delete mode 100644 doc/src/images/note.png delete mode 100644 doc/src/images/note.svg delete mode 100644 doc/src/images/prev.png delete mode 100644 doc/src/images/prev.svg delete mode 100644 doc/src/images/prev_disabled.png delete mode 100644 doc/src/images/smiley.png delete mode 100644 doc/src/images/tip.png delete mode 100644 doc/src/images/tip.svg delete mode 100644 doc/src/images/toc-blank.png delete mode 100644 doc/src/images/toc-minus.png delete mode 100644 doc/src/images/toc-plus.png delete mode 100644 doc/src/images/up.png delete mode 100644 doc/src/images/up.svg delete mode 100644 doc/src/images/up_disabled.png delete mode 100644 doc/src/images/warning.png delete mode 100644 doc/src/images/warning.svg delete mode 100644 doc/src/minimal.css delete mode 100644 doc/src/reference.css delete mode 100644 doc/tutorial.qbk delete mode 100644 example/Jamfile.v2 delete mode 100644 example/cline90/calendar.cpp delete mode 100644 example/cline90/stack.cpp delete mode 100644 example/cline90/vector.hpp delete mode 100644 example/cline90/vector_axx.hpp delete mode 100644 example/cline90/vector_main.cpp delete mode 100644 example/cline90/vstack.cpp delete mode 100644 example/features/access.cpp delete mode 100644 example/features/assertion_level.cpp delete mode 100644 example/features/base_types.cpp delete mode 100644 example/features/base_types_no_macro.cpp delete mode 100644 example/features/call_if_cxx14.cpp delete mode 100644 example/features/check.cpp delete mode 100644 example/features/code_block.cpp delete mode 100644 example/features/condition_if.cpp delete mode 100644 example/features/friend.cpp delete mode 100644 example/features/friend_invariant.cpp delete mode 100644 example/features/ifdef.cpp delete mode 100644 example/features/ifdef_macro.cpp delete mode 100644 example/features/introduction.cpp delete mode 100644 example/features/introduction_comments.cpp delete mode 100644 example/features/introduction_public.cpp delete mode 100644 example/features/lambda.cpp delete mode 100644 example/features/loop.cpp delete mode 100644 example/features/move.cpp delete mode 100644 example/features/named_override.cpp delete mode 100644 example/features/no_lambdas.cpp delete mode 100644 example/features/no_lambdas.hpp delete mode 100644 example/features/no_lambdas_local_func.cpp delete mode 100644 example/features/non_member.cpp delete mode 100644 example/features/old.cpp delete mode 100644 example/features/old_if_copyable.cpp delete mode 100644 example/features/old_no_macro.cpp delete mode 100644 example/features/optional_result.cpp delete mode 100644 example/features/optional_result_virtual.cpp delete mode 100644 example/features/overload.cpp delete mode 100644 example/features/private_protected.cpp delete mode 100644 example/features/private_protected_virtual.cpp delete mode 100644 example/features/private_protected_virtual_multi.cpp delete mode 100644 example/features/public.cpp delete mode 100644 example/features/pure_virtual_public.cpp delete mode 100644 example/features/separate_body.cpp delete mode 100644 example/features/separate_body.hpp delete mode 100644 example/features/static_public.cpp delete mode 100644 example/features/throw_on_failure.cpp delete mode 100644 example/features/union.cpp delete mode 100644 example/features/volatile.cpp delete mode 100644 example/meyer97/stack3.cpp delete mode 100644 example/meyer97/stack4.e delete mode 100644 example/meyer97/stack4.hpp delete mode 100644 example/meyer97/stack4_main.cpp delete mode 100644 example/mitchell02/counter/counter.hpp delete mode 100644 example/mitchell02/counter/decrement_button.hpp delete mode 100644 example/mitchell02/counter/push_button.hpp delete mode 100644 example/mitchell02/counter_main.cpp delete mode 100644 example/mitchell02/courier.cpp delete mode 100644 example/mitchell02/customer_manager.cpp delete mode 100644 example/mitchell02/dictionary.cpp delete mode 100644 example/mitchell02/name_list.cpp delete mode 100644 example/mitchell02/observer/observer.hpp delete mode 100644 example/mitchell02/observer/subject.hpp delete mode 100644 example/mitchell02/observer_main.cpp delete mode 100644 example/mitchell02/simple_queue.cpp delete mode 100644 example/mitchell02/stack.cpp delete mode 100644 example/n1962/circle.cpp delete mode 100644 example/n1962/equal.cpp delete mode 100644 example/n1962/factorial.cpp delete mode 100644 example/n1962/sqrt.cpp delete mode 100644 example/n1962/sqrt.d delete mode 100644 example/n1962/sum.cpp delete mode 100644 example/n1962/vector.cpp delete mode 100644 example/n1962/vector_n1962.hpp delete mode 100644 include/boost/contract.hpp delete mode 100644 include/boost/contract/assert.hpp delete mode 100644 include/boost/contract/base_types.hpp delete mode 100644 include/boost/contract/call_if.hpp delete mode 100644 include/boost/contract/check.hpp delete mode 100644 include/boost/contract/constructor.hpp delete mode 100644 include/boost/contract/core/access.hpp delete mode 100644 include/boost/contract/core/check_macro.hpp delete mode 100644 include/boost/contract/core/config.hpp delete mode 100644 include/boost/contract/core/constructor_precondition.hpp delete mode 100644 include/boost/contract/core/exception.hpp delete mode 100644 include/boost/contract/core/specify.hpp delete mode 100644 include/boost/contract/core/virtual.hpp delete mode 100644 include/boost/contract/destructor.hpp delete mode 100644 include/boost/contract/detail/assert.hpp delete mode 100644 include/boost/contract/detail/auto_ptr.hpp delete mode 100644 include/boost/contract/detail/check.hpp delete mode 100644 include/boost/contract/detail/checking.hpp delete mode 100644 include/boost/contract/detail/condition/cond_base.hpp delete mode 100644 include/boost/contract/detail/condition/cond_inv.hpp delete mode 100644 include/boost/contract/detail/condition/cond_post.hpp delete mode 100644 include/boost/contract/detail/condition/cond_subcontracting.hpp delete mode 100644 include/boost/contract/detail/config.hpp delete mode 100644 include/boost/contract/detail/debug.hpp delete mode 100644 include/boost/contract/detail/decl.hpp delete mode 100644 include/boost/contract/detail/declspec.hpp delete mode 100644 include/boost/contract/detail/inlined.hpp delete mode 100644 include/boost/contract/detail/inlined/core/exception.hpp delete mode 100644 include/boost/contract/detail/inlined/detail/checking.hpp delete mode 100644 include/boost/contract/detail/name.hpp delete mode 100644 include/boost/contract/detail/none.hpp delete mode 100644 include/boost/contract/detail/noop.hpp delete mode 100644 include/boost/contract/detail/operation/constructor.hpp delete mode 100644 include/boost/contract/detail/operation/destructor.hpp delete mode 100644 include/boost/contract/detail/operation/function.hpp delete mode 100644 include/boost/contract/detail/operation/public_function.hpp delete mode 100644 include/boost/contract/detail/operation/static_public_function.hpp delete mode 100644 include/boost/contract/detail/operator_safe_bool.hpp delete mode 100644 include/boost/contract/detail/preprocessor/keyword/private.hpp delete mode 100644 include/boost/contract/detail/preprocessor/keyword/protected.hpp delete mode 100644 include/boost/contract/detail/preprocessor/keyword/public.hpp delete mode 100644 include/boost/contract/detail/preprocessor/keyword/utility/is.hpp delete mode 100644 include/boost/contract/detail/preprocessor/keyword/virtual.hpp delete mode 100644 include/boost/contract/detail/tvariadic.hpp delete mode 100644 include/boost/contract/detail/type_traits/member_function_types.hpp delete mode 100644 include/boost/contract/detail/type_traits/mirror.hpp delete mode 100644 include/boost/contract/detail/type_traits/optional.hpp delete mode 100644 include/boost/contract/function.hpp delete mode 100644 include/boost/contract/old.hpp delete mode 100644 include/boost/contract/override.hpp delete mode 100644 include/boost/contract/public_function.hpp delete mode 100644 include/boost/contract_macro.hpp delete mode 100644 index.html delete mode 100644 src/contract.cpp delete mode 100644 test/Jamfile.v2 delete mode 100644 test/call_if/equal_to.cpp delete mode 100644 test/call_if/equal_to_cxx14.cpp delete mode 100644 test/call_if/false_.cpp delete mode 100644 test/call_if/false_void.cpp delete mode 100644 test/call_if/no_equal_call_if.cpp delete mode 100644 test/call_if/no_equal_condition_if.cpp delete mode 100644 test/call_if/no_equal_error.cpp delete mode 100644 test/call_if/true_.cpp delete mode 100644 test/call_if/true_void.cpp delete mode 100644 test/check/audit.cpp delete mode 100644 test/check/audit.hpp delete mode 100644 test/check/audit_disabled.cpp delete mode 100644 test/check/audit_disabled_error.cpp delete mode 100644 test/check/audit_error.cpp delete mode 100644 test/check/axiom.cpp delete mode 100644 test/check/axiom.hpp delete mode 100644 test/check/axiom_error.cpp delete mode 100644 test/check/decl.hpp delete mode 100644 test/check/decl_class.cpp delete mode 100644 test/check/decl_macro.cpp delete mode 100644 test/check/ifdef.cpp delete mode 100644 test/check/ifdef_macro.cpp delete mode 100644 test/constructor/access.cpp delete mode 100644 test/constructor/decl.hpp delete mode 100644 test/constructor/decl_entry_static_inv_all.cpp delete mode 100644 test/constructor/decl_entry_static_inv_ends.cpp delete mode 100644 test/constructor/decl_entry_static_inv_mid.cpp delete mode 100644 test/constructor/decl_entry_static_inv_none.cpp delete mode 100644 test/constructor/decl_exit_inv_all.cpp delete mode 100644 test/constructor/decl_exit_inv_ends.cpp delete mode 100644 test/constructor/decl_exit_inv_mid.cpp delete mode 100644 test/constructor/decl_exit_inv_none.cpp delete mode 100644 test/constructor/decl_exit_static_inv_all.cpp delete mode 100644 test/constructor/decl_exit_static_inv_ends.cpp delete mode 100644 test/constructor/decl_exit_static_inv_mid.cpp delete mode 100644 test/constructor/decl_exit_static_inv_none.cpp delete mode 100644 test/constructor/decl_post_all.cpp delete mode 100644 test/constructor/decl_post_ends.cpp delete mode 100644 test/constructor/decl_post_mid.cpp delete mode 100644 test/constructor/decl_post_none.cpp delete mode 100644 test/constructor/decl_pre_all.cpp delete mode 100644 test/constructor/decl_pre_ends.cpp delete mode 100644 test/constructor/decl_pre_mid.cpp delete mode 100644 test/constructor/decl_pre_none.cpp delete mode 100644 test/constructor/ifdef.cpp delete mode 100644 test/constructor/ifdef_macro.cpp delete mode 100644 test/constructor/pre_error.cpp delete mode 100644 test/constructor/smoke.cpp delete mode 100644 test/constructor/throwing_body.cpp delete mode 100644 test/constructor/throwing_old.cpp delete mode 100644 test/constructor/throwing_post.cpp delete mode 100644 test/constructor/throwing_pre.cpp delete mode 100644 test/destructor/access.cpp delete mode 100644 test/destructor/decl.hpp delete mode 100644 test/destructor/decl_entry_inv_all.cpp delete mode 100644 test/destructor/decl_entry_inv_ends.cpp delete mode 100644 test/destructor/decl_entry_inv_mid.cpp delete mode 100644 test/destructor/decl_entry_inv_none.cpp delete mode 100644 test/destructor/decl_entry_static_inv_all.cpp delete mode 100644 test/destructor/decl_entry_static_inv_ends.cpp delete mode 100644 test/destructor/decl_entry_static_inv_mid.cpp delete mode 100644 test/destructor/decl_entry_static_inv_none.cpp delete mode 100644 test/destructor/decl_exit_static_inv_all.cpp delete mode 100644 test/destructor/decl_exit_static_inv_ends.cpp delete mode 100644 test/destructor/decl_exit_static_inv_mid.cpp delete mode 100644 test/destructor/decl_exit_static_inv_none.cpp delete mode 100644 test/destructor/decl_post_all.cpp delete mode 100644 test/destructor/decl_post_ends.cpp delete mode 100644 test/destructor/decl_post_mid.cpp delete mode 100644 test/destructor/decl_post_none.cpp delete mode 100644 test/destructor/ifdef.cpp delete mode 100644 test/destructor/ifdef_macro.cpp delete mode 100644 test/destructor/pre_error.cpp delete mode 100644 test/destructor/smoke.cpp delete mode 100644 test/destructor/throwing_body.cpp delete mode 100644 test/destructor/throwing_old.cpp delete mode 100644 test/destructor/throwing_post.cpp delete mode 100644 test/detail/counter.hpp delete mode 100644 test/detail/oteststream.hpp delete mode 100644 test/detail/out.hpp delete mode 100644 test/detail/out_inlined.hpp delete mode 100644 test/detail/unprotected_commas.hpp delete mode 100644 test/disable/always_disable_post_except_lib.cpp delete mode 100644 test/disable/assertions_disable_assertions_lib.cpp delete mode 100644 test/disable/assertions_disable_assertions_prog.cpp delete mode 100644 test/disable/audit.cpp delete mode 100644 test/disable/audit.hpp delete mode 100644 test/disable/audit_disabled.cpp delete mode 100644 test/disable/audit_disabled_error.cpp delete mode 100644 test/disable/audit_error.cpp delete mode 100644 test/disable/axiom.cpp delete mode 100644 test/disable/axiom.hpp delete mode 100644 test/disable/axiom_error.cpp delete mode 100644 test/disable/lib_a.cpp delete mode 100644 test/disable/lib_a.hpp delete mode 100644 test/disable/lib_a_inlined.hpp delete mode 100644 test/disable/lib_ab.hpp delete mode 100644 test/disable/lib_b.cpp delete mode 100644 test/disable/lib_b.hpp delete mode 100644 test/disable/lib_b_inlined.hpp delete mode 100644 test/disable/lib_x.cpp delete mode 100644 test/disable/lib_x.hpp delete mode 100644 test/disable/lib_y.cpp delete mode 100644 test/disable/lib_y.hpp delete mode 100644 test/disable/pre_disable_no_assertion_prog.cpp delete mode 100644 test/disable/prog.hpp delete mode 100644 test/function/decl.hpp delete mode 100644 test/function/decl_post_all.cpp delete mode 100644 test/function/decl_post_none.cpp delete mode 100644 test/function/decl_pre_all.cpp delete mode 100644 test/function/decl_pre_none.cpp delete mode 100644 test/function/except_throw.cpp delete mode 100644 test/function/ifdef.cpp delete mode 100644 test/function/ifdef_macro.cpp delete mode 100644 test/function/smoke.cpp delete mode 100644 test/function/throwing_body.cpp delete mode 100644 test/function/throwing_old.cpp delete mode 100644 test/function/throwing_post.cpp delete mode 100644 test/function/throwing_pre.cpp delete mode 100644 test/invariant/decl.hpp delete mode 100644 test/invariant/decl_const.cpp delete mode 100644 test/invariant/decl_cv.cpp delete mode 100644 test/invariant/decl_cv_const.cpp delete mode 100644 test/invariant/decl_nothing.cpp delete mode 100644 test/invariant/decl_static.cpp delete mode 100644 test/invariant/decl_static_const.cpp delete mode 100644 test/invariant/decl_static_cv.cpp delete mode 100644 test/invariant/decl_static_cv_const.cpp delete mode 100644 test/invariant/ifdef.cpp delete mode 100644 test/invariant/ifdef_macro.cpp delete mode 100644 test/invariant/mutable.hpp delete mode 100644 test/invariant/mutable_error.cpp delete mode 100644 test/invariant/mutable_permissive.cpp delete mode 100644 test/invariant/static.hpp delete mode 100644 test/invariant/static_const.hpp delete mode 100644 test/invariant/static_const_error.cpp delete mode 100644 test/invariant/static_const_permissive.cpp delete mode 100644 test/invariant/static_cv.hpp delete mode 100644 test/invariant/static_cv_error.cpp delete mode 100644 test/invariant/static_cv_permissive.cpp delete mode 100644 test/invariant/static_error.cpp delete mode 100644 test/invariant/static_mutable.hpp delete mode 100644 test/invariant/static_mutable_error.cpp delete mode 100644 test/invariant/static_mutable_permissive.cpp delete mode 100644 test/invariant/static_permissive.cpp delete mode 100644 test/invariant/static_volatile.hpp delete mode 100644 test/invariant/static_volatile_error.cpp delete mode 100644 test/invariant/static_volatile_permissive.cpp delete mode 100644 test/invariant/volatile.hpp delete mode 100644 test/invariant/volatile_error.cpp delete mode 100644 test/invariant/volatile_permissive.cpp delete mode 100644 test/old/auto.cpp delete mode 100644 test/old/copyable_traits.cpp delete mode 100644 test/old/if_copyable.cpp delete mode 100644 test/old/if_copyable.hpp delete mode 100644 test/old/if_copyable_error.cpp delete mode 100644 test/old/if_copyable_macro.cpp delete mode 100644 test/old/no_macro.cpp delete mode 100644 test/old/no_macro.hpp delete mode 100644 test/old/no_macro_if_copyable.cpp delete mode 100644 test/old/no_make_old_error.cpp delete mode 100644 test/old/no_make_old_error.hpp delete mode 100644 test/old/no_make_old_if_copyable_error.cpp delete mode 100644 test/public_function/access.cpp delete mode 100644 test/public_function/decl.hpp delete mode 100644 test/public_function/decl_entry_inv_all.cpp delete mode 100644 test/public_function/decl_entry_inv_ends.cpp delete mode 100644 test/public_function/decl_entry_inv_mid.cpp delete mode 100644 test/public_function/decl_entry_inv_none.cpp delete mode 100644 test/public_function/decl_entry_static_inv_all.cpp delete mode 100644 test/public_function/decl_entry_static_inv_ends.cpp delete mode 100644 test/public_function/decl_entry_static_inv_mid.cpp delete mode 100644 test/public_function/decl_entry_static_inv_none.cpp delete mode 100644 test/public_function/decl_exit_inv_all.cpp delete mode 100644 test/public_function/decl_exit_inv_ends.cpp delete mode 100644 test/public_function/decl_exit_inv_mid.cpp delete mode 100644 test/public_function/decl_exit_inv_none.cpp delete mode 100644 test/public_function/decl_exit_static_inv_all.cpp delete mode 100644 test/public_function/decl_exit_static_inv_ends.cpp delete mode 100644 test/public_function/decl_exit_static_inv_mid.cpp delete mode 100644 test/public_function/decl_exit_static_inv_none.cpp delete mode 100644 test/public_function/decl_post_all.cpp delete mode 100644 test/public_function/decl_post_ends.cpp delete mode 100644 test/public_function/decl_post_mid.cpp delete mode 100644 test/public_function/decl_post_none.cpp delete mode 100644 test/public_function/decl_pre_all.cpp delete mode 100644 test/public_function/decl_pre_ends.cpp delete mode 100644 test/public_function/decl_pre_mid.cpp delete mode 100644 test/public_function/decl_pre_none.cpp delete mode 100644 test/public_function/friend.cpp delete mode 100644 test/public_function/ifdef.cpp delete mode 100644 test/public_function/ifdef_macro.cpp delete mode 100644 test/public_function/max_args.cpp delete mode 100644 test/public_function/max_args.hpp delete mode 100644 test/public_function/max_args0.cpp delete mode 100644 test/public_function/max_args0_no_tva.cpp delete mode 100644 test/public_function/max_args1.cpp delete mode 100644 test/public_function/max_args1_no_tva.cpp delete mode 100644 test/public_function/max_args2.cpp delete mode 100644 test/public_function/max_args2_no_tva.cpp delete mode 100644 test/public_function/max_args_no_tva.cpp delete mode 100644 test/public_function/max_bases.cpp delete mode 100644 test/public_function/old_virtual.cpp delete mode 100644 test/public_function/overload.cpp delete mode 100644 test/public_function/overload.hpp delete mode 100644 test/public_function/overload_no_tva.cpp delete mode 100644 test/public_function/override.hpp delete mode 100644 test/public_function/override_error.cpp delete mode 100644 test/public_function/override_permissive.cpp delete mode 100644 test/public_function/protected.cpp delete mode 100644 test/public_function/protected_error.cpp delete mode 100644 test/public_function/smoke.cpp delete mode 100644 test/public_function/smoke.hpp delete mode 100644 test/public_function/static.cpp delete mode 100644 test/public_function/static_ifdef.cpp delete mode 100644 test/public_function/static_ifdef_macro.cpp delete mode 100644 test/public_function/static_throwing_body.cpp delete mode 100644 test/public_function/static_throwing_old.cpp delete mode 100644 test/public_function/static_throwing_post.cpp delete mode 100644 test/public_function/static_throwing_pre.cpp delete mode 100644 test/public_function/throwing_body.cpp delete mode 100644 test/public_function/throwing_body_virtual.cpp delete mode 100644 test/public_function/throwing_body_virtual_branch.cpp delete mode 100644 test/public_function/throwing_old.cpp delete mode 100644 test/public_function/throwing_post.cpp delete mode 100644 test/public_function/throwing_pre.cpp delete mode 100644 test/public_function/virtual.cpp delete mode 100644 test/public_function/virtual_access.cpp delete mode 100644 test/public_function/virtual_access_multi.cpp delete mode 100644 test/public_function/virtual_branch.cpp delete mode 100644 test/public_function/virtual_sparse.cpp delete mode 100644 test/result/mixed_optional.cpp delete mode 100644 test/result/mixed_optional.hpp delete mode 100644 test/result/mixed_optional_ref.cpp delete mode 100644 test/result/type_mismatch_error.cpp delete mode 100644 test/specify/auto_error.cpp delete mode 100644 test/specify/auto_pre_error.cpp delete mode 100644 test/specify/auto_pre_old_error.cpp delete mode 100644 test/specify/auto_pre_old_post_error.cpp delete mode 100644 test/specify/auto_pre_old_post_except_error.cpp delete mode 100644 test/specify/except.cpp delete mode 100644 test/specify/except_old_error.cpp delete mode 100644 test/specify/except_post_error.cpp delete mode 100644 test/specify/except_pre_error.cpp delete mode 100644 test/specify/missing_check.cpp delete mode 100644 test/specify/nothing.cpp delete mode 100644 test/specify/old.cpp delete mode 100644 test/specify/old_except.cpp delete mode 100644 test/specify/old_post.cpp delete mode 100644 test/specify/old_post_except.cpp delete mode 100644 test/specify/old_pre_error.cpp delete mode 100644 test/specify/post.cpp delete mode 100644 test/specify/post_except.cpp delete mode 100644 test/specify/post_old_error.cpp delete mode 100644 test/specify/post_pre_error.cpp delete mode 100644 test/specify/pre.cpp delete mode 100644 test/specify/pre_except.cpp delete mode 100644 test/specify/pre_old.cpp delete mode 100644 test/specify/pre_old_except.cpp delete mode 100644 test/specify/pre_old_post.cpp delete mode 100644 test/specify/pre_old_post_except.cpp delete mode 100644 test/specify/pre_post.cpp delete mode 100644 test/specify/pre_post_except.cpp diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt deleted file mode 100644 index 5eaa5429..00000000 --- a/COPYRIGHT.txt +++ /dev/null @@ -1,4 +0,0 @@ -Copyright (C) 2008-2017 Lorenzo Caminiti -Distributed under the Boost Software License, Version 1.0 (see accompanying -file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -See: https://lcaminiti.github.io/boost-contract diff --git a/Jamroot b/Jamroot deleted file mode 100644 index 68435d1e..00000000 --- a/Jamroot +++ /dev/null @@ -1,110 +0,0 @@ - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -import build/boost_contract_no ; -import testing ; -import os ; -import feature ; - -BOOST_ROOT = [ os.environ BOOST_ROOT ] ; -if ! $(BOOST_ROOT) { - exit "Error: set BOOST_ROOT environment variable to Boost root directory" ; -} - -rule help_exit ( targets * : sources * : properties * ) { - all_nos = "" ; - sep = "" ; - for local cond in [ boost_contract_no.conds ] { - all_nos = "$(all_nos)$(sep)$(cond)" ; - sep = "," ; - } - echo " -Usage: bjam [OPTION]... DIR[-CPP_FILE_NAME] -Build and run Boost.Contract tests and examples. -Using Boost libraries from environment variable: $BOOST_ROOT = $(BOOST_ROOT) - -Options: - boost_contract_link=shared, build Boost.Contract library as shared, - static,header static, or header-only (shared by default) - boost_contract_no=all_yes, contract checking off (all_yea by default) - $(all_nos) - -Examples (on Linux-based bash): - Build just \"test/public_function/body_throw.cpp\": - [test]$ bjam public_function-body_throw - Build all targets using MSVC, GCC, and CLang compilers: - $ time bjam -q toolset=msvc,gcc,clang ; echo $? - Build with all linkages on multiple compilers: - $ time bjam -q toolset=msvc,gcc,clang boost_contract_link=static,header ; echo $? - Build with all contract checking combinations on multiple compilers: - $ time bjam -q toolset=msvc,gcc,clang boost_contract_no=$(all_nos) ; echo $? -" ; - exit ; -} - -project : - requirements - gcc:-std=c++11 - clang:-std=c++11 - - "./include" - - $(BOOST_ROOT) - $(BOOST_ROOT)/stage/lib - gcc:/boost/system//boost_system - clang:/boost/system//boost_system -; -use-project boost : $(BOOST_ROOT) ; - -rule subdir-compile-fail ( subdir : cpp_fname : requirements * ) { - compile-fail $(subdir)/$(cpp_fname).cpp : - shared:../build//boost_contract - static:../build//boost_contract - $(subdir) - $(requirements) - : - $(subdir)-$(cpp_fname) - ; -} - -rule subdir-run ( subdir : cpp_fname : requirements * ) { - run $(subdir)/$(cpp_fname).cpp : : : - shared:../build//boost_contract - static:../build//boost_contract - $(subdir) - $(requirements) - : - $(subdir)-$(cpp_fname) - ; -} - -rule subdir-lib ( subdir : cpp_fname : requirements * ) { - lib $(subdir)-$(cpp_fname) : $(subdir)/$(cpp_fname).cpp : - shared:../build//boost_contract - static:../build//boost_contract - $(subdir) - $(requirements) - ; -} - -feature.feature boost_contract_link : shared static header : - composite propagated link-incompatible ; -feature.compose shared : shared ; -feature.compose static : - static - BOOST_CONTRACT_STATIC_LINK -; -feature.compose header : - BOOST_CONTRACT_HEADER_ONLY -; - -feature.feature boost_contract_no : all_yes [ boost_contract_no.conds ] : - composite propagated link-incompatible ; -for local cond in [ boost_contract_no.conds ] { - feature.compose $(cond) : - [ boost_contract_no.defs_$(cond) ] ; -} - diff --git a/LICENSE_1_0.txt b/LICENSE_1_0.txt deleted file mode 100644 index 36b7cd93..00000000 --- a/LICENSE_1_0.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/README.txt b/README.txt deleted file mode 100644 index 690b6c99..00000000 --- a/README.txt +++ /dev/null @@ -1,19 +0,0 @@ -Boost.Contract (see: https://lcaminiti.github.io/boost-contract) - -A library implementing Contract Programming (a.k.a., Design by Contract or DbC) -for the C++ programming language. - -All Contract Programming features are supported by this library: subcontracting, -class invariants (also static and volatile), postconditions (with old and return -values), preconditions, customizable actions on assertion failure (terminate, -throw, etc.), optional compilation of assertion and checking, disable assertions -while already checking other assertions (to avoid infinite recursion), etc. - -NOTE: In one of its previous versions, this library passed Boost formal review -and it was accepted into the Boost libraries. However, the authors have not had -time yet to add this library to an official Boost release (see: -https://groups.google.com/forum/?fromgroups=#!topic/boost-list/jQ7OjAmos_Y). - -Copyright (C) 2008-2017 Lorenzo Caminiti -Distributed under the Boost Software License, Version 1.0 (see accompanying -file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). diff --git a/boost.png b/boost.png deleted file mode 100644 index b4d51fcd5c9149fd77f5ca6ed2b6b1b70e8fe24f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6308 zcmV;V7+dFwP)FBa0e37VcyhIDVmU z@{ls-C8mlZam5cr4-}LM9~I+5QpH5B!st{k3!T70hd^+W0NtImr#tP}?9T4a!E3dj1z_;Mr#v4xEk87nE(}rB1UTm zKa|L!Z^8i&PqZ)yF-hzFM_NzLlL93gC7ET zJdxAJ{EsJc$dZZ?qg9C?H%=Uhp!gvq7>XFJZv2qJLp}|JA4)he6fs&g_@M!h`?nMP zFcdLboA{vt4?(r_Roi-xqGx{o#=A#n-1*mS9)0ddf6I7fwa{w^kL-K>P;dG%5-xZs zQRJxBWOpk;5K!*IW}S{3Ju`jj)R{TY{OdN4Fs58ZGa@umc6HJZt5OQL&~}BD_X#6j7>kzV+ag=2Su& z*^ps;xmpNk#CEA4JC#2;tfJUh!dn3pYI(23qBlJfZQ?4fYlU?p*Kk`A1ALJEPpm~v8j|n_ll(i4PgaZ13 zG^>0oNB>dv^v7BKk`xsxS_E!aRn@A>o_1@ALEROB#w}+2tSUIKBs+tQMKi_kkd+_mRx#&-V{N+jAABQf&vNoMc;Ws2q%1) z{8=;hPnY^J(l&BDqp(fNRmFH*7d}&;)-=P+(QOaIiC{Y1G@BPrGfL<=D*F1BCZ@Sa zOsbV+f#(AG(A<7G%6oCf574a>V~i2Jxw^-Ic-e2_{?*KZz$0X1Bn=ytnM z`EQTTK;;B!PeU*KP?{+TxD9#{j(x8m z+Pi!EU+%cGy-EPX28Yf04zXsO9^m%wZ4-NTOm+g=9<&Ru7e=T~7~R42G>SJ3b?%gF z(|_%DTbpS`MX{J(=f?~61|ORUX+o&!TwbBYL1N+xJzXr<;G`BC0?Vi=JuGCj2^uww;Ps)T>wAnJg8$7-muj&@gu7T&kDXSW29Gh-<7o(O+lU5Y2oyiHd?`LK z6crqRa0!{_f8{Et)vKOTh-~)QFLgMExye)oDIxUQ!6R*Ou)C7uGp8SaWGDTA+M9O6 z1y8ubN3U%-(_Q?~EI?>!ZVGSutf$W^7Em<1y|Ge@Gm(&pp=;M0!%3mUi75b2UP0Mn z(>2%({W0YZ$F-2RC5qk!L>*bzq4I`<(AJ4DP;$tl_%r|UMp&ZHZc+koiP=eQ|4K(&ze{(0QnjmthP*Fcy0LzCrRV>Tg!5Kn#ZbqVj zWTmdvO6l}40OQj|^ij4ImtglX*wcv!x+0DuVzgeV2t4u(SwIxQqqrICP8GQ~4iWGZ z`oL@g1NfD^#HE+*!XOg5Y`43iaUoZisr}=2#5r=3LbXzjBxC$N&6eTuP+nBU7p@8XbZ%e=OWn_*B+SieC!^#3vbo)%>dVe zvKI>PI^L}=j%EV)V~50dZv5C~QCd{Wl{)BS-yD}T&4@f`M(?Z$_AxHqc8!*aqnfIz z#jKRhfC{!yL<{+b*s+Jkt%&zQ$g1Y#MRZBgLw>4!+%t@o(!1)bYU2R*^gn!;zzUuW z2et=+iOn^}k3X`@Q#FUoC%^a5-rd{D+SKLHE=VmL(}x0{5c{!P_#t?%JsGrtrCJ&O z8_n==I3Q&6HfRE`er-rUFXReZG#wX(N*%p($~!d9BV?|5{9#eAH6e0kE=s@*F2BQN zbHG?+u5t)B(CCOQj?y>)U^FFrCfpin@7o1!%CpSYo4OUx(aU9X{`jGcymZH&C4{Oh z*C2hz*CgYz>YOPuez%YFl8DNRs#Y!~lPM_i*&?dcJfMOs2qD{Vv%vWxx==QBv`9>K z8D?z{T8MhN6%42ZH;!Y-$C(5s6zLV4y$_K=>vT-@tKIg>geZJamzO{K+dsa_8*+vA z@M^KHuG^5}Zy$>pAmy9$o{fMSoQN;N5|RqRd+hcChHNC;)w+}*cNfb~q{)FyN@=uY&C4Llo&3rg=+zuLu_ zNufs`p`I_BYtw(=sl2&kpQET&kShbp*w)Qa&SRl=qKLhEC_u4H*=RiuJO>^MT%b2+QUuW8)9tL+pT`g0d8FAtfL8rQK9g z!U^Q3o_!f!uPZ+>BOR>}j zkVOl5baFv6gXP?zaR}idWXdEC{a+T1B+-D#$&o}vE75Pe6H2%{O<{LLrk!?rxw*+i zX%_dZ-K`U21b-b30!@2n-|L6=?40y zE|=ZEGWJ6U0fe4^aesSV(Cy`q!RAlN%3EF$lc{(^vGNF7 zTcOCQD#|U+=ZfV_O1k-K?o<}LMyMG9Egsfv4my!~nm+SvEwP=_h=4v^U_(mF;IsBEG z$OC^IOU1>D#Z*3@Uq3i-?GS(bOkGi(YlJwirL7SRp?fx>q^M8DN@|%CXpJA7DiX+J zV=n&jwgGH&9fe}KL-zwE$2bH_zuL8OUU=p)kRAu#IoA0iD=?@$WlmqSvv8^U!RdmvCy1?p)|xqO#PX;I-&*U1J4VY<;v?G@1O z2U1C1Rq`c$4bQEc1k(ZFFofI|k!1*7okkntdIUGBR_w^>#Q33KR`vXg`*DNco*k3a zO3~>+FaNcJM{tb>a;f#JT{7(m?o!7&4?15S7Z^V@n-8wsybAH61l)S|Vr6bgX%+B- z(8~JN_dcsE7F0n%d}0GCWx;w`ALq7S!<*5iZeIfO+IaEi4SIfAQ6)|xAjf0bT$aiY zOXers6bIBm&j+|rWt`55lXyC4gRJ82SG(a7VG;s2huc&6LypK?uJDq`7c2F*ewW2* zca{f0vqDIlTHJeQbjT$WVx5Z?3MJj*+`t=GS3n41HeS5>O0+JfyA5KtIa5!~%?%_1 z>(J<3xQ{g9gb&%-weO8Xl)UoH&)*;j0XJy-)o$BFn6UD+Ckc}f-B?-Nss3h%Q&rVO z!)N``xl+xpq}eb-HiXVxsGeJ@^Bj`WgArw^Tvd}Ix_?5jAk?bK%MiMD&=fv3kwdLkU391`!WGMpvSxUi9Br&brLGHxB=QFu#0CTTff?ETbR6xi6o@ACoOvQ z;8eIPZQJ+1c`jJUD`FzfW%ISE6U(TvG_4tZW1cqSYbtVBxEBQ4e0F*7L)+cjBh5xRfLKopq+ji}BYE@CarWa40D>dhK8Vj%aW)!D23*?v)(l7D6dDr9(@td!T)M}cNJC72> z2`RFW*QzSAd7>M8S#hYfg~-(d`fo+9Bn5@%dE5qz2=gh`KmWU*bmN6S{e$n|=IqES zpIrb3T|N!`@#Oa&YERV+yWKkB9bvq4(<{&YV~AL4fBm+i ziE*Agw^TXxWzm}E)SA&dj%CuVUxS4kSDV6R>SK9yU2=Vrmt*UBC8tFPN75X!!>1X$ zbBW?Ep`R8@@R-8N!4&4AnH#h`>pK76?GKWS?)3+a)jaZu`aJ zm_CqF2bF{?h^W?Ydy*jN_s%aVEqkUZuyBTuty-rcR8sUgpJ-HwakWBG&X;tLcD@Kl zwE#z{T9oyppdU3jisf3VToaAeKAtiM5qI8M$X*J!gH5%KY(_&F7_GzYKj2_r^P`vT zc4J^7k4k~O7ojg_AmN8Ri&CrVuCp7jPDBNv(fX}*vaifLXy287bOh`dfHWg>DWQqG7KNl+W=pqKuJ6Fw-6t&beN0%{vgFNPQr zX098h+!>>1?S{U*)OS=ey`7YQTIk`V0rWS=y3X}+v|OnrVv(J9Z20AodAmM_TpLG` zeF^uB>pFL-Tn7!#cT4y{3B2N4(4yKTfY z5Zsu1ci%@NF-%B<-Q}yJhQ5~wmH)uuNU*-Wvs_X|DGvPk-@iM5_PpE*5^Zv^g@Q(7 zhEt*8JTRmNBqlb-?;VdrBb8EK;%lBCR-nfT<;NEue&VN{cs8#yK0|Q*=Fv{(J)pC} zEP4068Omu2;1Xad-)&9%+ir&+M6llNJ=-RNhEAK_LfkHJzTTbQ;l~c4tSlrY@qAAC z#XEB?ZyN?ep1!!hnam8t`9eua^QAU~58)Rlg6LPL_J)9u^-zH9G7R1h!3dm`PR2)u z^{J20qlx>~?ph*${2=1je&i~u@zDs+zcaIR{L@^6HLVZ*G?*0&p>N;5Zqs^Esj5OX zCkk93;e*2oLGoON;9<0?i4W>La5%W)BC1r3(9bOcR;a;>4c`!Q$T7=*ke2vOgCeAA zN=1jDK^A_jv^zogmKFmKqkiHC$8c`fuyvXiRi&m5#DxdHG17vN4L1n6M4XX--`CS{ zp?&M=k7v(W>9`an z)MmEfxRm#Ob@pfQebrEy{G3+1W_oBaJ(Nk)l=Lm!9z{I4>D2o}Z?& zG6&-Pg;F&siFe;P=-7aOb0>}el}a_0;3+?#?e;{sjU1qLQrEgg2ruMQoB-|v5S2TjS7v*!p8|L-pyw4Xk>eH-ra06dPu<6~EmpW&6a z4nymNIz68u5s&`U_xIo+1ck}%{_4>0-=6w|b-H)=eK<(Gvj6bZv6J?khj&d*-gaZx z@qkGg9d~Ol2 z>Nyyhg$aMr|4w}X;PFMQ`R4$5;PL+X@Aq_7S%}ae$1}&SK{fX5jqtIE>Rfs1^&Q0~ zBzPQPXtcF9kYm#H%q+ZF8u09U{SYWfka+XZ??I_}c-LLt$eEdi-pVfJfAbP`;F?2^76#m|i4zf`Vl8XdZG>o~UXavtzt7S0+v&;65sL{RpC zkMF-zXX3Yyd_Z_e$1?zU;4yG7$1F_v+YcM^1b}T}8z-rte?ic}D|+I`|4AuM!^Dr{ zE4-ec;B_YmHMlw3H|VAfuQa8T0CeKvK`K4?n$clkEHtZcE<@2IDuawEsB z=6QZZ#DSmAkrULn21xk$^f?e3!1rW}7W4$r8KA?+3Ip^C9B&>v`q$sStHT~L$KdH^ z1Q)^NHIYW(He;|KZWcJ{hsH(FQQ_gCJQyLsZ8-b@6T@E$$b?%gy$kmkQ0A`N#^LRO z$bxr1ed06$KW2r5zX)Chi~{gZ%#I_BQ*L(%h$HCe-sx{{5#$LWU&s;i-Li-fw-%yH z8uTmZs(r8j#ytJuqYn}WX6U5J!ExU@p~FBg@4SbAYk_w`8#HZSg062G9)uP_A2X{m zx#xlVwvk1dSrtGC#tXO$-jXMDUwP{=2Q~04oQ5*UjLk^>_3VsmvcNyA~KMXvK);NCX zq2gJllUY|rjMfN#Ix0000shared ; -lib boost_contract : ../src/contract.cpp : static ; -# Build nothing for boost_contract_link=header (ignore errors Bjam gives). - diff --git a/build/boost_contract_no.jam b/build/boost_contract_no.jam deleted file mode 100644 index ea209859..00000000 --- a/build/boost_contract_no.jam +++ /dev/null @@ -1,141 +0,0 @@ - -# Generated file `python boost_contract_no.jam-gen.py > boost_contract_no.jam`. - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: https://lcaminiti.github.io/boost-contract - -module boost_contract_no { - -rule defs_entryinv { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS ; } - -rule defs_pre { return BOOST_CONTRACT_NO_PRECONDITIONS ; } - -rule defs_exitinv { return BOOST_CONTRACT_NO_EXIT_INVARIANTS ; } - -rule defs_post { return BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_except { return BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_check { return BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS ; } - -rule defs_entryinv_exitinv { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS ; } - -rule defs_entryinv_post { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_entryinv_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_exitinv { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS ; } - -rule defs_pre_post { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_pre_except { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_pre_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_exitinv_post { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_exitinv_except { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_exitinv_check { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_post_except { return BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_post_check { return BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_except_check { return BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_exitinv { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS ; } - -rule defs_entryinv_pre_post { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_entryinv_pre_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_pre_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_exitinv_post { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_entryinv_exitinv_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_exitinv_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_post_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_post_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_exitinv_post { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_pre_exitinv_except { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_pre_exitinv_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_post_except { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_pre_post_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_except_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_exitinv_post_except { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_exitinv_post_check { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_exitinv_except_check { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_post_except_check { return BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_exitinv_post { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS ; } - -rule defs_entryinv_pre_exitinv_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_pre_exitinv_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_post_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_pre_post_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_exitinv_post_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_exitinv_post_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_exitinv_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_post_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_exitinv_post_except { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_pre_exitinv_post_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_exitinv_except_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_post_except_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_exitinv_post_except_check { return BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_exitinv_post_except { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS ; } - -rule defs_entryinv_pre_exitinv_post_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_exitinv_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_post_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_exitinv_post_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_pre_exitinv_post_except_check { return BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - -rule defs_entryinv_pre_exitinv_post_except_check { return BOOST_CONTRACT_NO_ENTRY_INVARIANTS BOOST_CONTRACT_NO_PRECONDITIONS BOOST_CONTRACT_NO_EXIT_INVARIANTS BOOST_CONTRACT_NO_POSTCONDITIONS BOOST_CONTRACT_NO_EXCEPTS BOOST_CONTRACT_NO_CHECKS ; } - - -rule conds { return entryinv pre exitinv post except check entryinv_pre entryinv_exitinv entryinv_post entryinv_except entryinv_check pre_exitinv pre_post pre_except pre_check exitinv_post exitinv_except exitinv_check post_except post_check except_check entryinv_pre_exitinv entryinv_pre_post entryinv_pre_except entryinv_pre_check entryinv_exitinv_post entryinv_exitinv_except entryinv_exitinv_check entryinv_post_except entryinv_post_check entryinv_except_check pre_exitinv_post pre_exitinv_except pre_exitinv_check pre_post_except pre_post_check pre_except_check exitinv_post_except exitinv_post_check exitinv_except_check post_except_check entryinv_pre_exitinv_post entryinv_pre_exitinv_except entryinv_pre_exitinv_check entryinv_pre_post_except entryinv_pre_post_check entryinv_pre_except_check entryinv_exitinv_post_except entryinv_exitinv_post_check entryinv_exitinv_except_check entryinv_post_except_check pre_exitinv_post_except pre_exitinv_post_check pre_exitinv_except_check pre_post_except_check exitinv_post_except_check entryinv_pre_exitinv_post_except entryinv_pre_exitinv_post_check entryinv_pre_exitinv_except_check entryinv_pre_post_except_check entryinv_exitinv_post_except_check pre_exitinv_post_except_check entryinv_pre_exitinv_post_except_check ; } - -} # module - diff --git a/build/boost_contract_no.jam-gen.py b/build/boost_contract_no.jam-gen.py deleted file mode 100644 index 26540adb..00000000 --- a/build/boost_contract_no.jam-gen.py +++ /dev/null @@ -1,41 +0,0 @@ - -print ''' -# Generated file `python boost_contract_no.jam-gen.py > boost_contract_no.jam`. - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: https://lcaminiti.github.io/boost-contract -''' - -# NOTE: Other macros symbols can be added here as needed. -conds = ['entryinv', 'pre', 'exitinv', 'post', 'except', 'check'] -defs = { - 'entryinv': 'BOOST_CONTRACT_NO_ENTRY_INVARIANTS', - 'pre': 'BOOST_CONTRACT_NO_PRECONDITIONS', - 'exitinv': 'BOOST_CONTRACT_NO_EXIT_INVARIANTS', - 'post': 'BOOST_CONTRACT_NO_POSTCONDITIONS', - 'except': 'BOOST_CONTRACT_NO_EXCEPTS', - 'check': 'BOOST_CONTRACT_NO_CHECKS' -} - -import itertools -print 'module boost_contract_no {\n' -s = '' -for r in range(len(conds)): - for comb in itertools.combinations(conds, r + 1): - c = '' - d = '' - sep = '' - for cond in comb: - c += sep + cond - sep = '_' - d += " " + defs[cond] - s += ' ' + c - print 'rule defs_{0} {{ return {1} ; }}\n'.format(c, d) -print ''' -rule conds {{ return {0} ; }} - -}} # module -'''.format(s) - diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 deleted file mode 100644 index c5380344..00000000 --- a/doc/Jamfile.v2 +++ /dev/null @@ -1,63 +0,0 @@ - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -import quickbook ; -using boostbook ; - -doxygen reference -: - ../include/boost/contract.hpp - ../include/boost/contract_macro.hpp - - ../include/boost/contract/assert.hpp - ../include/boost/contract/base_types.hpp - ../include/boost/contract/call_if.hpp - ../include/boost/contract/check.hpp - ../include/boost/contract/constructor.hpp - ../include/boost/contract/destructor.hpp - ../include/boost/contract/function.hpp - ../include/boost/contract/old.hpp - ../include/boost/contract/override.hpp - ../include/boost/contract/public_function.hpp - - ../include/boost/contract/core/access.hpp - ../include/boost/contract/core/check_macro.hpp - ../include/boost/contract/core/config.hpp - ../include/boost/contract/core/constructor_precondition.hpp - ../include/boost/contract/core/exception.hpp - ../include/boost/contract/core/specify.hpp - ../include/boost/contract/core/virtual.hpp -: - "Reference" - # Quickbook's Doxygen does not show destructor exception specs. - PREDEFINED="BOOST_CONTRACT_DETAIL_DOXYGEN BOOST_PP_VARIADICS" - MACRO_EXPANSION=YES - INCLUDE_PATH="../include" - QUIET=YES - JAVADOC_AUTOBRIEF=YES - WARN_IF_UNDOCUMENTED=NO - EXCLUDE_SYMBOLS=std - # Following does not work for XML output... use @cond and/or - # #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN in code instead. - EXTRACT_PRIVATE=NO - HIDE_UNDOC_MEMBERS=YES - HIDE_UNDOC_CLASSES=YES - SHORT_NAMES=NO - ALIASES=" RefSect{2}=\"\\xmlonly\\2\\endxmlonly\" RefClass{1}=\"\\xmlonly\\1\\endxmlonly\" RefFunc{1}=\"\\xmlonly\\1\\endxmlonly\" RefMacro{1}=\"\\xmlonly\\1\\endxmlonly\" RefEnum{1}=\"\\xmlonly\\1\\endxmlonly\" " -; - -xml contract : main.qbk : reference ; - -boostbook doc : contract -: - html - boost.defaults=Boost - boost.root=../../ - admon.graphics.path=../../doc/src/images/ - html.stylesheet=../../doc/src/boostbook.css - toc.max.depth=1 -; - diff --git a/doc/acknowledgments.qbk b/doc/acknowledgments.qbk deleted file mode 100644 index 7d766aa3..00000000 --- a/doc/acknowledgments.qbk +++ /dev/null @@ -1,30 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Acknowledgments] - -This section aims to recognize the contributions of all the different people that participated directly or indirectly to the design and development of this library. - -Sincere thanks to my parents for their support with my education and my studies in computer science. - -Many thanks to Andrzej Krzemienski for reviewing early versions of this library providing valuable insights and exchanging early ideas on assertion requirements. - -Many thanks to Vicente J. Botet Escriba for reviewing earlier versions of this library providing valuable insights and for suggesting to use a dedicated trait to copy old values. - -Thanks to Steven Watanabe for providing valuable insights on C++, SFINAE, and introspection. - -Thanks to Dave Abrahams for moderating the Boost review of this library. - -Thanks to David Maley for sharing source code form his inspiring work on emulating Contract Programming and subcontracting in C++ in __Maley99__. - -Many thanks to Thorsten Ottosen for his work on the __N1962__ proposal (and its previous revisions) and for clarifying the proposal requirements directly with the library authors when needed. - -Many thanks to Bertrand Meyer for his pioneering and thorough work on Contract Programming in __Meyer97__. - -Finally, many thanks to the entire Boost community and [@http://lists.boost.org mailing list] for providing valuable comments on this library and great insights on the C++ programming language. - -[endsect] - diff --git a/doc/advanced.qbk b/doc/advanced.qbk deleted file mode 100644 index 46a79e57..00000000 --- a/doc/advanced.qbk +++ /dev/null @@ -1,484 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Advanced] - -This section is a guide to advanced usages of this library. - -[section Pure Virtual Public Functions] - -In C++, pure virtual functions are allowed to have a /default implementation/ as long as such implementation is programmed out-of-line so defined outside the class declaring the pure virtual function `virtual ... = 0;`. - -Contracts for pure virtual public functions are programmed using the [funcref boost::contract::public_function] function like for (non-pure) virtual public functions (all consideration made in __Virtual_Public_Functions__ apply). -However, contracts have to be programmed out-of-line, in the default implementation of the pure virtual function. -For example (see [@../../example/features/pure_virtual_public.cpp =pure_virtual_public.cpp=]): - -[import ../example/features/pure_virtual_public.cpp] -[pure_virtual_public_base_begin] -[pure_virtual_public_base_end] -[pure_virtual_public_base_impl] - -This library will never actually execute the pure virtual function body while it is calling the pure virtual function default implementation to check contracts for subcontracting. -Therefore, programmers can safely `assert(false)` at the beginning of the body if they intend for that body to never be executed (or they can program a working body in case they need to use C++ pure virtual function default implementation as usual with C++). - -[heading Subcontracting Preconditions Always True/False] - -As seen in __Public_Function_Overrides__, preconditions of overriding public functions are checked in __OR__ with preconditions of overridden virtual public functions. -Therefore, if a virtual public function in a base class specifies no precondition then preconditions specified by all its overriding functions in derived classes will have no effect (because when checked in __OR__ with the overridden function from the base class that has no preconditions, they will always pass). -This correctly reflects the fact that the overridden function in the base class can be called from any context (because it has no precondition) and so must all its overriding functions in all derived classes in accordance to the __substitution_principle__. -This is equivalent to declare the virtual public function in a base class with a single precondition `BOOST_CONTRACT_ASSERT(true)` that will always pass: - - // In a virtual public function of a base class. - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(true); // Prevent preconditions of overrides. - }) - ... - ; - -On the flip side, programmers might sometimes consider to declare a pure virtual public function in a base class with a single precondition `BOOST_CONTRACT_ASSERT(false)` that will always fail. -This indicates that the pure virtual public function can never be called unless it is redefined by a derived class (which is actually the case with C++ pure virtual functions) and also that the base class designers have intentionally left it up to derived classes to specify preconditions for the pure virtual function in question. -This technique might make sense only for preconditions of pure virtual public functions (otherwise `BOOST_CONTRACT_ASSERT(false)` will prevent calling virtual public functions in concrete bases). -For example (see [@../../example/features/named_override.cpp =named_override.cpp=]): - -[import ../example/features/named_override.cpp] -[named_override_pure_virtual_assert_false] - -That said, the need to declare such a precondition `BOOST_CONTRACT_ASSERT(false)` that will always fail might be an indication that the base class interface is not correctly designed. -In general, the base class interface should still contain all functions (eventually as pure virtual) that are necessary to program its contracts. - -[endsect] - -[section Optional Return Value] - -It is possible to use `boost::optional` to handle return values when programmers cannot construct the result variable at its point of declaration before the contract (e.g., because an appropriate constructor for the return type is not available at that point, or just because it would be too expensive to execute an extra initialization of the return value at run-time). -[footnote -*Rationale:* -`boost::optional` is used instead of `std::optional` because `std::optional` is not part of C++ standards prior to C++17. -] -For example (see [@../../example/features/optional_result.cpp =optional_result.cpp=]): - -[import ../example/features/optional_result.cpp] -[optional_result] - -In this example the return type is a reference so it does not have default constructor that can be used to initialize `result` when it is declared before the contract declaration. -In addition, `Index` needs to be validated to be smaller than `size()` by the precondition before it can be used to retrieve the reference to be assigned to `result` so `vect[Index]` cannot be used to initialize `result` when it is declared before the contract declaration. -Therefore, `boost::optional` is used to defer `result` proper initialization until the execution of the function body after the contract declaration when `Index` has been validated by the precondition and `vect[Index]` can be safely evaluated to initialize `result`. - -As seen in __Return_Value__, it is the responsibility of the programmers to ensure that `result` is always set to the return value (when the function exits without trowing an exception). -This also ensures that `result` is always set before the postconditions are checked so programmers can always dereference `result` in postconditions to access the return value (using `operator*` and `operator->` as usual with `boost::optional`, and without having to explicitly check if `result` is an empty `boost::optional` object or not). -This can be easily done by making sure that /all/ return statements in the function are of the form: - - boost::optional<...> result; - ... - return *(result = ...); // Assign `result` at each return. - -[heading Optional Results in Virtual Public Functions] - -Similarly, `boost::optional` can be used to handle the return value passed to contracts of virtual public functions (pure or not) and of public function overrides. -As seen in __Pure_Virtual_Public_Functions__, __Virtual_Public_Functions__, and __Public_Function_Overrides__, in these cases the return value `result` must be passed as a parameter to [funcref boost::contract::public_function] right after the parameter `v` of type [classref boost::contract::virtual_]`*`. -Then the functor passed to `.postcondition(...)` takes one single parameter of type `boost::optional<`[^['result-type]]` const&> const&`. -For example (see [@../../example/features/optional_result_virtual.cpp =optional_result_virtual.cpp=]): - -[import ../example/features/optional_result_virtual.cpp] -[optional_result_virtual] - -The inner `const&` in the postcondition functor parameter type `boost::optional<... const&> ...` is mandatory (while the outer `const&` in the postcondition functor parameter type `boost::optional<...> const&` is not). -[footnote -*Rationale:* -This library requires the postcondition functor parameter to be of type `boost::optional<... const&>` so the return value does not have to be copied (because of `&`) while postconditions are still not allowed to change its value (because of `const`, see __Constant_Correctness__). -In addition, programmers are encouraged to declare the postcondition functor to take its argument also as a constant reference `boost::optional<... const&> const&` to avoid possibly expensive copies of the `boost::optional` type. -] - -[endsect] - -[section Private and Protected Functions] - -Private and protected functions do not check class invariants (because they are not part of the public class interface) and they do not subcontract (because they are not accessible at the calling site where the __substitution_principle__ applies, see __Function_Calls__). -However, programmers may still want to specify preconditions and postconditions for private and protected functions when they want to check correctness of their implementation and usage from within the class, base classes, and friend classes or functions. -When programmers decide to specify contracts for private and protected functions, they shall use [funcref boost::contract::function] (like for non-member functions). -For example (see [@../../example/features/private_protected.cpp =private_protected.cpp=]): - -[import ../example/features/private_protected.cpp] -[private_protected] - -Considerations made in __Non_Member_Functions__ apply to private and protected functions as well. - -See __Constructors__ and __Destructors__ on how to program contracts for private and protected constructors and destructors instead. - -[heading Virtual Private and Protected Functions] - -When private and protected functions are virtual they should still declare the extra virtual parameter of type [classref boost::contract::virtual_]`*` with default value `0` (see __Virtual_Public_Functions__) even if that parameter does not have to be passed to [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::function] takes no argument (so the extra virtual parameter will remain unused and it does not need a name). -[footnote -Technically, the extra virtual parameter can still be passed to [macroref BOOST_CONTRACT_OLDOF] but that is not necessary and it has no effect so it is not done in this documentation. -] -That is necessary otherwise the private and protected virtual functions cannot be overridden by public functions in derived classes that specify contracts (because the [classref boost::contract::virtual_]`* = 0` parameter has to be part of signatures for public function overrides). -For example (see [@../../example/features/private_protected_virtual.cpp =private_protected_virtual.cpp=]): - -[import ../example/features/private_protected_virtual.cpp] -[private_protected_virtual_counter] - -However, public functions in derived classes overriding private or protected virtual functions from base classes shall not specify the extra `override_...` template parameter to [funcref boost::contract::public_function] because the overridden functions are private or protected and, not being public, they do not participate to subcontracting (this library will generate a compile-time error if `override_...` is specified because there will be no virtual public function to override from the base class). -For example (see [@../../example/features/private_protected_virtual.cpp =private_protected_virtual.cpp=]): - -[private_protected_virtual_counter10] - -Furthermore, using multiple inheritance it is possible to override functions that are private or protected from one base but public from another base. -In this case, public function overrides in derived classes will specify the extra `override_...` template parameter to [funcref boost::contract::public_function] (because the overridden functions are private or protected in one base and those do not participate to subcontracting, but public in another base and these participate to subcontracting instead). -For example (see [@../../example/features/private_protected_virtual_multi.cpp =private_protected_virtual_multi.cpp=]): - -[import ../example/features/private_protected_virtual_multi.cpp] -[private_protected_virtual_multi_countable] -[private_protected_virtual_multi_counter10] - -[warning -Unfortunately, the code above does not compile on MSVC (at least up to Visual Studio 2015) because MSVC incorrectly gives a compile-time error when SFINAE fails due to private or protected access levels. -Instead, GCC and Clang correctly implement SFINAE failures due to private and protected functions so the code above correctly complies on GCC and Clang. -Therefore, currently it is not possible to override a function that is public in one base but private or protected in other base using this library on MSVC, but that can be done on GCC or CLang instead. -] - -[endsect] - -[section Friend Functions] - -Friend functions are not member functions so [funcref boost::contract::function] can used to program contracts for them and all considerations made in __Non_Member_Functions__ apply. -For example (see [@../../example/features/friend.cpp =friend.cpp=]): - -[import ../example/features/friend.cpp] -[friend_byte] -[friend_bytes] - -However, in some cases a friend function might take an object as parameter and it can be logically considered an extension of that object's public interface (essentially at the same level as the object's public functions). -In these cases, programmers might chose to program the friend function contracts using [funcref boost::contract::public_function] (instead of [funcref boost::contract::function]) so to also check the class invariants of the object passed as parameter (and not just the pre- and postconditions of the friend function). -For example (see [@../../example/features/friend_invariant.cpp =friend_invariant.cpp=]): -[footnote -*Rationale:* -Contract programming proposals for C++ like __N1962__ do not provide a mechanism for friend functions to check class invariants of objects passed as parameters. -In other words, these proposals do not enable contracts to recognize that in C++ some friend functions logically act as if they were part of the public interface of the objects they take as parameters. -This is actually reasonable for proposals that add contracts to the core language because friend functions are not always meant to extend an object public interface and C++ does not provide a mechanism to programmatically specify when they do and when they do not. -However, this library adds the flexibility to let programmers manually specify when friend functions should also check class invariants of the objects they take as parameters (using [funcref boost::contract::public_function]) and when they should not (using [funcref boost::contract::function] instead). -] - -[import ../example/features/friend_invariant.cpp] -[friend_invariant] - -This technique can also be extended to friend functions that take multiple objects as parameters and can be logically considered extensions to the public interfaces of each of these objects. -For example: - - // Can be considered an extension of multiple objects' public interfaces. - friend void f(class1& object1, class2* object2, type3& value3) { - // Check preconditions. - boost::contract::check pre = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(object2 != nullptr); - ... - }) - ; - // Check class invariants for each object (programmers chose the order). - boost::contract::check inv1 = boost::contract::public_function(&object1); - boost::contract::check inv2 = boost::contract::public_function(object2); - // Check postconditions and exception guarantees. - boost::contract::check post_except = boost::contract::function() - .postcondition(...) - .except(...) - ; - - ... // Function body. - } - -Changing the order of the [classref boost::contract::check] declarations above, programmers can chose the order for checking class invariants among the different objects passed to the friend function and also whether to check these invariants before or after preconditions, postconditions, and exception guarantees at function entry and exit respectively (see __Non_Member_Functions__ and __Public_Functions__ for information on how the RAII objects returned by [funcref boost::contract::function] and [funcref boost::contract::public_function] check contract conditions). -The example above is programmed to check `class1` invariants before `class2` invariants (but the order could have been inverted if programmers so chose). - -[note -In the example above, preconditions are intentionally programmed to be checked before class invariants so the objects passed to the friend function can be validated by the preconditions before they are passed as pointers to [funcref boost::contract::public_function] (e.g., check `object2` is not null). -(Within member functions instead, the object pointer `this` is always well-formed, its validation is never needed, and [funcref boost::contract::public_function] checks class invariants before checking preconditions so programming preconditions can be simplified assuming the class invariants are satisfied already, see __Public_Function_Calls__.) -] - -[endsect] - -[section Function Overloads] - -As seen in __Public_Function_Overrides__, [funcref boost::contract::public_function] takes a pointer to the enclosing function as a parameter when used in public function overrides. -When names of public function overrides are overloaded, the function pointer cannot be automatically deduced by the compiler so programmers have to use `static_cast` to resolve ambiguities (as usual with pointers to overloaded functions in C++). -[footnote -*Rationale:* -In order to avoid copies, this library takes all function arguments and the return value passed to [funcref boost::contract::public_function] as references when used within public function overrides. -Therefore, the library cannot differentiate when the actual function argument and return types are passed by reference and when they are not. -As a result, the library cannot automatically reconstruct the type of the enclosing public function so this type must be deduced from the function pointer passed by programmers to [funcref boost::contract::public_function]. -When this automatic deduction is not possible due to overloaded function names, programmers must explicitly use `static_cast` to resolve ambiguities as usual in C++ with pointers to overloaded functions. -] -For example, note how `static_cast` is used in the following calls to [funcref boost::contract::public_function] (see [@../../example/features/overload.cpp =overload.cpp=]): - -[import ../example/features/overload.cpp] -[overload] - -Overloaded functions have the same function name so the same [^override_['function-name]] type can be reused as template parameter for all [funcref boost::contract::public_function] calls. -Therefore, [macroref BOOST_CONTRACT_OVERRIDE] only needs to be invoked once for any given function name even when that function name is overloaded. - -[endsect] - -[section Lambdas, Loops, Code Blocks (and `constexpr`)] - -While contracts are usually most useful to program specifications of functions and class interfaces, this library also allows to check contract conditions for implementation code (lambda functions, loops, code blocks, etc.). - -Lambda functions are not member functions, they are not part of class public interfaces so they do not check class invariants or participate int subcontracting. -They can use [funcref boost::contract::function] to specify preconditions, postconditions, and exception guarantees (considerations made in __Non_Member_Functions__ apply). -For example (see [@../../example/features/lambda.cpp =lambda.cpp=]): - -[import ../example/features/lambda.cpp] -[lambda] - -Similarly, [funcref boost::contract::function] can be used to program preconditions, postconditions, and exception guarantees for loops. -For example, for a for-loop but same for while- and all other loops (see [@../../example/features/loop.cpp =loop.cpp=]): - -[import ../example/features/loop.cpp] -[loop] - -More in general, [funcref boost::contract::function] can be used to program preconditions, postconditions, and exception guarantees of any block of code in a given function. -For example (see [@../../example/features/code_block.cpp =code_block.cpp=]): - -[import ../example/features/code_block.cpp] -[code_block] - -Finally, at the moment this library does not support contracts for functions and classes declared `constexpr`. -[footnote -*Rationale:* -In general, it might be useful to specify contracts for `constexpr` functions and literal classes. -However, the implementation of this library cannot support contracts for these functions and classes because C++ does not currently allow `constexpr` functions to do the following: -Declare local variables of (literal) types with non-trivial `constexpr` destructors (this RAII technique is used by this library to check invariants, postconditions, and exceptions guarantees at exit); -Call other `constexpr` functions using try-catch statements (used by this library to report contract assertion failures and catch any other exception that might be thrown when evaluating the asserted conditions); -Use lambda functions (used by this library for convenience to program functors that that check preconditions, postconditions, and exception guarantees). -Also note that even if supported, contracts for `constexpr` functions probably would not use old values (because `constexpr` prevents functions from having any side effect visible to the caller and variables recording such side-effects are usually the candidates for old value copies) and subcontracting (because `constexpr` functions cannot be virtual). -] - -[endsect] - -[section Implementation Checks] - -This library provides a mechanism to check assertions within implementation code outside of preconditions, postconditions, exceptions guarantees, and class invariants. -These implementation checks can be programmed using [macroref BOOST_CONTRACT_ASSERT] in a nullary functor that is directly assigned to [classref boost::contract::check] at the place within the code where the checks have to be executed (so without using [funcref boost::contract::function], [funcref boost::contract::public_function], etc.). -For example (see [@ ../../example/features/check.cpp =check.cpp=]): - -[import ../example/features/check.cpp] -[check_class] - -Alternatively, this library provides the [macroref BOOST_CONTRACT_CHECK] macro that allows to completely remove run- and compile-time overhead of implementation checks when [macroref BOOST_CONTRACT_NO_CHECKS] is defined. -For example (see [@ ../../example/features/check.cpp =check.cpp=]): - -[check_macro] - -(See __Disable_Contract_Checking__ and __Disable_Contract_Compilation__ for macros to completely remove run- and compile-time overhead of preconditions, postconditions, exception guarantees, and class invariants.) - -These implementation checks are essentially equivalent to using the C-style `assert` macro a part from the following: - -* A failure of the implementation checks will call [funcref boost::contract::check_failure] (see [funcref boost::contract::set_check_failure] and [funcref boost::contract::get_check_failure]). -* Implementation checks are automatically disabled when other contract conditions specified using this libraries are already being checked (to avoid infinite recursion, see [macroref BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION]). -* Implementation checks are disabled defining [macroref BOOST_CONTRACT_NO_CHECKS] (instead of `NDEBUG` for disabling `assert`). - -[endsect] - -[section Old Copies at Body] - -In the examples seen so far, old value variables of type [classref boost::contract::old_ptr] are initialized to a copy of the expression passed to [macroref BOOST_CONTRACT_OLDOF] at the point of their declaration. -This is correctly done before the function body is executed but it is also done before the contract is declared, therefore even before class invariants (for public functions) and preconditions are checked at function entry. - -This might work well in most cases, however in general old values should be copied before executing the function body but after checking entry class invariants and preconditions (see __Assertions__). -Specifically, there could be cases in which it makes sense to evaluate the expressions passed to [macroref BOOST_CONTRACT_OLDOF] only assuming that the assertions programmed in the class invariants and preconditions are first checked to be true. - -This library allows to construct [classref boost::contract::old_ptr] variables using their default constructor (equivalent to a null pointer) and then to assign them later to a copy of the expression passed to [macroref BOOST_CONTRACT_OLDOF] in a nullary functor [^['d]]`()` passed to `.old(`[^['d]]`)`. -The functor [^['d]]`()` is called by this library before the function body is executed but only after class invariants and preconditions are checked: -[footnote -*Rationale:* -Functors for preconditions, old value assignments, postconditions, and exception guarantees are all optional but when specified, they must be specified in that order. -Such order is enforced by the fact that [classref boost::contract::specify_precondition_old_postcondition_except], [classref boost::contract::specify_old_postcondition_except], [classref boost::contract::specify_postcondition_except], [classref boost::contract::specify_except], and [classref boost::contract::specify_nothing] provide a progressively decreasing subset of the `.precondition(...)`, `.old(...)`, `.postcondition(...)`, and `.except(...)` member functions. -The enforced order for specifying preconditions, old value assignments, postconditions, and exception guarantees makes logical sense because it follows the order at which these are executed at run-time. -Other contract programming frameworks allow to mix this order, that could have been implemented for this library as well but it would have complicated somewhat the library implementation while adding no real value (arguably creating confusion in user code by not enforcing a consistent order for specifying contract conditions). -] - - boost::contract::old_ptr<...> old_``[^['name]]``; // Default constructor (i.e., null pointer). - ... - boost::contract::guard c = boost::contract::function() // Same for all other contracts. - ... - .old([&] { // Capture by reference... - old_``[^['name]]`` = BOOST_CONTRACT_OLDOF(``[^['expression]]``); // ...but modify only old values. - ... - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(*old_``[^['name]]`` ...); // Never null here. - ... - }) - .except([&] { - BOOST_CONTRACT_ASSERT(*old_``[^['name]]`` ...); // Never null here. - ... - }) - ; - -For example, the following old value expression `s[index]` passed to [macroref BOOST_CONTRACT_OLDOF] is valid only after the precondition has checked that `index` is within valid range `index < s.size()`. -Therefore, `old_y` is first declared using its default constructor (i.e., initialized to a null pointer) and later assigned to a copy of `s[index]` in `.old(...)` after the precondition has checked `index` (see [@../../example/features/old.cpp =old.cpp=]): - -[import ../example/features/old.cpp] -[old] - -The functor passed to `.old(...)` should capture all variables it needs to evaluate to copy the old value expressions passed to [macroref BOOST_CONTRACT_OLDOF]. -In general, these variables should be captured by reference and not by value (because old values need to make copies of the values the captured variables will have just before executing the function body, and not copy the values these variables had when the functor passed to `.old(...)` was first declared). -In any case, the functor passed to `.old(...)` should modify only old values and not the values of other captured variables (see __Constant_Correctness__). - -This library will automatically call the failure handler [funcref boost::contract::old_failure] if calling the functor specified via `.old(...)` throws an exception (by default, this handler prints an error message to `std::cerr` and terminates the program calling `std::terminate`, but see __Throw_on_Failure__ to throw exceptions, exit the program with an error code, etc.). - -[note -If old value pointers are initialized at the point of their construction instead of using `.old(...)` then an exception thrown by the old value expression passed to [macroref BOOST_CONTRACT_OLDOF], or more in general any exception thrown by the old value pointer initialization, will result in that exception being thrown up the stack by the enclosing function. -This is arguably less correct than calling [funcref boost::contract::old_failure] because an exception thrown by an old value copy causes the program to fail checking its postconditions and exception guarantees but should not automatically causes the enclosing function to thrown an exception (this might not be a significant difference in practice, but it could be an additional reason to use `.old(...)` instead of copying old values when they are declared before the contract). -[footnote -*Rationale:* -It would be possible to wrap all old value operations ([classref boost::contract::old_ptr] copy constructor, [funcref boost::contract::make_old], etc.) in try-catch statements so this library will call [funcref boost::contract::old_failure] also when old values are copied when they are constructed outside `.old(...)`. -However, that will prevent this library from knowing the [enumref boost::contract::from] parameter and that would be problematic (specifically because destructors can have postconditions so that parameter is necessary to make sure user-defined failure handlers can be programmed to never throw from destructors as C++ usually requires). -] -] - -[endsect] - -[section Named Overrides] - -The function names passed to [macroref BOOST_CONTRACT_OVERRIDE] and [macroref BOOST_CONTRACT_OVERRIDES] should never start with an underscore to avoid generating names containing double underscores `override__...` (which are reserved by the C++ standard). -There is a separate macro [macroref BOOST_CONTRACT_NAMED_OVERRIDE] that can be used to explicitly specify the name of the type that will be passed to [funcref boost::contract::public_function] as a template argument: -[footnote -*Rationale:* -A different macro [macroref BOOST_CONTRACT_NAMED_OVERRIDE] is used instead of overloading [macroref BOOST_CONTRACT_OVERRIDE] using variadic macros because the override macros cannot be programmed manually by users so making it a variadic would prevent to use this library on compilers that do not support variadic macros (see __No_Macros__). -] - - BOOST_CONTRACT_OVERRIDE(``[^['function-name]]``) // Generate `override_...`. - BOOST_CONTRACT_NAMED_OVERRIDE(``[^['type-name]]``, ``[^['function-name]]``) // Generate `type-name`. - -For example, the following public function override is named `_1` so `BOOST_CONTRACT_OVERRIDE(_1)` would generate a type named `override__1` (which is reserved in C++ because it contains double underscores `__`), `BOOST_CONTRACT_NAMED_OVERRIDE(override1, _1)` is used to name the type `override1` instead (see [@../../example/features/named_override.cpp =named_override.cpp=]): - -[named_override] - -The [macroref BOOST_CONTRACT_NAMED_OVERRIDE] macro can also be used when the name `override_`[^['function-name]] generated by [macroref BOOST_CONTRACT_OVERRIDE] would clash with other names in user code, to generate names in CamelCase or in any other preferred style, and in any other case when programmers need or prefer to generate names different from `override_...`. - -Note that there is not a `BOOST_CONTRACT_NAMED_OVERRIDES` macro so [macroref BOOST_CONTRACT_NAMED_OVERRIDE] needs to be invoked separately on each function name (there is instead a [macroref BOOST_CONTRACT_OVERRIDES] macro as seen in __Public_Function_Overrides__). -[footnote -*Rationale:* -The syntax for invoking a possible `BOOST_CONTRACT_NAMED_OVERRIDES` macro would need to be something like `BOOST_CONTRACT_NAMED_OVERRIDES(`[^['type-name1]]`, `[^['function-name1]]`, `[^['type-name2]]`, `[^['function-name2]]`, ...)`. -The authors felt this syntax is less readable than repeating single `BOOST_CONTRACT_NAMED_OVERRIDE` invocations `BOOST_CONTRACT_NAMED_OVERRIDE(`[^['type-name1]]`, `[^['function-name1]]`) BOOST_CONTRACT_NAMED_OVERRIDE(`[^['type-name2]]`, `[^['function-name2]]`) ...` so decided not to provide the `BOOST_CONTRACT_NAMED_OVERRIDES` macro. -] - -[endsect] - -[section Access Specifiers] - -As we have seen so far, programmers are required to decorate their classes declaring extra members that are internally used by this library to check contracts: - -* The `invariant` and `static_invariant` member functions (used to check class invariants, see __Class_Invariants__). -* The `base_types` member type declared via [macroref BOOST_CONTRACT_BASE_TYPES] (used to implement subcontracting, see __Public_Function_Overrides__). -* The `override_...` member types declared via [macroref BOOST_CONTRACT_OVERRIDE], [macroref BOOST_CONTRACT_NAMED_OVERRIDE], and [macroref BOOST_CONTRACT_OVERRIDES] (used to implement subcontracting for overriding functions, see __Public_Function_Overrides__). -[footnote -*Rationale:* -The internals of the `override_...` type generated by [macroref BOOST_CONTRACT_OVERRIDE] use names reserved by this library so programmers should not actually use such a type even when it is declared `public`. -] - -In general, these members must be declared `public` in the user class in order for this library to be able to access them. -[footnote -There is some variability among compiler implementations: -The `base_types` member type needs to be declared `public` on MSVC, GCC, ang CLang; -The `invariant` and `static_invariant` member functions need to be declared `public` on MSVC, but not on GCC and CLang; -The `override_...` member types do not have to be declared `public` on any compiler. -In any case, declaring the [classref boost::contract::access] class `friend` allows to always declare all these extra members `private` on all compilers. -] -However, programmers might need to more precisely control the public members of their classes to prevent incorrect access of encapsulated members. -All these members can be declared `private` as long as the [classref boost::contract::access] class is declared as `friend` of the user class. -For example (see [@../../example/features/access.cpp =access.cpp=]): - -[import ../example/features/access.cpp] -[access] - -This technique is not used in most examples of this documentation only for brevity, but programmers are encouraged to use it in real code. - -[warning -Not declaring this class friend of user classes might cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible. -On other compilers (e.g., GCC and CLang), the private access will instead fail SFINAE and no compiler error will be reported while invariants and subcontracting will be silently skipped at run-time. -Therefore, programmers should always make sure to either declare invariant functions and base types `typedef` as public members or to declare the [classref boost::contract::access] class as friend. -] - -[endsect] - -[section Throw on Failure (and `noexcept`)] - -If a conditions checked using [macroref BOOST_CONTRACT_ASSERT] is evaluated to be `false` or more in general if any of the specified contract code throws an exception ([macroref BOOST_CONTRACT_ASSERT] simply expands to code that throws a [classref boost::contract::assertion_failure] exception, see __No_Macros__), this library will call an appropriate /contract failure handler/ function as follow: - -* Preconditions: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from within `.precondition(...)` call [funcref boost::contract::precondition_failure]. -* Postconditions: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from within `.postcondition(...)` call [funcref boost::contract::postcondition_failure]. -* Exceptions guarantees: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from within `.except(...)` call [funcref boost::contract::except_failure]. -* Class invariants: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from `invariant()` and `static_invariant()` call [funcref boost::contract::entry_invariant_failure] when checked at function entry and [funcref boost::contract::exit_invariant_failure] when checked at function exit. -* Old copies at body: Exceptions thrown from old value copies at body within `.old(...)` call [funcref boost::contract::old_failure]. -* Implementation checks: False [macroref BOOST_CONTRACT_ASSERT] assertions and exceptions thrown from implementation checks `boost::contract::check c = `[^['nullary-functor]] and [macroref BOOST_CONTRACT_CHECK] calls [funcref boost::contract::check_failure]. - -By default, these contract failure handlers print a message to the standard error `std::cerr` and then terminate the program calling `std::terminate`. -[footnote -*Rationale:* -In general, when a contract fails the only safe thing to do is to terminate program execution (because the contract failure indicates a bug in the program, and in general the program is in a state for which no operation can be successfully performed, so the program should be stopped). -Therefore, this library terminates the program by default. -However, for specific applications, programmers could implement some fail-safe mechanism for which some mission-critical operation could always be performed upon handling failures so this library allows programmers to override the default contract failure handlers to fully customize how to handle contract failures. -] -However, programmers can override the default contract failure handlers to perform any custom action on contract failure using the following functions respectively: - -* Preconditions: [funcref boost::contract::set_precondition_failure]. -* Postconditions: [funcref boost::contract::set_postcondition_failure]. -* Exception guarantees: [funcref boost::contract::set_except_failure]. -* Class invariants: [funcref boost::contract::set_entry_invariant_failure] and [funcref boost::contract::set_exit_invariant_failure], or [funcref boost::contract::set_invariant_failure] (to set both entry and exit invariant failure handlers at once for convenience). -* Old copies at body: [funcref boost::contract::set_old_failure]. -* Implementation checks: [funcref boost::contract::set_check_failure]. - -These `set_..._failure(`[^['f]]`)` function calls return the contract failure handler functor [^['f]] that they take as input parameter. -For example (see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]): -[footnote -*Rationale:* -Even if somewhat different from `std::set_terminate`, the `set_..._failure` functions take a functor as parameter (so to handle not just function pointers, but also lambdas, binds, etc.) and return this same functor as result (so they can be concatenated). -The related `get_..._failure` functions can be used to query the functors currently set as failure handlers. -] - -[import ../example/features/throw_on_failure.cpp] -[throw_on_failure_handlers] - -When programming custom failure handlers that trow exceptions instead of terminating the program, programmers should be wary of the following: - -* In order to comply with C++ and STL exception safety, destructors should never throw. -This library passes a [enumref boost::contract::from] parameter to the contract failure handlers for preconditions ([funcref boost::contract::precondition_failure]), postconditions ([funcref boost::contract::postcondition_failure]), class invariants ([funcref boost::contract::entry_invariant_failure] and [funcref boost::contract::exit_invariant_failure]), and old value copies at body ([funcref boost::contract::old_failure]). -This [enumref boost::contract::from] parameter indicates if the contract failure occurred in a destructor, constructor, or function call so programmers can use it to code custom contract failure hander functions that never throw from destructors. -(In the example above, contract failures from destructors are simply ignored even if that is probably never a safe thing to do in real code.) -* C++ stack-unwinding will execute base class destructors even when the derived class destructor trows an exception. -Therefore, the contracts of base class destructors will continue to be checked when contract failure handlers are programmed to throw exceptions on contract failures from destructors (yet another reason to not throw exception from destructors, not even for contract failures). -* Implementation checks can appear in any code, including destructor implementation code, so [funcref boost::contract::check_failure] should also never throw, or implementation checks should never be used in destructors (note that [funcref boost::contract::check_failure] does not provide the [enumref boost::contract::from] parameter so it is not possible to differentiate from implementation checks failing from destructors instead than from other parts of the code). -* The contract failure handler for exception guarantees [funcref boost::contract::except_failure] should also never throw (regardless of the value of its [enumref boost::contract::from] parameter) because when [funcref boost::contract::except_failure] is called there is already an active exception on the stack, the exception that triggered the exception guarantees to be checked in the first place (and throwing an exception while there is already an active exception will force C++ to terminate the program or lead to undefined behaviour). - -[note -It is the responsibility of the programmers to decide how to handle contract failures from destructors when they program custom contract failure handlers that throw exceptions instead of terminating the program (given that C++ and STL exception safety rules requires destructors to never throw). -This is not a simple dilemma and it might be a good reason to terminate the program instead of throwing exceptions when assertions fail in C++ (as this library and also C-style `assert` do by default). -] - -Contract assertions can be programmed to throw [classref boost::contract::assertion_failure] using [macroref BOOST_CONTRACT_ASSERT]`(`[^['condition]]`)` as we have seen so far (see __No_Macros__). -Alternatively, contract assertions can be programmed to throw any other exception (including user-defined exceptions) using code similar to the following: - - if(!``[^['condition]]``) throw ``[^['exception-object]]``; - -For example, if the following precondition functor throws the user-defined exception `too_large_error` then the contract failure handler [funcref boost::contract::precondition_failure] will be called (same as when preconditions programmed using [macroref BOOST_CONTRACT_ASSERT] fail, see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]): - -[throw_on_failure_class_begin] -[throw_on_failure_ctor] -[throw_on_failure_class_end] - -Finally, note that the exception specifiers `noexcept` (since C++11) and `throw` (deprecated in C++11) of the enclosing operation declaring the contract correctly apply to the contract code as well. -Therefore, even if the contract failure handlers are reprogrammed to throw exceptions in case of contract failures, those exceptions will never be thrown outside the context of the enclosing operation if that is not in accordance with the exception specifiers of that operation (e.g., note that all destructors are implicitly declared `noexcept` in C++11). -For example, the following code will correctly never throw from the `noexcept` destructor, not even if the class invariants checked at destructor entry throw `too_large_error` and the contract failure handlers for invariants are programmed to throw from destructors (the program will always terminate in this case instead, see [@../../example/features/throw_on_failure.cpp =throw_on_failure.cpp=]): - -[throw_on_failure_class_begin] -[throw_on_failure_dtor] -[throw_on_failure_class_end] -[throw_on_failure_bad_handler] - -[endsect] - -[endsect] - diff --git a/doc/bibliography.qbk b/doc/bibliography.qbk deleted file mode 100644 index a20d36b2..00000000 --- a/doc/bibliography.qbk +++ /dev/null @@ -1,112 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Bibliography] - -This section lists all references consulted while designing and developing this library. - -[#Andrzej13_anchor] [Andrzej13] A. Krzemienski. [@https://akrzemi1.wordpress.com/2013/01/04/preconditions-part-i/ /Andrzej's C++ blog: Preconditions/]. 2013. - -[#Bright04_anchor] [Bright04] W. Bright. [@http://www.digitalmars.com/d/2.0/dbc.html /Contract Programming for the D Programming Language/]. 2004. - -[#Bright04b_anchor] [Bright04b] W. Bright. [@http://www.digitalmars.com/ctg/contract.html /Contract Programming for the Digital Mars C++ Compiler/]. 2004. - -[#C2_anchor] [C2] Aechmea. [@http://www.programmersheaven.com/app/news/DisplayNews.aspx?NewsID=3843 /C^2 Contract Programming add-on for C++/]. 2005. - -[#Chrome_anchor] [Chrome] RemObjects. [@http://blogs.remobjects.com/blogs/mh/2008/05/01/p216 /Chrome: Contract Programming for Object Pascal in .NET/]. 2002. - -[#Clarke06_anchor] [Clarke06] L. A. Clarke and D. S. Rosenblum. [@http://discovery.ucl.ac.uk/4991/1/4991.pdf /A Historical Perspective on Runtime Assertion Checking in Software Development/]. Newsletter ACM SIGSOFT Software Engineering Notes, 2006. - -[#Cline90_anchor] [Cline90] M. Cline and D. Lea. /The Behaviour of C++ Classes/ and [@http://surface.syr.edu/cgi/viewcontent.cgi?article=1116&context=eecs /Using Annotated C++/]. Proc. of the Symposium on Object Oriented Programming Emphasizing Practical Applications, Maris College, 1990. - -[#Ellis90_anchor] [Ellis90] M. A. Ellis and B. Stroustrup. /The Annotated C++ Reference Manual/. ANSI Base Document, Addison Wesley, 1990. - -[#Gautron92_anchor] [Gautron92] P. Gautron. /An Assertion Mechanism Based on Exceptions/. Fourth C++ Technical Conference, 1992. - -[#Hoare73_anchor] [Hoare73] C. A. R. Hoare. /Hints on Programming Language Design/. Stanford University Artificial Intelligence memo AIM-224/STAN-CS-73-403, pages 193-216, 1973. - -[#CodeContracts_anchor] [CodeContracts] Microsoft Research. [@http://research.microsoft.com/en-us/projects/contracts/ /Code Contracts: Design-By-Contract Programming for All .NET Programming Languages/]. 2012. - -[#iContract_anchor] [iContract] O. Enseling. [@http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-cooltools.html /iContract: Contract Programming for Java/]. 2001. - -[#Jcontract_anchor] [Jcontract] Parasoft. [@http://www.parasoft.com/jsp/products/article.jsp?label=product_info_Jcontract /Jcontract: Contract Programming for Java/]. - -[#Lindrud04_anchor] [Lindrud04] J. Lindrud. [@http://www.codeproject.com/Articles/8293/Design-by-Contract-in-C /Design by Contract in C++/]. 2004. - -[#Maley99_anchor] [Maley99] D. Maley and I. Spence. [@http://www.computer.org/portal/web/csdl/doi/10.1109/TOOLS.1999.779000 /Emulating Design by Contract in C++/]. Proceedings of TOOLS, IEEE Computer Society, 1999. - -[#Meyer97_anchor] [Meyer97] B. Meyer. /Object Oriented Software Construction/. Prentice-Hall, 2nd edition, 1997. - -[#Mitchell02_anchor] [Mitchell02] R. Mitchell and J. McKim. /Design by Contract, by Example/. Addison-Wesley, 2002. - -[#N1613_anchor] [N1613] T. Ottosen. [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1613.pdf /Proposal to add Design by Contract to C++/]. The C++ Standards Committee, N1613, 2004. - -[#N1653_anchor] [N1653] C. Nelson. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm /Working draft changes for C99 preprocessor synchronization/]. C++ Standards Committee, N1653, 2004. - -[#N1669_anchor] [N1669] T. Ottosen. [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1669.html /Proposal to add Contract Programming to C++ (revision 1)/]. The C++ Standards Committee, N1669, 2004. - -[#N1773_anchor] [N1773] D. Abrahams, L. Crowl, T. Ottosen, and J. Widman. [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1773.html /Proposal to add Contract Programming to C++ (revision 2)/]. The C++ Standards Committee, N1773, 2005. - -[#N1866_anchor] [N1866] L. Crowl and T. Ottosen. [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1866.html /Proposal to add Contract Programming to C++ (revision 3)/]. The C++ Standards Committee, N1866, 2005. - -[#N1895_anchor] [N1895] H. Sutter and F. Glassborow. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1895.pdf /Delegating Constructors (revision 2)/]. C++ Standards Committee, N1895, 2005. - -[#N1962_anchor] [N1962] L. Crowl and T. Ottosen. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1962.html /Proposal to add Contract Programming to C++ (revision 4)/]. The C++ Standards Committee, N1962, 2006. - -[#N2081_anchor] [N2081] D. Gregor and B. Stroustrup. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf /Concepts (revision 1)/]. The C++ Standards Committee, N2081, 2006. - -[#N2887_anchor] [N2887] G. Dos Reis, B. Stroustrup, and A. Meredith. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2887.pdf /Axioms: Semantics Aspects of C++ Concepts/]. The C++ Standards Committee, N2887, 2009. - -[#N2914_anchor] [N2914] P. Becker. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2914.pdf /Working Draft, Standard for Programming Language C++/]. The C++ Standards Committee, N2914, 2009. - -[#N2906_anchor] [N2906] B. Stroustrup. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2906.pdf /Simplifying the sue of concepts/]. The C++ Standards Committee, N2906, 2009. - -[#N3248_anchor] [N3248] J. Lakos. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3248.pdf ['[^noexcept] Prevents Library Validation]]. The C++ Standards Committee, N3248, 2011. - -[#N4154_anchor] [N4154] D. Krauss. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4154.pdf ['Operator [^assert]]]. The C++ Standards Committee, N4154, 2014. - -[#N4160_anchor] [N4160] A. Krzemienski. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4160.html /Value constraints/]. The C++ Standards Committee, N4160, 2014. - -[#N4248_anchor] [N4248] A. Meredith. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4248.html /Library Preconditions are a Language Feature/]. The C++ Standards Committee, N4248, 2014. - -[#N4293_anchor] [N4293] J. D. Garcia. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4293.pdf /C++ language support for contract programming/]. The C++ Standards Committee, N4293, 2014. - -[#N4378_anchor] [N4378] J. Lakos, N. Myers, A. Zakharov, and A. Beels. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4378.pdf /Language Support for Contract Assertions (Revision 10)/]. The C++ Standards Committee, N4378, 2015. - -[#Nana_anchor] [Nana] P. J. Maker. [@https://github.com/pjmaker/nana /GNU Nana/]. 2014. - -[#N4379_anchor] [N4378] J. Lakos and N. Myers. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4379.pdf /FAQ about Contract Assertions/]. The C++ Standards Committee, N4379, 2015. - -[#N4435_anchor] [N4435] W. E. Brown. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4435.pdf /Proposing Contract Attributes/]. The C++ Standards Committee, N4435, 2015. - -[#P0147_anchor] [P0147] L. Crowl. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0147r0.html /The Use and Implementation of Contracts/]. The C++ Standards Committee, P0147R0, 2015. - -[#P0166_anchor] [P0166] J. D. Garcia. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0166r0.pdf /Three interesting questions about contracts/]. The C++ Standards Committee, P0166R0, 2015. - -[#P0246_anchor] [P0246] N. Myers. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0246r0.pdf /Criteria for Contract Support Merged Proposal/]. The C++ Standards Committee, P0246R0, 2016. - -[#P0287_anchor] [P0287] G. Dos Reis, J.D. Garcia, F. Logozzo, M. Fahndrich, S. Lahiri. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0287r0.pdf /Simple Contracts for C++ (R1)/]. The C++ Standards Committee, P0287R0, 2016. - -[#P0380_anchor] [P0380] G. Dos Reis, J.D. Garcia, J. Lakos, A. Meredith, N. Myers, and B. Stroustrup. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0380r1.pdf /A Contract Design/]. The C++ Standards Committee, P0380R1, 2016. - -[#P0542_anchor] [P0542] G. Dos Reis, J.D. Garcia, J. Lakos, A. Meredith, N. Myers, and B. Stroustrup. [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0542r0.html /Support for contract based programming in C++/]. The C++ Standards Committee, P0542R0, 2017. - -[#Rosenblum95_anchor] [Rosenblum95] D. S. Rosenblum. [@http://www.cs.toronto.edu/~chechik/courses06/csc410/rosenblum_assert95.pdf /A practical Approach to Programming With Assertions/]. IEEE Transactions on Software Engineering, 1995. - -[#SPARKAda_anchor] [SPARKAda] Praxis. [@http://www.praxis-his.com/sparkada/language.asp /SPARKAda (Ada-like Language with Contract Programming)/]. - -[#SpecSharp_anchor] [SpecSharp] Microsoft. [@http:://research.microsoft.com/en-us/projects/specsharp/ /Spec# (C# Extension)/]. - -[#Stroustrup94_anchor] [Stroustrup94] B. Stroustrup. /The Design and Evolution of C++/. Addison Wesley, 1994. - -[#Stroustrup13_anchor] [Stroustrup13] B. Stroustrup. /The C++ Programming Language/. Addison Wesley, 4th Edition, 2013. - -[#Tandin04_anchor] [Tandin04] A. Tandin. [@http://www.codeproject.com/KB/macros/DbC_and_Doxygen.aspx /Design by Contract macros for C++ and link to Doxygen/]. 2004. - -[#Wilson06_anchor] [Wilson06] M. Wilson. [@http://www.artima.com/cppsource/deepspace.html /Contract Programming 101 - The Nuclear Reactor and the Deep Space Probe/]. The C++ Source, 2006. - -[endsect] - diff --git a/doc/contract_programming_overview.qbk b/doc/contract_programming_overview.qbk deleted file mode 100644 index 01caa815..00000000 --- a/doc/contract_programming_overview.qbk +++ /dev/null @@ -1,679 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Contract Programming Overview] - -[:['["It is absurd to make elaborate security checks on debugging runs, when no trust is put in the results, and then remove them in production runs, when an erroneous result could be expensive or disastrous. What would we think of a sailing enthusiast who wears his life-jacket when training on dry land but takes it off as soon as he goes to sea?]]] -[:['-- Charles Antony Richard Hoare (see __Hoare73__)]] - -This section gives an overview of Contract Programming (see __Meyer97__, __Mitchell02__, and __N1613__ for more detailed introductions to Contract Programming). -Readers that already have a basic understanding of Contract Programming can skip this section and maybe come back to it after reading the __Tutorial__. - -[note -The objective of this library is not to convince programmers to use Contract Programming. -It is assumed that programmes understand the benefits and trade-offs associated with Contract Programming and they have already decided to use this methodology in their code. -Then, this library aims to be the best and more complete Contract Programming library for C++ (that does not use preprocessors and other tools external to the C++ preprocessor and language itself). -] - -[section Assertions] - -Contract Programming is characterized by the following assertion mechanisms: - -* /Preconditions/: These are logical conditions that programmers expect to be true when a function is called (e.g., to check constraints on function arguments). -Operations that logically have no preconditions (i.e., that are always well-defined for the entire domain of their inputs) are often referred to as having a /wide contract/. -This is in contrast to operations that have preconditions which are often referred to as having a /narrow contract/ (note that operations with truly narrow contracts should not even throw exceptions). -[footnote -The nomenclature of wide and narrow contracts has gained some popularity in recent years in the C++ community (appearing in a number of more recent proposals to add contract programming to the C++ standard, see __Bibliography__). -This nomenclature is perfectly reasonable but it is not often used in this document because the authors generally prefer to explicit mention "this operation has no preconditions..." or "this operation has preconditions...". -] -* /Postconditions/: These are logical conditions that programmers expect to be true when a function exits without throwing an exception (e.g., to check the result and any side effect that a function might have). -Postconditions can access the function return value (for non-void functions) and /old values/ that expressions had before the function body was executed. -* /Exception guarantees/: These are logical conditions that programmers except to be true when a function exits throwing an exception. -Exceptions specifications can access old values (but not the function return value). -[footnote -*Rationale:* -Contract assertions for exception guarantees were first introduced by this library (even if exception safety guarantees have long been part of C++ STL documentation). -Contract assertions for exception safety guarantees are not part of __N1962__ or other references listed in the __Bibliography__. -] -* /Class invariants/: These are logical conditions that programmers expect to be true after a constructor exits without throwing an exception, before and after the execution of every non-static public non-static function (even if they throw exceptions), before the destructor is executed and if the destructor throws an exception (i.e., class invariants define valid states for all objects of a given class). -It is possible to specify a different set of class invariants for volatile public functions, namely /volatile class invariants/. -It is also possible to specify /static class invariants/ which are excepted to be true before and after the execution of any constructor, destructor (even if it does not throw an exception), and public function (even if static). -[footnote -*Rationale:* -Static and volatile class invariants were first introduced by this library to reflect the fact that C++ supports both static and volatile public functions. -Static and volatile class invariants are not part of __N1962__ or other references listed in the __Bibliography__. -] -* /Subcontracting/: This indicates that preconditions cannot be strengthen, while postconditions and class invariants cannot be weaken when a public function in a derived class overrides public functions in one or more of its base classes (this is formally defined according to the __substitution_principle__). - -Class invariants can also be used to specify /basic/ exception safety guarantees for an object (because they are checked at exit of public functions even when those throw an exception), while contract assertions for exception guarantees can be used to specify /strong/ exception safety guarantees for given operations on the same object. - -It is also a common requirement for Contract Programming to automatically disable contract checking while already checking assertions from another contract (in order to avoid infinite recursion while checking contract assertions). - -[note -This library implements this requirement but in order to globally disable assertions while checking another assertion some kind of global arbitrating variable needs to be used by this library implementation. -This library will automatically protect such a global variable from race conditions in multi-threated programs, but this will effectively introduce a global lock in the program (the [macroref BOOST_CONTRACT_DISABLE_THREADS] macro can be defined to disable this global lock but at the risk of incurring in race conditions). -[footnote -*Rationale:* -[macroref BOOST_CONTRACT_DISABLE_THREADS] is named after `BOOST_DISABLE_THREADS`. -] -] - -In general, it is recommended to specify different contract conditions using separate assertion statements and not to group them together into a single condition using logical operators (`&&`, `||`, etc.). -This is because when contract conditions are programmed together in a single assertion using logical operators, it is not be clear which condition actually failed in case the entire assertion fails at run-time. - -[heading C-Style Assertions] - -A limited form of Contract Programming is the use of the C-style `assert` macro. -Using `assert` is common practice for many programmers but it suffers of the following limitations: - -* `assert` does not distinguish between preconditions and postconditions. -In well-tested production code, postconditions can usually be disabled trusting the correctness of the implementation while preconditions might still need to remain enabled because of possible changes in the calling code (e.g., postconditions of a given library could be disabled after testing while its preconditions can be kept enabled given the library cannot predict the evolution of user code that will be calling it). -Using `assert` it is not possible to selectively disable only postconditions and all assertions must be disabled at once. -* `assert` requires to manually program extra code to check class invariants (extra member functions, try blocks, etc.). -* `assert` does not support subcontracting. -* `assert` calls are usually scattered within function implementations thus the asserted conditions are not immediately visible in their entirety by programmers (as they are instead when the assertions appear in the function declaration or at least at the very top of function definition). - -Contract Programming does not suffers of these limitations. - -[endsect] - -[section Benefits and Costs] - -[heading Benefits] - -The main use of Contract Programming is to improve software quality. -__Meyer97__ discusses how Contract Programming can be used as the basic tool to write ["correct] software. -__Stroustrup94__ discusses the key importance of class invariants plus advantages and disadvantages of preconditions and postconditions. -The following is a short summary of the benefits associated with Contract Programming inspired mainly by __N1613__: - -* Preconditions and postconditions: -Using function preconditions and postconditions, programmers can give a precise semantic description of what a function requires at its entry and what it ensures at its exit (if it does not throw an exception). -In particular, using postcondition old values, Contract Programming provides a mechanism that allows programmers to compare values of an expression before and after the function body execution. -This mechanism is powerful enough to enable programmers to express many correctness constraints within the code itself, constraints that would otherwise have to be captured at best only informally by documentation. -* Class invariants: -Using class invariants, programmers can describe what to expect from a class and the logic dependencies between the class members. -It is the job of the constructor to ensure that the class invariants are satisfied when the object is first created. -Then the implementation of the member functions can be largely simplified as they can be written knowing that the class invariants are satisfied because Contract Programing checks them before and after the execution of every public function. -Finally, the destructor makes sure that the class invariants held for the entire life of the object checking the class invariants one last time before the object is destructed. -Class invariants can also be used as a criterion for good abstraction: If it is not possible to specify an invariant, it might be an indication that the design abstraction maybe be poor and it should not have been made into a class. -* Self-documenting code: -Contracts are part of the source code, they are checked at run-time so they are always up-to-date with the code itself. -Therefore program specifications, as documented by the contracts, can be trusted to always be up-to-date with the implementation. -* Easier debugging: -Contract Programming can provide a powerful debugging facility because, if contracts are well written, bugs will cause contract assertions to fail exactly where the problem first occurs instead than at some later stage of the program execution in an apparently unrelated (and often hard to debug) manner. -Note that a precondition failure points to a bug in the function caller, a postcondition failure points instead to a bug in the function implementation. -[footnote -Of course, if contracts are ill-written then Contract Programming is of little use. -However, it is less likely to have a bug in both the function body and the contract than in the function body only. -For example, consider the validation of a result in postconditions. -Validating the return value might seem redundant, but in this case we actually want that redundancy. -When programmers write a function, there is a certain probability that they make a mistake in implementing the function body. -When programmers specify the result of the function in the postconditions, there is also a certain probability that they make a mistake in writing the contract. -However, the probability that programmers make a mistake twice (in both the body /and/ the contract) is in general lower than the probability that the mistake is made just once (in either the body or the contract). -] -* Easier testing: -Contract Programming facilitates testing because a contract naturally specifies what a test should check. -For example, preconditions of a function state which inputs cause the function to fail and postconditions state which outputs are produced by the function on successful exit (Contract Programming should be seen as a tool to complement, but obviously not to replace, testing). -* Formal design: -Contract Programming can serve to reduce the gap between designers and programmers by providing a precise and unambiguous specification language in terms of the contract assertions. -Moreover, contracts can make code reviews easier by clarifying some of the semantics and usage of the code. -* Formalized inheritance: -Contract Programming formalizes the virtual function overriding mechanism using subcontracting as justified by the __substitution_principle__. -This keeps the base class programmers in control as overriding functions always have to fully satisfy the contracts of their base classes. -* Replace Defensive Programming: -Contract Programming assertions can replace [@http://en.wikipedia.org/wiki/Defensive_programming Defensive Programming] checks localizing these checks within the contract and making the code more readable. - -Of course, not all formal contract specifications can be asserted in C++. -For example, in C++ is it not possible to assert the validity of an iterator range in the general case because the only way to check if two iterators form a valid range is to keep incrementing the first iterator until we reach the second iterator. -However, in case the iterator range is invalid, such a code would render undefined behaviour or run forever instead of failing an assertion. -Nevertheless, a large amount of contract assertions can be successfully programmed in C++ as illustrated by the numerous examples in this documentation and from the literature (for example see how much of STL [link N1962_vector_anchor `vector`] contract assertions can actually be programmed in C++ using this library). - -[heading Costs] - -In general, Contract Programming benefits come at the cost of performance as discussed in detail by both __Stroustrup94__ and __Meyer97__. -While performance trade-offs should be carefully considered depending on the specific application domain, software quality cannot be sacrificed: It is difficult to see value in software that quickly and efficiently provides incorrect results. - -The run-time performances are negatively impacted by Contract Programming mainly because of extra time require to: - -* Check the asserted conditions. -* Copy old values when these are used in postconditions and exception guarantees. -* Call additional functors that check preconditions, postconditions, exception guarantees, class invariants, etc. (especially for subcontracting). - -[note -In general, contracts introduce at least three extra functor calls to check preconditions, postconditions, and exception guarantees for any given non-member function call. -Public functions introduce also two more function calls to check class invariants (at entry and at exit). -For subcontracting, these extra calls (some of which become virtual calls) are repeated for the number of functions being overridden from the base classes (possibly deep in the inheritance tree). -In addition to that, this library introduces a number of function calls internal to its implementation in order to properly check the contracts. -] - -To mitigate the run-time performance impact, programmers can selectively disable run-time checking of some of the contract assertions. -Programmers will have to decide based on the performance trade-offs required by their applications, but a reasonable approach often is to (see __Disable_Contract_Checking__): - -* Always write contracts to clarify the semantics of the design embedding the specifications directly in the code and making the code self-documenting. -* Check preconditions, postconditions, class invariants, and maybe even exception guarantees during initial testing. -* Only check preconditions (and maybe class invariants, but not postconditions and exception guarantees) during release testing and for the final release. - -This approach is usually reasonable because in well-tested production code, validating the function body implementation using postconditions is rarely needed since the function has shown itself to be ["correct] during testing. -On the other hand, checking function arguments using preconditions is always needed because of changes that can be made to the calling code (without having to necessarily re-test and re-release the called code). -Furthermore, postconditions and also exception guarantees, with related old value copies, are often computationally more expensive to check than preconditions and even class invariants. - -[endsect] - -[section Function Calls] - -[heading Non-Member Functions] - -A call to a non-member function with a contract executes the following steps (see [funcref boost::contract::function]): - -# Check function preconditions. -# Execute the function body. -# If the body did not throw an exception, check function postconditions. -# Else, check function exception guarantees. - -[heading Private and Protected Functions] - -In Contract Programming, private and protected functions do not have to satisfy the class invariants because these functions are part of the class implementation and not of the class public interface. -Furthermore, the __substitution_principle__ does not apply to private and protected functions because these functions are not accessible to the user at the calling site where the __substitution_principle__ applies. - -Therefore, calls to private and protected functions with contracts execute the same steps as the ones indicated above for non-member functions (checking only preconditions and postconditions, but without checking class invariants and without subcontracting). - -[endsect] - -[section Public Function Calls] - -[heading Overriding Public Functions] - -Let's consider a public function in a derived class that overrides public virtual functions declared in a number of its public base classes (because of C++ multiple inheritance, the function could override from more than one base class). -We refer to the function in the derived class as the /overriding function/, and to the set of base classes containing all the /overridden functions/ as /overridden bases/. - -When subcontracting, overridden functions are searched (at compile-time) deeply in the public branches of the inheritance tree (i.e., not just the derived class's direct public parents are inspected, but also all its public grandparents, etc.). -In case of multiple inheritance this search also extends widely to all multiple public base classes following their order of declaration in the derived class inheritance list (as usual in C++, this search could result in multiple overridden functions and therefore in subcontracting from multiple public base classes). -Note that only public base classes are considered for subcontracting because private and protected base classes are not accessible to the user at the calling site where the __substitution_principle__ applies. - -A call to the overriding public function with a contract executes the following steps (see [funcref boost::contract::public_function]): - -# Check static class invariants __AND__ non-static class invariants for all overridden bases, __AND__ then check the derived class static __AND__ non-static invariants. -# Check preconditions of overridden public functions from all overridden bases in __OR__ with each other, __OR__ else check the overriding function preconditions in the derived class. -# Execute the overriding function body. -# Check static class invariants __AND__ non-static class invariants for all overridden bases, __AND__ then check the derived class static __AND__ non-static invariants (even if the body threw an exception). -# If the body did not throw an exception, check postconditions of overridden public functions from all overridden bases in __AND__ with each other, __AND__ then check the overriding function postconditions in the derived class. -# Else, check exception guarantees of overridden public functions from all overridden bases in __AND__ with each other, __AND__ then check the overriding function exception guarantees in the derived class. - -Volatile public functions check static class invariants __AND__ /volatile/ class invariants instead. -Preconditions and postconditions of volatile public functions and volatile class invariants access the object as `volatile`. - -Class invariants are checked before preconditions and postconditions so programming precondition and postcondition assertions can be simplified assuming that class invariants are satisfied already (e.g., if class invariants assert that a pointer cannot be null then preconditions and postconditions can safety dereference that pointer without additional checking). -Similarly, subcontracting checks contracts of public base classes before checking the derived class contracts so programming derived class contract assertions can be simplified by assuming that public base class contracts are satisfied already. - -[note -[#and_anchor] [#or_anchor] -In this documentation __AND__ and __OR__ indicate the logic /and/ and /or/ operations evaluated in /short-circuit/. -For example: `p` __AND__ `q` is true if and only if both `p` and `q` are true, but `q` is never evaluated when `p` is false; `p` __OR__ `q` is true if and only if either `p` or `q` are true, but `q` is never evaluated when `p` is true. - -As indicated by the steps above and in accordance with the __substitution_principle__, subcontracting checks preconditions in __OR__ while class invariants, postconditions, and exceptions guarantees in __AND__ with preconditions, class invariants, postconditions, and exceptions guarantees of base classes. -] - -[heading Non-Overriding Public Functions] - -A call to a non-static public function with a contract (that does not override functions from any of the public base classes) executes the following steps (see [funcref boost::contract::public_function]): - -# Check class static __AND__ non-static invariants (but none of the invariants from base classes). -# Check function preconditions (but none of the preconditions from functions in base classes). -# Execute the function body. -# Check the class static __AND__ non-static invariants (even if the body threw an exception, but none of the invariants from base classes). -# If the body did not throw an exception, check function postconditions (but none of the postconditions from functions in base classes). -# Else, check function exception guarantees (but none of the exception guarantees from functions in base classes). - -Volatile public functions check static class invariants __AND__ /volatile/ class invariants instead. -Preconditions and postconditions of volatile functions and volatile class invariants access the object as `volatile`. - -Class invariants are checked because this function is part of the class public interface. -However, none of the contracts of the base classes are checked because this function does not override any functions from any of the public base classes (so the __substitution_principle__ does not require to subcontract in this case). - -[heading Static Public Functions] - -A call to a static public function with a contract executes the following steps (see [funcref boost::contract::public_function]): - -# Check static class invariants (but not the non-static invariants and none of the invariants from base classes). -# Check function preconditions (but none of the preconditions from function in base classes). -# Execute the function body. -# Check static class invariants (even if the body threw an exception, but not the non-static invariants and none of the invariants from base classes). -# If the body did not throw an exception, check function postconditions (but none of the postconditions from functions in base classes). -# Else, check function exception guarantees (but none of the exception guarantees from functions in base classes). - -Class invariants are checked because this function is part of the class public interface, but only static class invariants can be checked (because this is a static function so it cannot access the object that would instead be required to check non-static class invariants, volatile or not). -Furthermore, static functions cannot override any function so the __substitution_principle__ does not apply and they do not subcontract. - -Preconditions and postconditions of static functions and static class invariants cannot access the object (because they are checked from `static` member functions). - -[endsect] - -[section Constructor Calls] - -A call to a constructor with a contract executes the following steps (see [classref boost::contract::constructor_precondition] and [funcref boost::contract::constructor]): - -# Check constructor preconditions (but these cannot access the object because the object is not constructed yet). -# Execute the constructor member initialization list (if present). - # Construct any base class (public or not) according with C++ construction mechanism and also check the contracts of these base constructors (according with steps similar to the ones listed here). -# Check static class invariants (but not the non-static or volatile class invariants, because the object is not constructed yet). -# Execute the constructor body. -# Check static class invariants (even if the body threw an exception). -# If the body did not throw an exception: - # Check non-static __AND__ volatile class invariants (because the object is now successfully constructed). - # Check constructor postconditions (but these cannot access the object old value [^['oldof]]`(*this)` because there was no object before the execution of the constructor body). -# Else, check constructor exception guarantees (but these cannot access the object old value [^['oldof]]`(*this)` because there was no object before the execution of the constructor body, plus they can only access class static members because the object was not successfully constructed upon the constructor body throwing an exception). - -Constructor preconditions are checked before executing the member initialization list so programming these initializations can be simplified assuming the constructor preconditions are satisfied (e.g., constructor arguments can be validated by the constructor preconditions before they are used to initialize base classes and data members). - -As indicated in step 2.a. above, C++ object construction mechanism will automatically check base class contracts when these bases are initialized (no explicit subcontracting behaviour is required here). - -[endsect] - -[section Destructor Calls] - -A call to a destructor with a contract executes the following steps (see [funcref boost::contract::destructor]): - -# Check static class invariants __AND__ non-static __AND__ volatile class invariants. -# Execute the destructor body (destructors have no parameters and they can be called at any time after object construction so they have no preconditions). -# Check static class invariants (even if the body threw an exception). -# If the body did not throw an exception: - # Check destructor postconditions (but these can only access class static members and the object old value [^['oldof]]`(*this)` because there is no object after successful execution of the destructor body). -[footnote -*Rationale:* -Postconditions for destructors are not part of __N1962__ or other references listed in the __Bibliography__ (but with respect to __Meyer97__ it should be noted that Eiffel does not support static data members and that might by why destructors do not have postconditions in Eiffel). -However, in principle there could be uses for destructor postconditions so this library supports postconditions for destructors (e.g., a class that counts object instances could use destructor postconditions to assert that an instance counter stored in a static data member is decreased by `1` because the object has been destructed). -] - # Destroy any base class (public or not) according with C++ destruction mechanism and also check the contracts of these base destructors (according with steps similar to the ones listed here). -# Else (even if destructors should rarely, if ever, be allowed to throw exceptions in C++): - # Check non-static class invariants (because the object was not successfully destructed so it still exists and should satisfy its invariants). - # Check destructor exception guarantees. - -As indicated in step 4.b. above, C++ object destruction mechanism will automatically check base class contracts when the destructor exits without throwing an exception (no explicit subcontracting behaviour is required here). - -[note -Given that C++ allows destructors to throw, this library handles the case when the destructor body throws an exception as indicated above. -However, in order to comply with STL exception safety guarantees and good C++ programming practices, programmers should implement destructor bodies to rarely, if ever, throw exceptions (in fact destructors are declared `noexcept` by default in C++11). -] - -[endsect] - -[section Constant-Correctness] - -Contracts should not be allowed to modify the program state because they are only responsible to check (and not to change) the program state in order to verify its compliance with the specifications. -Therefore, contracts should only have access to the object, function arguments, function return value, old values, and all other program variables in `const` context (via `const&`, `const* const`, `const volatile`, etc.). - -Whenever possible (e.g., class invariants and postcondition old values), this library automatically enforces this constant-correctness constraint at compile-time using `const`. -However, this library cannot automatically enforce this constraint in all cases (for preconditions and postconditions of mutable member functions, for global variables, etc.). -See __No_Lambda_Functions__ for ways of using this library that always and automatically enforce the constant-correctness constraint at compile-time (but these methods require a significant amount of boiler-plate code to be programmed manually so they are not recommended in general). - -[important -In general, it is the responsibility of the programmers to code assertions that only check, and do not change, program variables. -[footnote -Note that also when using C-style `assert` it is the responsibility of the programmers to code assertions that only check and do not change program variables. -] -] - -[endsect] - -[section Specification vs. Implementation] - -Contracts are part of the program specification and not of its implementation. -Therefore, contracts should ideally be programmed within C++ declarations, and not within definitions. - -In general, this library cannot satisfy this requirement. -However, even when the contracts are programmed together with the body in the function definition, it is still very easy for users to identify and read just the contract portion of the function definition (because the contract code must always be programmed at the very top of the function definition). -See __Separate_Body_Implementation__ for ways of using this library to program contract specifications outside of the body implementation but at the cost of writing one extra function for any given function (for applications were this requirement is truly important). - -Furthermore, contracts are most useful when they assert conditions only using public members (in most cases, the need for using non-public members to check contracts, especially in preconditions, indicates an error in the class design). -For example, the caller of a public function cannot in general make sure that the function preconditions are satisfied if the precondition assertions use private members that are not callable by the caller (therefore, a failure in the preconditions will not necessarily indicate a bug in the caller given that the caller was made unable to fully check the preconditions in the first place). - -However, given that C++ provides programmers ways around access level restrictions (`friend`, function pointers, etc.), this library leaves it up to the programmers to make sure that only public members are used in contract assertions (especially in preconditions). (__N1962__ follows the same approach not restricting contracts to only use public members, Eiffel instead generates a compile-time error if preconditions are asserted using non-public members.) -[footnote -*Rationale:* -If C++ [@http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#45 defect 45] had not been fixed, this library could have been implemented so to generate a compile-time error when precondition assertions use non-public members more similarly to Eiffel's implementation (but not necessary the best approach for C++). -] - -[endsect] - -[section On Contract Failure] - -If precondition, postcondition, exception guarantee, or class invariant assertions are either checked to be false or their evaluation throws an exception at run-time then this library will call specific /failure handler functions/. - -By default, these failure handler functions print a message to the standard error `std::cerr` (with detailed information about the failure) and then terminate the program calling `std::terminate`. -However, using [funcref boost::contract::set_precondition_failure], [funcref boost::contract::set_postcondition_failure], [funcref boost::contract::set_except_failure], [funcref boost::contract::set_invariant_failure], etc. programmers can define their own failure handler functions that can take any user-specified action (throw an exception, exit the program with an error code, etc., see __Throw_on_Failure__). -[footnote -*Rationale:* -This customizable failure handling mechanism is similar to the one used by C++ `std::terminate` and also to the one proposed in __N1962__. -] - -[note -In C++ there are a number of issues with programming contract failure handlers that throw exceptions instead of terminating the program. -Specifically, destructors check class invariants so they will throw if programmers change class invariant failure handlers to throw instead of terminating the program, but in general destructors should not throw in C++ (to comply with STL exception safety, etc.). -Furthermore, programming an exception guarantee failure handler to throw will throw an exception (the one reporting the contract failure) while there is already an active exception (the one that caused the exception guarantees to be checked in the first place), and this will force C++ to terminate the program anyway. -] - -Therefore, it is recommended to terminate the program at least for contract failures from destructors and exception guarantees (if not in all other cases of contract failures as it is done by default by this library). -The contract failure handler functions programmed using this library have information about the failed contract (preconditions, postconditions, etc.) and the operation that was checking the contract (constructor, destructor, etc.) so programmers can granularly distinguish all cases and decide when it is appropriate to terminate, throw, or take some other user-specific action. - -[endsect] - -[section Feature Summary] - -The Contract Programming features supported by this library are largely based on __N1962__ and on the Eiffel programming language. -The following table compares Contract Programming features among this library, __N1962__ (unfortunately the C++ standard committee rejected this proposal commenting on a general lack of need for adding Contract Programming to C++ at the time, even if __N1962__ itself is sound), a more recent proposal __P0380__ (which unfortunately only supports preconditions and postconditions, but does not support class invariants, old values, and subcontracting), the Eiffel and D programming languages: - -[table -[ - [Feature] - [This Library] - [__N1962__ Proposal (not accepted in C++)] - [__P0380__ Proposal (being considered for C++2x)] - [ISE Eiffel 5.4 (see __Meyer97__)] - [D (see __Bright04__)] -][ - [['Keywords and specifiers]] - [ -Specifiers: `precondition`, `postcondition`, `invariant`, `static_invariant`, and `base_types`. -The last three specifiers appear in user code so their names can be referred to or changed using [macroref BOOST_CONTRACT_INVARIANT], [macroref BOOST_CONTRACT_STATIC_INVARIANT], and [macroref BOOST_CONTRACT_BASES_TYPEDEF] macros respectively to avoid name clashes. - ] - [Keywords: `precondition`, `postcondition`, `oldof`, and `invariant`.] - [Attributes: `[[expects]]` and `[[ensures]]`.] - [Keywords: =require=, =require else=, =ensure=, =ensure then=, =old=, =result=, =do=, and =invariant=.] - [Keywords: =in=, =out=, =assert=, and =invariant=.] -][ - [['On contract failure]] - [Print an error to `std::cerr` and call `std::terminate` (but can be customized to throw exceptions, exit with an error code, etc.).] - [Call `std::terminate` (but can be customized to throw exceptions, exit with an error code, etc.).] - [Call `std::abort` (but can be customized to throw exceptions, exit with an error code, etc.).] - [Throw exceptions.] - [Throw exceptions.] -][ - [['Result value in postconditions]] - [Yes, captured by or passed as a parameter to (for virtual functions) the postcondition functor.] - [Yes, `postcondition(`[^['result-variable-name]]`)`.] - [Yes, `[[ensures `[^['result-variable-name]]`: ...]]`.] - [Yes, =result= keyword.] - [No.] -][ - [['Old values in postconditions]] - [ -Yes, [macroref BOOST_CONTRACT_OLD] macro and [classref boost::contract::old_ptr] (but copied before preconditions unless `.old(...)` is used as shown in __Old_Copies_at_Body__). -For templates, [classref boost::contract::old_ptr_if_copyable] skips old value copies for non-copyable types and [funcref boost::contract::condition_if] skips old value copies selectively based on old expression type requirements. - ] - [ -Yes, `oldof` keyword (copied after preconditions and before body). -(Never skipped, not even in templates for non-copyable types.) -] - [No.] - [ -Yes, =old= keyword (copied after preconditions and before body). -(Never skipped, but all types are copyable in Eiffel.) -] - [No.] -][ - [['Class invariants]] - [ -Checked at constructor exit, at destructor entry and throw, and at public function entry, exit, and throw. -Same for volatile class invariants. -Static class invariants checked at entry and exit of constructor, destructor, and any (also `static`) public function. - ] - [ -Checked at constructor exit, at destructor entry and throw, and at public function entry, exit, and throw. -(Volatile and static class invariants not supported.) -] - [No.] - [ -Checked at constructor exit, and around public functions. -(Volatile and static class invariants do not apply to Eiffel.) - ] - [ -Checked at constructor exit, at destructor entry, and around public functions. -(Volatile and static class invariants not supported, `volatile` was deprecated all together in D.) - ] -][ - [['Subcontracting]] - [ -Yes, also supports subcontracting for multiple inheritance ([macroref BOOST_CONTRACT_BASE_TYPES], [macroref BOOST_CONTRACT_OVERRIDE], and [classref boost::contract::virtual_] are used for declaring base classes, overriding and virtual public functions respectively). -] - [ -Yes, also supports subcontracting for multiple inheritance but only preconditions only in base classes. -[footnote -*Rationale:* -The authors of __N1962__ decided to forbid derived classes from subcontracting preconditions because they found that such a feature was rarely, if evet, used (see [@http://lists.boost.org/Archives/boost/2010/04/164862.php Re: \[boost\] \[contract\] diff n1962]). -Still, it should be noted that even in __N1962__ if a derived class overrides two functions with preconditions coming from two different base classes via multiple inheritance, the overriding function contract will check preconditions from its two base class functions in __OR__ (so even in __N1962__ preconditions can indirectly subcontract when multiple inheritance is used). -The authors of this library found that confusing about __N1962__. -Furthermore, subcontracting preconditions is soundly defined by the __substitution_principle__ so this library allows to subcontract preconditions as Eiffel does (users can always avoid using this feature if they have no need for it). -(This is essentially the only feature for which this library deliberately differ from __N1962__.) -] - ] - [No.] - [Yes.] - [Yes.] -][ - [['Contracts for pure virtual functions]] - [Yes (but they must be programmed in out-of-line functions as always in C++ with pure virtual function definitions).] - [Yes.] - [No (because no subcontracting).] - [Yes (contracts for abstract functions).] - [No (but planned).] -][ - [['Arbitrary code in contracts]] - [Yes (but users are generally recommended to only program assertions using [macroref BOOST_CONTRACT_ASSERT] and if-guard statements within contracts to avoid introducing bugs and expensive code in contracts, and also to only use public functions to program preconditions).] - [No, assertions only.] - [No, assertions only. In addition only public members can be used in preconditions.] - [No, assertions only. In addition only public members can be used in preconditions.] - [Yes.] -][ - [['Constant-correctness]] - [Enforced only for class invariants and old values (making also preconditions and postconditions constant-correct is possible but requires users to program a fare amount of boiler-plate code).] - [Yes.] - [Yes.] - [Yes.] - [No.] -][ - [['Contracts in specifications or implementation]] - [Implementation (unless programmers manually write an extra function for any given function).] - [Specification (function declaration).] - [Specification (function declaration).] - [Specification.] - [Specification.] -][ - [['Function code ordering]] - [Preconditions, postconditions, exception guarantees, body.] - [Preconditions, postconditions, body.] - [Preconditions, postconditions, body.] - [Preconditions, body, postconditions.] - [Preconditions, postconditions, body.] -][ - [['Disable assertion checking within assertions checking (to avoid infinite recursion when checking contracts)]] - [ -Yes, but use [macroref BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION] to disable no assertion while checking preconditions (see [macroref BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION]). -[footnote -*Rationale:* -Theoretically, it can be shown that an incorrect argument might be passed to the function body when assertion checking is disabled while checking preconditions (see [@http://lists.boost.org/Archives/boost/2010/04/164862.php Re: \[boost\] \[contract\] diff n1962]). -Therefore, __N1962__ does not disable any assertion while checking preconditions. -However, that makes it possible to have infinite recursion while checking preconditions, plus Eiffel disables assertion checking also while checking preconditions. -Therefore, this library by default disables assertion checking also while checking preconditions, but it also provides the [macroref BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION] configuration macro so users can change this behaviour if needed. -] -(In multi-threaded programs this introduces a global lock, see [macroref BOOST_CONTRACT_DISABLE_THREADS].) - ] - [Yes for class invariants and postconditions, but preconditions disable no assertion.] - [No.] - [Yes.] - [No.] -][ - [['Nested member function calls]] - [ -Disable nothing. -[footnote -*Rationale:* -Older versions of this library defined a data member in the user class that was automatically used to disable checking of class invariants within nested member function calls (similarly to Eiffel). -This feature was also required by older revisions of __N1962__ but it is no longer required by __N1962__. -Furthermore, in multi-threaded programs this feature would introduce a lock that synchronizes all member functions calls for a given object. -Therefore, this feature was removed in the current revision of this library. -] - ] - [Disable nothing.] - [Disable nothing.] - [Disable all contract assertions.] - [Disable nothing.] -][ - [['Disable contract checking]] - [Yes, contract checking can be skipped at run-time by defining combinations of the [macroref BOOST_CONTRACT_NO_PRECONDITIONS], [macroref BOOST_CONTRACT_NO_POSTCONDITIONS], [macroref BOOST_CONTRACT_NO_INVARIANTS], [macroref BOOST_CONTRACT_NO_ENTRY_INVARIANTS], and [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS] macros (completely removing contract code from compiled object code is possible but requires using macros shown in __Disable_Contract_Compilation__).] - [Yes (contract code also removed from compiled object code, but details are compiler-implementation specific).] - [Yes (contract code also removed from compiled object code, but details are compiler-implementation specific).] - [Yes, but only predefined combinations of preconditions, postconditions, and class invariants can be disabled (contract code also removed from compiled object code).] - [Yes.] -][ - [['Assertion levels]] - [Yes, predefined default, audit, and axiom plus programmers can define their own levels.] - [No (but a previous revision of this proposal considered adding assertion levels called "assertion ordering").] - [Yes, predefined default, audit, and axiom.] - [No.] - [No.] -] -] - -The authors of this library also consulted the following references that implemented Contract Programming for C++ (but usually for only a limited set of features, or using preprocessing tools other than the C++ preprocessor and external to the language itself) or for languages other than C++ (see __Bibliography__ for a complete list of all the references consulted in the design and development of this library): - -[table -[ [Reference] [Language] [Notes] ] -[ [__Bright04b__] [C++] [ -The Digital Mars C++ compiler extends C++ adding Contract Programming language support (among many other features). -] ] -[ [__Lindrud04__] [C++] [ -This supports class invariants and old values but it does not support subcontracting (contracts are specified within definitions instead of declarations and assertions are not constant-correct). -] ] -[ [__Tandin04__] [C++] [ -Interestingly, these contract macros automatically generate Doxygen documentation -[footnote -*Rationale:* -Older versions of this library also automatically generated Doxygen documentation from contract definition macros. -This functionality was abandoned for a number of reasons: this library no longer uses macros to program contracts; even before that, the implementation of this library macros became too complex and the Doxygen preprocessor was no longer able to expand them; the Doxygen documentation was just a repeat of the contract code (so programmers could directly look at contracts in the source code); Doxygen might not necessarily be the documentation tool used by all C++ programmers. -] -but old values, class invariants, and subcontracting are not supported (plus contracts are specified within definitions instead of declarations and assertions are not constant-correct). -] ] -[ [__Maley99__] [C++] [ -This supports Contract Programming including subcontracting but with limitations (e.g., programmers need to manually build an inheritance tree using artificial template parameters), it does not use macros but programmers are required to write by hand a significant amount of boiler-plate code. -(The authors have found this work very inspiring when developing initial revisions of this library especially for its attempt to support subcontracting.) -] ] -[ [__Nana__] [C++] [ -This uses macros but it only works on GCC (and maybe Clang, but it does not work on MSVC, etc.). -It does not support subcontracting. -It requires extra care to program postconditions for functions with multiple return statements. -It seems that it might not check class invariants when functions throw exceptions (unless the `END` macro does that...). -(In addition, it provides tools for logging and integration with GDB.) -] ] -[ [__C2__] [C++] [ -This uses an external preprocessing tool (the authors could no longer find this project's code to evaluate it). -] ] -[ [__iContract__] [Java] [ -This uses an external preprocessing tool. -] ] -[ [__Jcontract__] [Java] [ -This uses an external preprocessing tool. -] ] -[ [__CodeContracts__] [.NET] [ -Microsoft Contract Programming for .NET programming languages. -] ] -[ [__SpecSharp__] [C#] [ -This is a C# extension with Contract Programming language support. -] ] -[ [__Chrome__] [Object Pascal] [ -This is the .NET version of Object Pascal and it has language support for Contract Programming. -] ] -[ [__SPARKAda__] [Ada] [ -This is an Ada-like programming language with support for Contract Programming. -] ] -] - -To the best knowledge of the authors, this the only library that fully supports all Contract Programming features for C++. -Generally speaking: - -* Implementing preconditions and postconditions in C++ is not difficult (e.g., using some kind of RAII object). -* Implementing postcondition old values is also not too difficult usually requiring programmers to copy old values into local variables, but it is already somewhat more difficult to ensure such copies are not performed when postconditions are disabled. -[footnote -For example, the following emulation of old values based on __P0380__ never disables old value copies plus requires boiler-plate code to make sure postconditions are correctly checked in a `scope_exit` RAII object after all other local objects have been destroyed (because some of these destructors contribute to establishing the postconditions) and only if the function did not throw an exception: -`` - void fswap(file& x, file& y) - [[expects: x.closed()]] - [[excepts: y.closed()]] - // Postconditions in function definition below to emulate old values. - { - file old_x = x; // Emulate old values with local copies (not disabled). - file old_y = y; - scope_exit ensures([&] { // Check after local objects destroyed. - if(!std::uncaught_exception()) { // Check only if no throw. - [[assert: x.closed()]] - [[assert: y.closed()]] - [[assert: x == old_y]] - [[assert: y == old_x]] - } - }); - - x.open(); - scope_exit close_x([&] { x.close(); }); - y.open(); - scope_exit close_y([&] { y.close(); }); - file t = file::temp(); - t.open; - scope_exit close_t([&] { t.close(); }); - - x.mv(t); - y.mv(x); - t.mv(y); - } -`` -Here `scope_exit` is an RAII object that executes the nullary functor passed to its constructor when it is destroyed. -] - -* Implementing class invariants is more involved (especially if done automatically, without requiring programmers to manually invoke extra functions to check the invariants). -[footnote -For example, the following possible emulation of class invariants based on __P0380__ requires boiler-plate code to manually invoke the function that checks the invariants (note that invariants are checked at public function exit regardless of exceptions being thrown while postconditions are not): -`` - template - class vector { - bool invariant() const { // Check invariants at... - [[assert: empty() == (size() == 0)]] - [[assert: size() <= capacity()]] - return true; - } - - public: - vector() - [[ensures: invariant()]] // ...constructor exit (only if no throw). - { ... } - - ~vector() noexcept - [[expects: invariant()]] // ...destructor entry. - { ... } - - void push_back(T const& value) - [[expects: invariant()]] // ...public function entry. - [[ensures: invariant()]] // ...public function exit (if no throw). - try { - ... // Function body. - } catch(...) { - invariant(); // ...public function exit (if throw). - throw; - } - - ... - }; -`` -In case the destructor can throw (e.g., it is declared `noexcept(false)`), the destructor also requires a `try-catch` statement similar to the one programmed for `push_back` to check class invariants at destructor exit when it throws exceptions. -] -All references reviewed by the authors seem to not consider static and volatile functions not supporting static and volatile invariants respectively. - -* Implementing subcontracting involves a significant amount of complexity and it seems to not be properly supported by any C++ library other than this one (especially when handling multiple inheritance, correctly copying postcondition old values across all overridden contracts deep in the inheritance tree, and correctly reporting the return value to the postconditions of overridden virtual functions in base classes). -[footnote -For example, it is not really possible to sketch pseudocode based on __P0380__ that emulates subcontracting in the general case. -] - -[endsect] - -[endsect] - diff --git a/doc/examples.qbk b/doc/examples.qbk deleted file mode 100644 index 57a3f9ed..00000000 --- a/doc/examples.qbk +++ /dev/null @@ -1,172 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Examples] - -This section lists some examples taken from different sources discussing Contract Programming and implemented here using this library. - -[note -Some of these examples might be from old code, containing obsolete coding practices, not optimized for execution speed, not complete, and they might be more relevant in the context of programming languages different from C++. -Nevertheless, programmers are encouraged to review these examples to see a few diverse usages of this library that might be relevant to their needs. -] - -Sources of the listed examples: - -* __N1962__: Examples from the proposal to add Contract Programming to C++11 (unfortunately, this proposal was never accepted into the standard). -* __Meyer97__: Examples using the Eiffel programming language and reprogrammed using this library for C++. -* __Mitchell02__: Additional examples using the Eiffel programming language and reprogrammed using this library for C++. -* __Cline90__: Examples from a very early proposal called Annotated C++ (A++) to add Contract Programming to C++ (A++ was never implemented or proposed for addition to the standard). - -A few notable examples: - -* [link N1962_vector_anchor \[N1962\] Vector]: Complete contracts for `std::vector` and a comparison with __N1962__ syntax. -* [link N1962_square_root_anchor \[N1962\] Square Root]: Comparison with D syntax. -* [link Mitchell02_counter_anchor \[Mitchell02\] Counter]: Subcontracting. -* [link Meyer97_stack4_anchor \[Meyer97\] Stack4]: Comparison with Eiffel syntax. -* [link Cline90_vector_anchor \[Cline90\] Vector]: Comparison with A++ syntax. - -[#N1962_vector_anchor] -[section \[N1962\] Vector: Contracts for STL vector and comparison with C++11 proposal syntax] - -On compilers that support C++17 `if constexpr`, the following example using this library can be simplified removing [funcref boost::contract::condition_if] and related functor templates such as `all_of_equal_to`, etc. (making it more similar to the pseudo-code on the right-hand side). - -[import ../example/n1962/vector.cpp] -[import ../example/n1962/vector_n1962.hpp] -[table - [ [This library] [\[N1962\] proposal (not accepted in C++) plus C++17 [^if constexpr]] ] - [ [[n1962_vector]] [[n1962_vector_n1962]] ] -] - -[endsect] - -[section \[N1962\] Circle: Subcontracting] -[import ../example/n1962/circle.cpp] -[n1962_circle] -[endsect] - -[#N1962_factorial_anchor] -[section \[N1962\] Factorial: Recursion] -[import ../example/n1962/factorial.cpp] -[n1962_factorial] -[endsect] - -[section \[N1962\] Equal: Operators] -[import ../example/n1962/equal.cpp] -[n1962_equal] -[endsect] - -[section \[N1962\] Sum: Array parameter] -[import ../example/n1962/sum.cpp] -[n1962_sum] -[endsect] - -[#N1962_square_root_anchor] -[section \[N1962\] Square Root: Default parameters and comparison with D syntax] -[import ../example/n1962/sqrt.cpp] -[import ../example/n1962/sqrt.d] -[table - [ [This Library] [The D Programming Language] ] - [ [[n1962_sqrt]] [[n1962_sqrt_d]] ] -] -[endsect] - -[#Meyer97_stack4_anchor] -[section \[Meyer97\] Stack4: Comparison with Eiffel syntax] -[import ../example/meyer97/stack4.hpp] -[import ../example/meyer97/stack4_main.cpp] -[import ../example/meyer97/stack4.e] -[table - [ [This Library] [The Eiffel Programming Language] ] - [ [[meyer97_stack4]] [[meyer97_stack4_e]] ] - [ [[meyer97_stack4_main]] [] ] -] -[endsect] - -[section \[Meyer97\] Stack3: Error codes instead of preconditions] -[import ../example/meyer97/stack3.cpp] -[meyer97_stack3] -[endsect] - -[section \[Mitchell02\] Name List: Relaxed subcontracts] -[import ../example/mitchell02/name_list.cpp] -[mitchell02_name_list] -[endsect] - -[section \[Mitchell02\] Dictionary: Key-value map] -[import ../example/mitchell02/dictionary.cpp] -[mitchell02_dictionary] -[endsect] - -[section \[Mitchell02\] Courier: Subcontracting and static class invariants] -[import ../example/mitchell02/courier.cpp] -[mitchell02_courier] -[endsect] - -[section \[Mitchell02\] Stack: Stack-like container] -[import ../example/mitchell02/stack.cpp] -[mitchell02_stack] -[endsect] - -[section \[Mitchell02\] Simple Queue: Queue-like container and disable old value copies for audit assertions] -[import ../example/mitchell02/simple_queue.cpp] -[mitchell02_simple_queue] -[endsect] - -[section \[Mitchell02\] Customer Manager: Contracts instead of Defensive Programming] -[import ../example/mitchell02/customer_manager.cpp] -[mitchell02_customer_manager] -[endsect] - -[section \[Mitchell02\] Observer: Pure virtual functions] -[import ../example/mitchell02/observer/observer.hpp] -[mitchell02_observer] -[import ../example/mitchell02/observer/subject.hpp] -[mitchell02_subject] -[import ../example/mitchell02/observer_main.cpp] -[mitchell02_observer_main] -[endsect] - -[#Mitchell02_counter_anchor] -[section \[Mitchell02\] Counter: Subcontracting] -[import ../example/mitchell02/counter/push_button.hpp] -[mitchell02_push_button] -[import ../example/mitchell02/counter/decrement_button.hpp] -[mitchell02_decrement_button] -[import ../example/mitchell02/counter/counter.hpp] -[mitchell02_counter] -[import ../example/mitchell02/counter_main.cpp] -[mitchell02_counter_main] -[endsect] - -[#Cline90_vector_anchor] -[section \[Cline90\] Vector: Comparison with A++ proposal syntax] -[import ../example/cline90/vector.hpp] -[import ../example/cline90/vector_main.cpp] -[import ../example/cline90/vector_axx.hpp] -[table - [ [This Library] [A++ Proposal (never actually implemented)] ] - [ [[cline90_vector]] [[cline90_vector_axx]] ] - [ [[cline90_vector_main]] [] ] -] -[endsect] - -[section \[Cline90\] Stack: Stack-like container] -[import ../example/cline90/stack.cpp] -[cline90_stack] -[endsect] - -[section \[Cline90\] Vector-Stack: Subcontracting] -[import ../example/cline90/vstack.cpp] -[cline90_vstack] -[endsect] - -[section \[Cline90\] Calendar: A very simple calendar] -[import ../example/cline90/calendar.cpp] -[cline90_calendar] -[endsect] - -[endsect] - diff --git a/doc/extras.qbk b/doc/extras.qbk deleted file mode 100644 index 6c6761df..00000000 --- a/doc/extras.qbk +++ /dev/null @@ -1,612 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Extras] - -This section can be consulted selectively for specific topics of interest. - -[section Old Value Requirements (Templates)] - -Old values require to copy the expression passed to [macroref BOOST_CONTRACT_OLDOF] thus the type of that expression must be copyable. -More precisely, dereferencing an old value pointer of type [classref boost::contract::old_ptr]`` requires [classref boost::contract::is_old_value_copyable]`::value` to be `true` (otherwise this library will generate a compile-time error). - -In some cases it might be acceptable, or even desirable, to cause a compile-time error when a program uses old value types that are not copyable (because it is not possible to fully check the correctness of the program as stated by the contract assertions that use these old values). -In these cases, programmers can declare old values using [classref boost::contract::old_ptr] as seen so far. - -However, in some other cases it might be desirable to skip assertions that use old values when the respective old value types are not copyable. -Programmers can do this by using [classref boost::contract::old_ptr_if_copyable] instead of [classref boost::contract::old_ptr] to program these old values and by checking if the old value pointer is not null before dereferencing it in postconditions. -For example, consider the following function template that could in general be instantiated for types `T` that are not copy constructible (that is for which [classref boost::contract::is_old_value_copyable]`::value` is `false`, see [@../../example/features/old_if_copyable.cpp =old_if_copyable.cpp=]): -[footnote -*Rationale:* -__N1962__ and other proposals to add contracts to C++ do not provide a mechanism to selectively disable copies for only old value types that are not copy constructible. -However, this library provides such a mechanism to allow to program contracts for template code without necessarily adding extra copy constructible type requirements that would not be present if it were not for copying the old values (so compiling the code with and without contracts will not necessarily alter the type requirements of the program). -Something similar could be achieved combing C++17 `if constexpr` with __N1962__ or __P0380__ so that old value expressions within template code could be guarded by `if constexpr` statements checking if the old value types are copyable or not. -For example, assuming old values are added to __P0380__ (e.g., via `oldof`) and that C++17 `if constexpr` can be used within __P0380__ contracts: -`` - template - void offset(T& x, int count) - [[ensures: if constexpr(std::is_copy_constructible::value) x == oldof(x) + count]] - ... -`` -] - -[import ../example/features/old_if_copyable.cpp] -[old_if_copyable_offset] - -The old value pointer `old_x` is programmed using [classref boost::contract::old_ptr_if_copyable] so if `T` is not copyable then `x` will simply not be copied and `old_x` will be left as a null pointer (here `old_x` must be checked to be not null `if(old_x) ...` before it is dereferenced in postconditions and exception guarantees). -If the above example used [classref boost::contract::old_ptr] instead then the library would have generated a compile-time error when `offset` is instantiated with types `T` that are not copy constructible (but only if `old_x` is actually dereferenced somewhere in the contract assertions using `*old_x ...`, `old_x->...`, etc.). - -When C++11 `auto` declarations are used with [macroref BOOST_CONTRACT_OLDOF], this library always defaults to using the [classref boost::contract::old_ptr] type (because this type requirements are more stringent, if programmers want to relax the copyable type requirement they must do so explicitly by using [classref boost::contract::old_ptr_if_copyable] instead of using `auto`). -For example, the following will use [classref boost::contract::old_ptr] and not [classref boost::contract::old_ptr_if_copyable] to declare `old_x`: - - auto old_x = BOOST_CONTRACT_OLDOF(x); // C++11 auto declarations always use `old_ptr` (never `old_ptr_if_copyable`). - -This library internally uses [classref boost::contract::is_old_value_copyable] to determine if an old value type is copyable or not, and then [classref boost::contract::old_value_copy] to actually copy the old value. -By default, [classref boost::contract::is_old_value_copyable]`` is equivalent to `boost::is_copy_constructible` and [classref boost::contract::old_value_copy]`` is implemented using `T`'s copy constructor. -However, these type traits can be specialized by programmers for example to avoid making old value copies of types even when they have a copy constructor (maybe because these copy constructors are too expensive), or to make old value copies for types that do not have a copy constructor, or for any other specific need programmers might have for the types in question. -For example, the following specialization of [classref boost::contract::is_old_value_copyable] intentionally avoids making old value copies for all expressions of type `w` even if that type has a copy constructor (see [@../../example/features/old_if_copyable.cpp =old_if_copyable.cpp=]): - -[old_if_copyable_w_decl] -[old_if_copyable_w_spec] - -On the flit side, the following specializations of [classref boost::contract::is_old_value_copyable] and [classref boost::contract::old_value_copy] make old value copies of expressions of type `p` even if that type does not actually have a copy constructor (see [@../../example/features/old_if_copyable.cpp =old_if_copyable.cpp=]): - -[old_if_copyable_p_decl] -[old_if_copyable_p_spec] - -[heading No C++11] - -In general, `boost::contract::is_copy_constructible` and therefore [classref boost::contract::is_old_value_copyable] require C++11 `decltype` and SFINAE to automatically detect if a given type is not copyable. -On non-C++11 compilers, it is possible to inherit the old value type from `boost::noncopyable`, or use `BOOST_MOVABLE_BUT_NOT_COPYABLE`, or specialize `boost::is_copy_constructible` (see [@http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html `boost::is_copy_constructible`] documentation for more information). -Alternatively, it is possible to just specialize [classref boost::contract::is_old_value_copyable]. -For example, for a non-copyable type `n` (see [@../../example/features/old_if_copyable.cpp =old_if_copyable.cpp=]): - -[old_if_copyable_n_decl] -[old_if_copyable_n_spec] - -[endsect] - -[section Assertion Requirements (Templates)] - -In general, assertions can introduce a new set of requirements on the types used by a program. -Some of these type requirements might be necessary only to check the assertions and they would not be required by the program otherwise. - -In some cases it might be acceptable, or even desirable, to cause a compile-time error when a program uses types that do not provide all the operations needed to check contract assertions (because it is not possible to fully check the correctness of the program as specified by its contracts). -In these cases, programmers can specify contract assertions as we have seen so far, compilation will fail if user types do not provide all operations necessary to check the contracts. - -However, in some other cases it might be desirable to not augment the type requirements of a program because of contract assertions and to skip these assertions when user types do not provide all the operations necessary to check them. -Programmers can do this by using [funcref boost::contract::condition_if] (or [funcref boost::contract::condition_if_c]). - -For example, let's consider the following `vector` class template. -This class template does not usually require that its type parameter `T` has an equality operator `==` (it only requires `T` to be copy constructible, see `std::vector` documentation). -However, the contracts for the `vector::push_back(value)` public function include a postcondition `back() == value` that introduces the new requirement that `T` must also have an equality operator `==`. -Programmers can specify this postcondition as usual with `BOOST_CONTRACT_ASSERT(back() == value)` an let the program fail to compile when users instantiate `vector` with a type `T` that does not provide an equality operator `==`. -Otherwise, programmers can specify this postcondition using [funcref boost::contract::condition_if] to evaluate the asserted condition only for types `T` that have an equality operator `==` (and trivially evaluate to `true` otherwise). -On C++17 compilers, the same can be achieved using `if constexpr` instead of [funcref boost::contract::condition_if] resulting in a more concise and readable syntax. -For example (see [@../../example/features/condition_if.cpp =condition_if.cpp=]): - -[import ../example/features/condition_if.cpp] -[table -[[Until C++17 (without `if constexpr`)][Since C++17 (with `if constexpr`)]] -[[[condition_if]] [`` -template -class vector { -public: - void push_back(T const& value) { - boost::contract::check c = boot::contract::public_function(this) - .postcondition([&] { - // Guard with `if constexpr` for T without `==`. - if constexpr(boost::has_equal_to::value) - BOOST_CONTRACT_ASSERT(back() == value); - }) - ; - - vect_.push_back(value); - } - - - - - - - - /* ... */ -``]] -] - -The [funcref boost::contract::condition_if] function template is a special case of the more general facility [funcref boost::contract::call_if]: -Specifically, [funcref boost::contract::condition_if]`<`[^['Predicate]]`>(`[^['condition]]`)` is equivalent to: -[footnote -For optimization reasons, the internal implementation of [funcref boost::contract::condition_if] does not actually uses [funcref boost::contract::call_if] (but in principle [funcref boost::contract::condition_if] could be implemented using [funcref boost::contract::call_if] as shown in this documentation). -] - - boost::contract::call_if<``[^['Predicate]]``>( - ``[^['condition]]`` - ).else_( - [] { return true; } - ) - -Where [^['Predicate]] is a nullary boolean meta-function and [^['condition]] is a nullary boolean functor. -If [^['Predicate]]`::value` is statically evaluated to be `true` at compile-time then [^['condition]]`()` is called at run-time and its boolean result is returned by the enclosing `call_if`. -Otherwise, if [^['Predicate]]`::value` is statically evaluated to be `false` at compile-time then the lambda function `[] { return true; }()` is called at run-time and `true` is trivially returned by the enclosing `call_if`. -Therefore, if [^['condition]] is a functor template (and not just a functor) then its code that contains the assertion operations with the extra type requirements (e.g., the equality operator `==`) will not be instantiated and compiled for specific types unless the compiler determines at compile-time that [^['Predicate]]`::value` is `true` (functor templates like `std::equal_to` and C++14 generic lambdas can be used to program [^['condition]], but C++11 lambdas cannot). - -More in general, [funcref boost::contract::call_if] accepts a number of optional /else-if/ statements and one optional /else/ statement: - - boost::contract::call_if<``[^['Predicate1]]``>( - ``[^['then1]]`` - ).template else_if<``[^['Predicate2]]``>( // Optional. - ``[^['then2]]`` - ) - ... // Optionally, other `else_if` statements. - .else_( // Optional for `void` functors, otherwise required. - ``[^['else]]`` - ) - -Where [^['Predicate1]], [^['Predicate2]], ... are nullary boolean meta-functions and [^['then1]], [^['then2]], ..., [^['else]] are nullary functors. -The return types of the functor calls [^['then1]]`()`, [^['then2]]`()`, ..., [^['else]]`()` must either be all the same (including all `void`) or be of types implicitly convertible into one another. -At run-time [funcref boost::contract::call_if] will call the functor [^['then1]]`()`, or [^['then2]]`()`, ..., or [^['else]]`()` depending on which meta-function [^['Predicate1]]`::value`, [^['Predicate2]]`::value`, ... is statically evaluated to be `true` or `false` at compile-time, and it will return the value returned by the functor being called. -If [^['then1]], [^['then2]], ..., [^['else]] are nullary functor templates (not just nullary functors) then their code will only be compiled if the compiler determines they need to be actually called at run-time (so only if the related [^['Predicate1]]`::value`, [^['Predicate2]]`::value`, ... are evaluated to be `true` or `false` at compile-time). -All the `else_if<...>(...)` statements are optional, the `else_(...)` statement is optional if the functor calls return `void` but it is required otherwise. - -In general, [funcref boost::contract::call_if] can be used to program contract assertions that compile and check different functor templates depending on related predicates being statically evaluated to be `true` or `false` at compile-time (but in most cases [funcref boost::contract::condition_if] should be sufficient and less verbose to use). -The [funcref boost::contract::condition_if_c], [funcref boost::contract::call_if_c], and `.else_if_c` function templates work similarly to their counterparts without the `..._c` postfix above, but they take their predicate template parameters as static boolean values instead of nullary boolean meta-functions. - -Another example where assertion requirements might be useful is to disable assertions that might be constant-correct only for specific template types. -For example, `std::distance` does not alter its iterator arguments but only for forward iterators so the follow template function evaluates its preconditions only for for those types (for convenience this example uses C++17 `if constexpr` but it could have been implemented using [funcref boost::contract::condition_if] together with C++14 generic lambdas or binding to a C++11 functor template that calls `std::distance` in its `operator()`): - - template - void display_first_second_next(InputIter begin, InputIter end) { - boost::contract::check c = boost::contract::function() - .precondition([&] { - if constexpr(is_forward_iterator::value) { - BOOST_CONTRACT_ASSERT(std::distance(begin, end) >= 2); - } // Otherwise, std::distance would change begin and end. - }) - ; - ... - } - - -[heading If-Constexpr Emulation (C++14)] - -The [funcref boost::contract::call_if] function template is a general facility and its use is not limited to programming contracts. -In fact, [funcref boost::contract::call_if] can be used together with C++14 generic lambdas to emulate statements similar to C++17 `if constexpr` -For example (see [@../../example/features/call_if_cxx14.cpp =call_if_cxx14.cpp=]): -[footnote -Boost.Hana (`boost::hana::if_`) can also be used together with C++14 generic lambdas to emulate statements similar to C++17 `if constexpr`. -] - -[import ../example/features/call_if_cxx14.cpp] -[table -[[Until C++17 (without `if constexpr`)][Since C++17 (with `if constexpr`)]] -[[[call_if_cxx14]] [`` -template -void myadvance(Iter& i, Dist n) { - if constexpr(is_random_access_iterator::value) { - i += n; - } else if constexpr(is_bidirectional_iterator::value) { - if(n >= 0) while(n--) ++i; - else while(n++) --i; - } else if constexpr(is_input_iterator::value) { - while(n--) ++p; - } else { - static_assert(false, "requires at least input iterator"); - } -} -``]] -] - -This implementation is more concise, easier to read and maintain than the usual implementation of `std::advance` that uses tag dispatching. -Of course the implementation that uses C++17 `if constexpr` is even more readable and concise. - -[endsect] - -[section Volatile Public Functions] - -This library allows to specify a different set of class invariants to check for volatile public functions. -These /volatile class invariants/ are programmed in a public `const volatile` function, named `invariant`, taking no argument, and returning `void` (see [macroref BOOST_CONTRACT_INVARIANT_FUNC] to name the invariant function differently from `invariant` and __Access_Specifiers__ to not have to declare it `public`). -Classes that do no have invariants for their volatile public functions, simply do not declare the `void invariant() const volatile` function. - -In general, `const volatile` invariants work the same as `const` invariants (see __Class_Invariants__) with the only difference that `volatile` and `const volatile` functions check `const volatile` invariants while non-`const` (i.e., neither `const` nor `volatile`) and `const` functions check `const` invariants. -A given class can specify any combination of `static`, `const volatile`, and `const` invariant functions (see __Class_Invariants__): -[footnote -*Rationale:* -Constructors and destructors check `const volatile` and `const` invariants in that order because the qualifier that can be applied to more calls is checked first (note that `const volatile` calls can be made on any object while `const` calls cannot be made on `volatile` objects, in that sense the `const volatile` qualifier can be applied to more calls than `const` alone can). -This is consistent with `static` class invariants that are checked even before `const volatile` invariants (the `static` classifier can be applied to even more calls than `const volatile`, in fact an object is not even needed to make static calls). -] - -* Constructors check `static` invariants at entry and exit (even if an exception is thrown), plus `const volatile` and `const` invariants in that order at exit but only if no exception is thrown. -* Destructors check `static` invariants at entry and exit (even if an exception is thrown), plus `const volatile` and `const` invariants in that order at entry (and at exit but only if an exception is thrown, even is destructors should in general never throw in C++). -* Both non-`const` and `const` public functions check `static` and `const` invariants at entry and at exit (even if an exception is thrown). -* Both `volatile` and `const volatile` public functions check `static` and `const volatile` invariants at entry and at exit (even if an exception is thrown). - -These rules ensure that volatile class invariants are correctly checked (see __Constructor_Calls__, __Destructor_Calls__, and __Public_Function_Calls__). -For example (see [@../../example/features/volatile.cpp =volatile.cpp=]): - -[import ../example/features/volatile.cpp] -[volatile] - -This library does not automatically check `const volatile` invariants for non-`volatile` functions. -However, if the contract specifications require it, programmers can explicitly call the `const volatile` invariant function from the `const` invariant function (preferably in that order to be consistent with the order `const volatile` and `const` invariants are checked for constructors and destructors). -That way all public functions, `volatile` or not, will check `const volatile` invariants (while only `const` and non-`const` public functions will check only `const` invariants, correctly so because the `volatile` qualifier shall not be stripped away): -[footnote -*Rationale:* -Note that while all public functions can be made to check `const volatile` invariants, it is never possible to make volatile public functions check `const` non-volatile invariants. -That is because both `const` and `volatile` can always be added but never stripped in C++ (a part from forcefully via `const_cast`) but `const` is always automatically added by this library in order to enforce contract constant-correctness (see __Constant_Correctness__). -That said, it would be incorrect for this library to also automatically add `volatile` and require all functions to check `const volatile` (not just `const`) invariants because only `volatile` members can be accessed from `const volatile` invariants so there could be many `const` (but not `const volatile`) members that are accessible from `const` invariants but not from `const volatile` invariants. -To avoid this confusion, this library has chosen to draw a clear dichotomy between `const` and `const volatile` invariants so that only volatile public functions check `const volatile` invariants and only non-volatile public functions check `const` (but not `const volatile`) invariants. -This is simple and should serve most cases. -If programmers need non-volatile public functions to also check `const volatile` invariants, they can explicitly do so by calling the `const volatile` invariant function from the `const` invariant function as shown in this documentation. -] - - class a { - public: - void invariant() const volatile { ... } // Volatile invariants. - - void invariant() const { - const_cast(this)->invariant(); // Call `const volatile` invariant function above. - ... // Other non-volatile invariants. - } - - ... - }; - -(As usual, private and protected functions do not check any invariant, not even when they are `volatile` or `const volatile`, see __Private_and_Protected_Functions__). - -[endsect] - -[section Move Operations] - -As with all public operations of a class, also move operations should maintain class invariants (see __Stroustrup13__, p. 520). -Specifically, C++ requires the following: - -* The moved-from object can be copy assigned. -* The moved-from object can be move assigned. -* The moved-from object can be destroyed (if not for anything else, this requires that class invariants are maintained by move operations because the destructor of the moved-from object requires class invariants to be satisfied at its entry, as always with destructors see __Destructor_Calls__). - -Therefore, both the move constructor and the move assignment operator need to maintain the class invariants of the moved-from object so their contracts can be programmed using [funcref boost::contract::constructor] and [funcref boost::contract::public_function] as always for constructors and public functions. -For example (see [@../../example/features/move.cpp =move.cpp=]): - -[import ../example/features/move.cpp] -[move] - -This example assumes that it is possible to call the public function `moved()` on the moved-from object. -This allows to make explicit the precondition that except for destructor, copy and move assignments all other public functions cannot be called on a moved-from object. -This precondition is usually implicit in C++ (i.e., documented by the standard but not checked by the language at run-time). -If it is is not possible (e.g., due to some optimized implementation of the move operations) to have such a `moved()` public function, the private `moved_` member (or similar) can be used to program class invariants and preconditions (and that will just relay on the usual implicit C++ assumption on moved-from object because users will not be able to fully check preconditions and class invariants before calling functions of a moved-from object). - -[note -The default move constructor and move assignment operator generated by C++ will not automatically check contracts. -Therefore, unless the move operations are not public or they have no preconditions, no postconditions, and their class has no invariants, programmers should manually define them using [funcref boost::contract::constructor], [classref boost::contract::constructor_precondition], and [funcref boost::contract::public_function] instead of relying on their default implementations generated by C++. -(Same as for all other operations automatically implemented by C++.) -] - -[endsect] - -[section Unions] - -In C++, a `union` cannot have virtual functions, bases classes, and cannot be used as a base class thus subcontracting ([classref boost::contract::virtual_], [macroref BOOST_CONTRACT_OVERRIDE], etc.) do not apply to unions. -Also a `union` cannot inherit from [classref boost::contract::constructor_precondition] (because it cannot have base classes) so such a class is used to declare a local object that checks constructor preconditions (at the very beginning of the constructor before old value copies and other contracts, see declaration of `pre` in the example below). -A part from that, this library is used as usual to program contracts for unions. -For example (see [@../../example/features/union.cpp =union.cpp=]): - -[import ../example/features/union.cpp] -[union] - -[endsect] - -[section Disable Contract Checking] - -Checking contracts adds run-time overhead and can slow down program execution (see __Benefits_and_Costs__). -Therefore, programmers can define any combination of the following macros (`-D` option in Clang and GCC, `/D` option in MSVC, etc.) to instruct this library to not check specific kind of contract conditions at run-time: - -* Define [macroref BOOST_CONTRACT_NO_PRECONDITIONS] to not check preconditions. -* Define [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] to not check postconditions. -* Define [macroref BOOST_CONTRACT_NO_EXCEPTS] to not check exception guarantees. -* Define [macroref BOOST_CONTRACT_NO_ENTRY_INVARIANTS] to not check class invariants at call entry. -* Define [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS] to not check class invariants at call exit. -* Or, define [macroref BOOST_CONTRACT_NO_INVARIANTS] to not check class invariants at both call entry and exit. (This is provided for convenience, it is equivalent to define both [macroref BOOST_CONTRACT_NO_ENTRY_INVARIANTS] and [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS].) -* Define [macroref BOOST_CONTRACT_NO_CHECKS] to not run implementation checks (programmed using [macroref BOOST_CONTRACT_CHECK], etc.). - -[note -In general, old values are used by both postconditions and exception guarantees so it is necessary to define both [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] and [macroref BOOST_CONTRACT_NO_EXCEPTS] to disable old value copies. -] - -By default, none of these macros are defined so this library checks all contracts. -When these macros are defined by the user, the implementation code of this library is internally optimized to minimize as much as possible any run-time and compile-time overhead associated with checking and compiling contracts (see __Disable_Contract_Compilation__ for techniques to completely remove any run-time and compile-time overhead associated with contract code). - -For example, programmers could decide to check all contracts during early development builds, but later check only preconditions and maybe entry invariants for release builds by defining [macroref BOOST_CONTRACT_NO_POSTCONDITIONS], [macroref BOOST_CONTRACT_NO_EXCEPTS], [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS], and [macroref BOOST_CONTRACT_NO_CHECKS]. - -[endsect] - -[section Assertion Levels] - -This library provides three predefined /assertion levels/ that can be used depending on the computational complexity of the asserted conditions: -[footnote -The assertion levels predefined by this library are similar to the default, audit, and axiom levels proposed in __P0380__. -] - -* [macroref BOOST_CONTRACT_ASSERT] is used to assert conditions that are not computationally expensive, at least compared to the cost of executing the function body. -These assertions are always checked at run-time and cannot be disabled. -* [macroref BOOST_CONTRACT_ASSERT_AUDIT] is used to assert conditions that are computationally expensive compared to the cost of executing the function body. -These assertions are not checked at run-time unless programmers explicitly define [macroref BOOST_CONTRACT_AUDITS] (undefined by default), but the conditions are always compiled and validated syntactically (even when they are not actually evaluated and checked at run-time). -* [macroref BOOST_CONTRACT_ASSERT_AXIOM] is used to assert conditions that are computationally prohibitive, at least compared to the cost of executing the function body. -These assertions are never evaluated or checked at run-time, but the asserted conditions are always compiled and validated syntactically so these assertions can serve as formal comments in the code. - -In addition, [macroref BOOST_CONTRACT_CHECK_AUDIT] and [macroref BOOST_CONTRACT_CHECK_AXIOM] are similar to [macroref BOOST_CONTRACT_ASSERT_AUDIT] and [macroref BOOST_CONTRACT_ASSERT_AXIOM] but they are used to program audit and axiom levels for implementation checks instead of assertions (see __Implementation_Checks__). - -For example, [macroref BOOST_CONTRACT_ASSERT_AUDIT] can be used to program computationally expensive assertions (see [@../../example/features/assertion_level.cpp =assertion_level.cpp=]): - -[import ../example/features/assertion_level.cpp] -[assertion_level_audit] - -Also [macroref BOOST_CONTRACT_AUDITS] can be used to disable expensive old value copies and related assertions that use them (see [@../../example/features/assertion_level.cpp =assertion_level.cpp=]): - -[assertion_level_class_begin] -[assertion_level_audit_old] -[assertion_level_class_end] - -The condition passed to [macroref BOOST_CONTRACT_ASSERT_AXIOM] is compiled but not actually evaluated at run-time so this macro can be used to program computationally prohibitive assertions but also assertions that cannot actually be programmed in C++ using functions that are declared but left undefined. -For example, (see [@../../example/features/assertion_level.cpp =assertion_level.cpp=]): - -[assertion_level_no_impl] -[assertion_level_class_begin] -[assertion_level_axiom] -[assertion_level_class_end] - -In addition to the assertion levels predefined by this library, programmers are free to define their own. -For example, the following macro could be used to program and selectively disable assertions that have exponential computational complexity `O(e^n)`: - - #ifdef NO_EXPONENTIALLY_COMPLEX_ASSERTIONS - // Following will compile but never actually evaluate `cond`. - #define EXP_ASSERTION(cond) BOOST_CONTRACT_ASSERT(true || (cond)) - #else - // Following will compile and also evaluate `cond`. - #define EXP_ASSERTION(cond) BOOST_CONTRACT_ASSERT(cond) - #endif - - ... - - EXP_ASSERTION(``[^['some-exponentially-complex-boolean-condition]]``); - -[endsect] - -[section Disable Contract Compilation (Macro Interface)] - -This library provides macros that can be used to completely disable compile-time and run-time overhead introduced by contracts but at the cost of manually programming `#ifndef` statements around contract code: - -* This library defines [macroref BOOST_CONTRACT_NO_CONSTRUCTORS] when contract checking is disabled for constructors. -* This library defines [macroref BOOST_CONTRACT_NO_DESTRUCTORS] when contract checking is disabled for destructors. -* This library defines [macroref BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS] when contract checking is disabled for public functions. -* This library defines [macroref BOOST_CONTRACT_NO_FUNCTIONS] when contract checking is disabled for (non-public) functions. -* This library defines [macroref BOOST_CONTRACT_NO_OLDS] when old value copies are disabled. -* This library defines [macroref BOOST_CONTRACT_NO_ALL] when checks are disabled for all contracts above. - -These macros are not configuration macros and they should not be defined directly by the users (otherwise this library will generate a compile-time error). -Instead, these macros are automatically defined by this library when users define [macroref BOOST_CONTRACT_NO_PRECONDITIONS], [macroref BOOST_CONTRACT_NO_POSTCONDITIONS], [macroref BOOST_CONTRACT_NO_EXCEPTS], [macroref BOOST_CONTRACT_NO_INVARIANTS] (or [macroref BOOST_CONTRACT_NO_ENTRY_INVARIANTS] and [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS]), and [macroref BOOST_CONTRACT_NO_CHECKS] (see __Disable_Contract_Checking__). - -Alternatively, this library provides a macro-based interface [headerref boost/contract_macro.hpp] that can be used to completely disable compile-time and run-time overhead introduced by contracts. -This macro interface is usually preferred because more concise and easier to use than programming `#ifdef` statements by hand, but it can make compiler errors more cryptic (because all macro code expands on a single line in C++ so line numbers in compiler errors are less useful than usual) and it leave a bit of contract decorations in the code but at no measurable overhead (extra [classref boost::contract::virtual_]`*` parameter, call to [classref boost::contract::constructor_precondition] default constructor which does nothing, [macroref BOOST_CONTRACT_BASE_TYPES] `typedef`, and [classref boost::contract::access] friendship, see example below). - -The following examples show how to use both the macro interface and alternatively the `#ifdef` statements to completely disable compile-time and run-time overhead introduced by contracts (see [@../../example/features/ifdef_macro.cpp =ifdef_macro.cpp=] and [@../../example/features/ifdef.cpp =ifdef.cpp=]): - -[import ../example/features/ifdef_macro.cpp] -[import ../example/features/ifdef.cpp] -[table -[ [Macro Interface] [`#ifdef` Statements] ] -[ [[ifdef_macro_function]] [[ifdef_function]] ] -] - -The same can be used to disable contract code complication for private and protected functions. -The [macroref BOOST_CONTRACT_OLD_PTR_IF_COPYABLE] macro is provided to handle non-copyable old value types (equivalently to [classref boost::contract::old_ptr_if_copyable]). -For constructors, destructors, and public functions instead (see [@../../example/features/ifdef_macro.cpp =ifdef_macro.cpp=] and [@../../example/features/ifdef.cpp =ifdef.cpp=]): - -[table -[ [Macro Interface] [`#ifdef` Statements] ] -[ [[ifdef_macro_class]] [[ifdef_class]] ] -] - -Static class invariants can be programmed using [macroref BOOST_CONTRACT_STATIC_INVARIANT] and volatile class invariants using [macroref BOOST_CONTRACT_INVARIANT_VOLATILE] (these macros expand code equivalent to the `static void `[macroref BOOST_CONTRACT_STATIC_INVARIANT_FUNC]`()` and `void `[macroref BOOST_CONTRACT_INVARIANT_FUNC]`() const volatile` functions respectively). - -Macro code expands on a single line so using the macro interface will cause all assertions within a given set of preconditions, postconditions, exception guarantees, and class invariants to list the same line number in their error messages if they fail at run-time (but the assertion code will be listed as well and it should allow programmers to identify the specific assertion that failed). -In general, the authors do not recommend to use the macro interface and the `#ifdef` statements unless strictly necessary because they both make the contract code more verbose, less readable, and can cause cryptic error messages. - -That said, disabling contract as shown in __Disable_Contract_Checking__ will still leave the overhead of compiling contract code plus some small run-time overhead due to the initialization of old value pointers (even if those will be all null and no old value will be actually copied), the calls to the contract functions used to initialize [classref boost::contract::check] and [classref boost::contract::constructor_precondition] (even if those calls will be internally optimized by this library to essentially do nothing), etc. -For truly performance critical code for which even such small run-time overhead might not be acceptable, the macro interface (or the `#ifdef` statements) shown here can be used to completely disable compile-time and run-time overheads of contracts. -However, for such performance-critical code even the overhead of checking simple preconditions might be too much so it might be best to not program contracts for such performance-critical code all together. - -Therefore, in most cases the compile-time overhead of contracts should not represent an issue and it should be sufficient to disable contract checking at run-time as indicated in __Disable_Contract_Checking__. - -[endsect] - -[section Separate Body Implementation] - -Contracts are part of the program specification and not of its implementation (see __Specification_vs_Implementation__). -However, this library uses function definitions to program contracts so contract code appears together with the function implementation code. -This is not ideal (even if contracts programmed using this library will always appear at the very beginning of the function definition so programmers will easily be able to distinguish contract code from the rest of the function implementation code and this might not be real problem in practise). - -In some cases, it might be desirable to completely separate the contract code from the function implementation code. -For example, this could be necessary for software that ships only header files and compiled object files to its users. -If contracts are programmed in function definitions that are compiled in the object files, users will not be able to see the contract code to understand semantics and usage of the functions (again, this might not be a real problem in practice for example if contracts are already somehow extracted from the source code and presented as part of the documentation of the shipped software). - -In any case, when it is truly important to separate contracts from function implementation code, function implementations can be programmed in extra /body functions/ (e.g., named `..._body`) that are compiled in object files. -Function definitions that remain in header files instead will contain just contract code followed by calls the extra body functions. -This technique allows to keep the contract code in header files while separating the implementation code to object files but at the cost of manually programming an extra function declaration for the body function (and with the limitation that constructor member initialization lists must be programmed in header files because that is where constructors need to be defined to list the constructor contract code). - -For example, the following header file only contains function declarations, contract code, and constructor member initializations, but it does not contain the code implementing the function bodies (see [@../../example/features/separate_body.hpp =separate_body.hpp=]): - -[import ../example/features/separate_body.hpp] -[separate_body_hpp] - -Instead, the function bodies are implemented in a separate source file (see [@../../example/features/separate_body.cpp =separate_body.cpp=]): - -[import ../example/features/separate_body.cpp] -[separate_body_cpp] - -The same technique can be used for non-member, private, and protected functions, etc. - -[note -When contracts are programmed only in =.cpp= files and also all this library headers are `#include`d only from the =.cpp= files, then these =.cpp= files can be compiled disabling specific contract checking (for example, [macroref BOOST_CONTRACT_NO_POSTCONDITIONS], [macroref BOOST_CONTRACT_NO_EXCEPTS], and [macroref BOOST_CONTRACT_NO_EXIT_INVARIANTS], see __Disable_Contract_Checking__). -Then the code in these =.cpp= files will always have such contract checking disabled even when linked to some other user code that might have been compiled with a different set of contracts disabled (i.e., a different set of `BOOST_CONTRACT_NO_...` macros defined). -This technique might be useful to ship compiled object files (e.g., for a library) that will never check some contracts (e.g., postconditions, exception guarantees, and exit invariants) regardless of the definition of the `BOOST_CONTRACT_NO_...` macros used to compile code that links against the shipped object files. - -On the contrary, if contracts are programmed only in header files (e.g., using extra `..._body` functions as shown in this section) and this library headers are `#include`d only in these header files that are being shipped, then end users can enable or disables contract checking of the shipped code by defining the `BOOST_CONTRACT_NO_...` macros when they compile the shipped header files as part of their code. -This technique might be useful in other situations when programmers that ship code want to leave it up the their end users to decide which contracts of the shipped code should be checked at run-time. -] - -[endsect] - -[section No Lambda Functions (No C++11)] - -This section shows how to use this library without C++11 lambda functions. -This has some advantages: - -* It allows to use this library on compilers that do not support C++11 lambda functions (essentially most C++03 compilers can be used in that case, see __No_Macros__ to also avoid using variadic macros). -* Contract functions (i.e., the `..._precondition`, `..._old`, and `..._postcondition` functions in the example below) can be programmed to fully enforce constant-correctness and other contract requirements at compile-time (see __Constant_Correctness__). -[footnote -If C++ allowed lambda functions to capture variables by constant reference (for example using the syntax `[const&] { ... }` and `[const& `[^['variable-name]]`] { ... }`, see [@https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/0UKQw9eo3N0]) also lambdas could be used to program contract functors that fully enforce __Constant_Correctness__ at compile-time. -Note that C++11 lambdas allow to capture variables by value (`[=] { ... }` and `[`[^['variable-name]]`] { ... }`), these value captures are `const` (unless the lambda is explicitly declared `mutable`) but they are not suitable to program postconditions and exception guarantees using this library (because those require capturing by reference, see __Postconditions__ and __Exception_Guarantees__), plus they introduce a copy of the captured value that might be too expensive in general and therefore not suitable for preconditions either. -] -* Code of the contract functions is separated from function body implementations (see __Separate_Body_Implementation__). -[footnote -Alternatively, on compilers that do not support C++11 lambda functions, [@http://www.boost.org/doc/libs/release/libs/local_function/doc/html/index.html Boost.LocalFunction] could be used to program the contract functors still within the function definitions (for example, see [@../../example/features/no_lambdas_local_func.cpp =no_lambda_local_func.cpp=]). -In general, such a code is less verbose than the example shown in this section that uses contract functions programmed outside of the original function definitions (about 30% less lines of code) but the contract code is hard to ready. -Other libraries could also be used to program the contract functors without C++11 lambda functions (Boost.Lambda, Boost.Fusion, etc.) but again all these techniques will result in contract code either more verbose, or harder to read and maintain than the code that uses C++11 lambda functions. -] - -However, not using C++11 lambda functions comes to the significant cost of having to manually program the extra contract function and related boiler-plate code. -For example (see [@../../example/features/no_lambdas.hpp =no_lambdas.hpp=] and [@../../example/features/no_lambdas.cpp =no_lambdas.cpp=]): - -[import ../example/features/no_lambdas.hpp] -[no_lambdas_hpp] - -[import ../example/features/no_lambdas.cpp] -[no_lambdas_cpp] - -If programmers also want to fully enforce all contract programming constant-correctness requirements at compile-time, they should follow these rules when programming the contract functions (see __Constant_Correctness__): - -* Precondition functions (i.e., the `..._precondition` functions in the example above) can take their arguments either by `const` value or by `const&`, and when they are member functions they should be either `static` or `const` functions. -* Postcondition functions (i.e., the `..._postcondition` functions in the example above) should take their arguments by `const&`, and when they are member functions they should be either `static` or `const` functions. -* Similarly, exception guarantee functions (not shown in the example above) should take their arguments by `const&`, and when they are member functions they should be either `static` or `const` functions. -* Old value functions (i.e., the `..._old` functions in the example above) should take their arguments by `const&` a part from old value pointers that should be taken by `&` (so only old value pointers can be modified), and when they are member functions they should be either `static` or `const` functions. -* Constructor precondition, old value, and exception guarantee functions should be `static` (because there is no valid object `this` if the constructor body does not run successfully, see __Constructor_Calls__). -* Destructor postcondition functions should be `static` (because there is no valid object `this` after the destructor body runs successfully, but exception guarantee functions do not have to be `static` since the object `this` is still valid because the destructor body did not run successfully, see __Destructor_Calls__). - -Note that the extra contract functions also allow to keep the contract code in the header file while all function bodies are implemented in a separate source file (including the constructor member initialization list, that could not be done with the techniques shown in __Separate_Body_Implementation__). -[footnote -In this example, `bind` was used to generate nullary functors from the contract functions. -As always with `bind`, `cref` and `ref` must be used to bind arguments by `const&` and `&` respectively, plus it might be necessary to explicitly `static_cast` the function pointer passed to `bind` for overloaded functions. -] -Also note that the contract functions can always be declared `private` if programmers need to exactly control the public members of the class (this was not done in this example only for brevity). - -The authors think this library is most useful when used together with C++11 lambda functions. - -[endsect] - -[section No Macros (and No Variadic Macros)] - -It is possible to specify contracts without using most of the macros provided by this library and programming the related code manually instead (the only macros that cannot be programmed manually are [macroref BOOST_CONTRACT_OVERRIDE], [macroref BOOST_CONTRACT_OVERRIDES], and [macroref BOOST_CONTRACT_NAMED_OVERRIDE]). - -[note -Some of this library macros are variadic macros, others are not (see below). -Variadic macros were officially added to the language in C++11 but most compilers have been supporting them as an extension for a long time, plus essentially all compilers that support C++11 lambda functions also support C++11 variadic macros (and this library might rarely be used without the convenience of C++11 lambda functions, see __No_Lambda_Functions__). -[footnote -Compilation times of this library were measured to be comparable between compilers that support variadic macros and compilers that do not. -(See also [macroref BOOST_CONTRACT_MAX_ARGS] on compilers that do not support variadic macros. -*Rationale:* [macroref BOOST_CONTRACT_MAX_ARGS] is named after `BOOST_FUNCTION_MAX_ARGS`.) -] -Therefore, the rest of this section can be considered mainly a curiosity because programmers should seldom need to use this library without using its macros. -] - -[heading Overrides] - -As shown in __Public_Function_Overrides__ and __Named_Overrides__, this library provides the [macroref BOOST_CONTRACT_OVERRIDE] and [macroref BOOST_CONTRACT_NAMED_OVERRIDE] macros to program contracts for overriding public functions. -These macros cannot be programmed manually but they are not variadic macros so programmers should be able to use them on all C++ compilers. -[footnote -*Rationale:* -These macros expand SFINAE-based introspection templates that are too complex to be programmed manually by users (that remains the case even if C++14 generic lambdas were to be used here). -On a related note, in theory using C++14 generic lambdas, the [macroref BOOST_CONTRACT_OVERRIDE] macro could be re-implemented in a way that can be expanded at function scope, instead of class scope (but there is not really a need for that). -] -The [macroref BOOST_CONTRACT_OVERRIDES] macro is a variadic macro instead but programmes can manually repeat the non-variadic macro [macroref BOOST_CONTRACT_OVERRIDE] for each overriding public function name on compilers that do not support variadic macros. - -[heading Assertions (Not Variadic)] - -As shown in __Preconditions__, __Postconditions__, __Exception_Guarantees__, __Class_Invariants__, etc. this library provides the [macroref BOOST_CONTRACT_ASSERT] macro to assert contract conditions. -This is not a variadic macro and programmers should be able to use it on all C++ compilers. -In any case, the invocation `BOOST_CONTRACT_ASSERT(`[^['condition]]`)` expands to code equivalent to the following: -[footnote -*Rationale:* -No need to also support C++11 `__func__` because this will always expand to the name of `operator()` of the functor used to program the contract assertions (e.g., of the lambda function) and it will not expand to the name of the actual function specifying the contract. -] - - if(!(``[^['condition]]``)) { - throw boost::contract::assertion_failure(__FILE__, __LINE__, - BOOST_PP_STRINGIZE(``[^['condition]]``)); - } - -In fact, this library considers any exception thrown from within preconditions, postconditions, exception guarantees, and class invariants as a contract failure and reports it calling the related contract failure handler ([funcref boost::contract::precondition_failure], etc.). -If there is a need for it, programmers can always program contract assertions that throw specific user-defined exceptions as follow (see __Throw_on_Failure__): - - if(!``[^['condition]]``) throw ``[^['exception-object]]``; - -However, using [macroref BOOST_CONTRACT_ASSERT] is convenient because it always allows this library to show an informative message in case of assertion failure containing the assertion code, file name and line number, etc. - -The [macroref BOOST_CONTRACT_ASSERT_AUDIT] and [macroref BOOST_CONTRACT_ASSERT_AXIOM] macros are not a variadic macros and programmers should be able to use them on all C++ compilers. -Their implements are equivalent to the following: - - #ifdef BOOST_CONTRACT_AUDITS - #define BOOST_CONTRACT_ASSERT_AUDIT(condition) \ - BOOST_CONTRACT_ASSERT(condition) - #else - #define BOOST_CONTRACT_ASSERT_AUDIT(condition) \ - BOOST_CONTRACT_ASSERT(true || (condition)) - #endif - - #define BOOST_CONTRACT_ASSERT_AXIOM(condition) \ - BOOST_CONTRACT_ASSERT(true || (condition)) - -[heading Base Types (Variadic)] - -As shown in __Base_Classes__, this library provides the [macroref BOOST_CONTRACT_BASE_TYPES] variadic macro to declare the `base_types` member type that will expand to the list of all public bases of a derived class. -Programmers can also declare `base_types` without using [macroref BOOST_CONTRACT_BASE_TYPES] at the cost of writing a bit more code manually and increased maintenance. -For example (see [@../../example/features/base_types_no_macro.cpp =base_types_no_macro.cpp=]): - -[import ../example/features/base_types_no_macro.cpp] -[base_types_no_macro] - -The `base_types` member type must be a `boost::mpl::vector` which must list /all and only/ `public` base classes (because only public bases subcontract, see __Function_Calls__), and in the same order these public base classes appear in the derived class inheritance list. -If the [macroref BOOST_CONTRACT_BASE_TYPES] macro is not used, it is the responsibility of the programmers to maintain the correct list of bases in the `boost::mpl::vector` each time the derived class inheritance list changes (this might significantly complicate maintenance). - -In general, it is recommended to use the [macroref BOOST_CONTRACT_BASE_TYPES] macro whenever possible. - -[heading Old Values (Variadic)] - -As shown in __Old_Values__, this library provides the [macroref BOOST_CONTRACT_OLDOF] variadic macro to assign old value copies. -Programmers can also assign old values without using [macroref BOOST_CONTRACT_OLDOF] at the cost of writing a bit more code manually. -For example (see [@../../example/features/old_no_macro.cpp =old_no_macro.cpp=]): - -[import ../example/features/old_no_macro.cpp] -[old_no_macro] - -The ternary operator `boost::contract::copy_old(v) ? size() : boost::contract::null_old()` must be used here to avoid evaluating and copying the old value expression `size()` when [funcref boost::contract::copy_old] returns `false` (because old values are not being copied when postcondition and exception guarantees checking is disabled at run-time, an overridden virtual function call is not checking postconditions or exception guarantees yet, etc.). -The enclosing [funcref boost::contract::make_old] copies the old value expression and creates an old value pointer. -Otherwise, [funcref boost::contract::null_old] indicates that a null old value pointer should be created. - -The [funcref boost::contract::make_old] and [funcref boost::contract::copy_old] functions are used exactly as shown above but without the extra `v` parameter when they are called from within non-virtual functions (see __Public_Function_Overrides__). -The old value pointer returned by [funcref boost::contract::make_old] can be assigned to either [classref boost::contract::old_ptr] or [classref boost::contract::old_ptr_if_copyable] (see __Old_Value_Requirements__). - -In general, it is recommended to use the [macroref BOOST_CONTRACT_OLDOF] macro whenever possible. - -[heading Macro Interface (Variadic)] - -Almost all macros defined in [headerref boost/contract_macro.hpp] are variadic macros. -On compilers that do not support variadic macros, programmers can manually disable contract code compilation using `#ifdef` statements as shown in __Disable_Contract_Compilation__. - -[endsect] - -[endsect] - diff --git a/doc/full_table_of_contents.qbk b/doc/full_table_of_contents.qbk deleted file mode 100644 index 94f3e0b4..00000000 --- a/doc/full_table_of_contents.qbk +++ /dev/null @@ -1,75 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Full Table of Contents] - -[pre -__Introduction__ -__Full_Table_of_Contents__ -__Getting_Started__ - __This_Documentation__ - __Compilers_and_Platforms__ - __Code_Organization__ - __Install_and_Compile__ -__Contract_Programming_Overview__ - __Assertions__ - __Benefits_and_Costs__ - __Function_Calls__ - __Public_Function_Calls__ - __Constructor_Calls__ - __Destructor_Calls__ - __Constant_Correctness__ - __Specification_vs_Implementation__ - __On_Contract_Failure__ - __Feature_Summary__ -__Tutorial__ - __Non_Member_Functions__ - __Preconditions__ - __Postconditions__ - __Return_Value__ - __Old_Values__ - __Exception_Guarantees__ - __Class_Invariants__ - __Constructors__ - __Destructors__ - __Public_Functions__ - __Virtual_Public_Functions__ - __Public_Function_Overrides_Subcontracting__ - __Base_Classes_Subcontracting__ - __Static_Public_Functions__ -__Advanced__ - __Pure_Virtual_Public_Functions__ - __Optional_Return_Value__ - __Private_and_Protected_Functions__ - __Friend_Functions__ - __Function_Overloads__ - __Lambdas_Loops_Code_Blocks_and_constexpr__ - __Implementation_Checks__ - __Old_Copies_at_Body__ - __Named_Overrides__ - __Access_Specifiers__ - __Throw_on_Failure_and_noexcept__ -__Extras__ - __Old_Value_Requirements_Templates__ - __Assertion_Requirements_Templates__ - __Volatile_Public_Functions__ - __Move_Operations__ - __Unions__ - __Disable_Contract_Checking__ - __Assertion_Levels__ - __Disable_Contract_Compilation_Macro_Interface__ - __Separate_Body_Implementation__ - __No_Lambda_Functions_No_CXX11__ - __No_Macros_and_No_Variadic_Macros__ -__Reference__ -__Examples__ -__Release_Notes__ -__Bibliography__ -__Acknowledgments__ -] - -[endsect] - diff --git a/doc/getting_started.qbk b/doc/getting_started.qbk deleted file mode 100644 index 96764aa2..00000000 --- a/doc/getting_started.qbk +++ /dev/null @@ -1,214 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Getting Started] - -This section illustrates how to setup a system to use this library. - -[section This Documentation] - -Programmers should be able to start using this library after reading __Introduction__, __Getting_Started__, and __Tutorial__. -Other sections of this documentation (e.g., __Advanced__ and __Extras__) can be consulted at a later point to gain a more in-depth knowledge of the library. -__Contract_Programming_Overview__ can be skipped by programmers that are already well familiar with the contract programming methodology. - -Some of the source code of the examples linked by this documentation contain special code comments of the form `//[...` and `//]`. -These mark sections of the code that are automatically extracted from the source and presented as part of this documentation. -[footnote -*Rationale:* -This allows to make sure that most of the example code presented in this documentation is always up-to-date, builds and runs with the latest implementation of the library. -] -Also the purpose of all examples in this documentation is to illustrate how to use this library and not to represent real product code. - -Some footnotes are marked by the word "*Rationale*". -These explain reasons behind decisions made during the design and implementation of this library. - -[endsect] - -[section Compilers and Platforms] - -In general, this library requires a C++ compiler with support for SFINAE and other template meta-programming techniques part of the C++03 standard. -This library requires Boost (Boost.Optional, Boost.Thread, Boost.FunctionTypes, Boost.Traits, Boost.MPL, etc.). - -It is possible to use this library without C++11 lambda functions but a large amount of boiler-plate code is required to manually program separate functor to specify preconditions, postconditions, etc. (so using this library without C++11 lambda functions is possible but not recommended, see __No_Lambda_Functions__). -It is also possible to use this library without variadic macros by manually programming a small amount of boiler-plate code (but most if not all modern C++ compilers support variadic macros even before C++99 and C++11 so this should never be needed in practice, see __No_Macros__). - -Some parts of this documentation use an operator [^['type-of](...)] to indicate an operator logically equivalent to C++11 `decltype(...)`. -However, this library implementation does not actually use type deduction in these cases (because the library already knows the types in question) so support for C++11 `decltype` and other type-of implementations are not actually required by this library (that is why [^['type-of]] and not the real `decltype` operator is used in this documentation). - -This library has been developed and tested using: - -* Visual Studio 2015 on Windows (MSVC =cl= version 19.00.24215.1). -* GCC version 5.4.0 on Cygwin (with C++11 features enabled =-std=c++11=). -* Clang version 3.8.1 on Cygwin (with C++11 features enabled =-std=c++11=). -* Boost C++ libraries version 1.62.0. - -[endsect] - -[section Code Organization] - -Let [^['lib-root]] be the directory under which this library source files have been installed. -This library flies are organized as follows: - -[pre -['lib-root/] # Directory where this library files were installed. - build/ # Build files (using Boost.Jam). - doc/ # Documentation (using Boost.QuickBook). - html/ # This documentation (HTML). - example/ # Examples (including those listed in this documentation). - include/ - boost/ - contract.hpp # Include all headers at once. - contract/ # Header files to be included one-by-one. - core/ # Fundamental headers (usually indirectly included by other headers). - detail/ # Implementation code (should never be included or used directly). - src/ # Library source code to be compiled. - test/ # Tests. -] - -All headers required by this library can be included at once by: - - #include - -Alternatively, all =boost/contract/*.hpp= headers are independent from one another and they can be selectively included one-by-one based on the specific functionality of this library being used (this might somewhat reduce compilation time). -The =boost/contract/core/*.hpp= headers are not independent from other headers and they do not need to be directly included in user code when =boost/contract.hpp= or =boost/contract/*.hpp= headers are included already. - -Files in =boost/contract/detail/=, names in the `boost::contract::detail` namespace, macros starting with `BOOST_CONTRACT_DETAIL...`, and all names starting with `boost_contract_detail...` (in any namespace, including user-defined namespaces) are part of this library implementation and should never be used directly in user code. - -Names starting with `BOOST_CONTRACT_ERROR...` are used by this library to report some compile-time errors (so spotting these names in compiler error messages might help troubleshooting). - -[endsect] - -[section Install and Compile] - -Let [^['lib-root]] be the directory under which this library source files have been installed. -Let [^['boost-root]] be the directory under which Boost source code has been installed and compiled following Boost's documentation (if pre-compiled Boost distributions are used instead, the [^['lib-boost]\/include] and [^['lib-boost]\/stage\/lib] directories below might be replaced by =/usr/include= and =/usr/lib= or similar directories depending on the specific Boost distribution, OS, etc.). - -The steps below show how to compile this library as a shared library (a.k.a., Dynamically Linked Library or DLL) and then compile and run a sample program that uses this library (the [@../../example/features/introduction.cpp =introduction.cpp=] program shown in __Introduction__ is used as an example). - -[warning -By default, this library is compiled as a shared library (in which case this library automatically defines the [macroref BOOST_CONTRACT_DYN_LINK] macro). -There are configuration macros [macroref BOOST_CONTRACT_STATIC_LINK] and [macroref BOOST_CONTRACT_HEADER_ONLY] that can be defined to compile this library as a static or header-only library respectively. -[footnote -*Rationale:* -[macroref BOOST_CONTRACT_DYN_LINK], [macroref BOOST_CONTRACT_STATIC_LINK], and [macroref BOOST_CONTRACT_HEADER_ONLY] are named after `BOOST_ALL_DYN_LINK`, `BOOST_ALL_DYN_LINK`, and `BOOST_CHRONO_HEADER_ONLY` respectively. -] - -The use of [macroref BOOST_CONTRACT_STATIC_LINK] and [macroref BOOST_CONTRACT_HEADER_ONLY] is discouraged because this library is not guaranteed to always work correctly at run-time when these macros are defined. -Specifically, this library might not correctly disable contracts while checking other contracts and call the correct user-defined contract failure handlers unless it is compiled as a shared library when it is being used by different program units (different programs, different shared libraries of the same program, etc.). -However, [macroref BOOST_CONTRACT_STATIC_LINK] and [macroref BOOST_CONTRACT_HEADER_ONLY] can be used for applications that check contracts in a single program unit (e.g., a single program with only statically linked libraries that check contracts). -] - -[heading Visual Studio (MSVC)] - -Using MSVC on Windows (from a developer command prompt that automatically invokes the correct =vcvarsall.bat=): - -[pre -> cd ['lib-root]\build -> cl ['lib-root]\src\contract.cpp \/MDd \/EHs -I ['lib-root]\include -I ['boost-root] /link /DLL /LIBPATH:['boost-root]\stage\lib /out:boost_contract.dll -] - -[pre -> cd ['lib-root]\example\features -> cl introduction.cpp \/MDd \/EHs -I ['lib-root]\include -I ['boost-root] /link /LIBPATH:['boost-root]\stage\lib ['lib-root]\build\boost_contract.lib -] - -[pre -> set PATH=%PATH%;['lib-root]\build -> introduction -] - -[heading GCC and CLang] - -Using GCC on Cygwin (or some Linux-like OS): - -[pre -$ cd ['lib-root]\/build -$ g++ ['lib-root]\/src\/contract.cpp -std=c++11 -shared -I ['lib-root]\/include -I ['boost-root] ['boost-root]\/stage\/lib\/libboost_system.a -o boost_contract.dll -] - -[pre -$ cd ['lib-root]\/example\/features -$ g++ introduction.cpp -std=c++11 -I ['lib-root]\/include -I ['boost-root] ['lib-root]\/build\/boost_contract.dll -o introduction -] - -[pre -$ export PATH=$PATH:['lib-root]\/build -$ .\/introduction -] - -The above steps also work for Clang replacing =g++= with =clang++=. - -[heading Boost.Build (BJam)] - -Alternatively, programmers can setup their build environments (BJam, Make, CMake, MSBuild, etc.) to compile this library source code into a shared library and then compile and link user code against it (if that is preferred instead of manually running the compiler as indicated by the steps above). -For example, this library source comes with a complete set of BJam files that can be used to build the library, build and run its tests and examples (see [@../../example/Jamfile.v2 =example/Jamfile.v2=], [@../../test/Jamfile.v2 =test/Jamfile.v2=], [@../../build/Jamfile.v2 =build/Jamfile.v2=], [@../../Jamroot =Jammroot=], [@../../build/boost_contract_no.jam =build/boost_contract_no.jam=], etc.). - -Prior to running BJam, it is necessary to install and configure Boost from source. -That can be done following these instructions for Windows (and similarly for Linux, see the [@http://www.boost.org/users/index.html Boost website]): - -* Download the Boost source file for Windows [@http://www.boost.org/users/download/ [^boost_['version].zip]] and unzip it to some directory [^['boost-root]]. -* Run (from a developer command prompt that automatically invokes the correct =vcvarsall.bat=): - -[pre -> cd [^['boost-root]] -> bootstrap.bat -> b2 -] - -* Create an environment variable named `BOOST_ROOT` and set it to the [^['boost-root]] directory path. -* Add %BOOST_ROOT% to the end of the `PATH` environment variable (so `bjam` and other Boost tools can be found). - -Boost and BJam are now ready to build this library. -For example, the following uses BJam to build and run the [@../../example/features/introduction.cpp [^['lib-root]/example/features/introduction.cpp]] program and also to automatically build this library if necessary (from a developer command prompt that automatically invokes the correct =vcvarsall.bat=): - -[pre -> cd ['lib-root]\example -> bjam features-introduction -] - -In addition, the following commands build this library, build and run all the examples and tests (from a developer command prompt that automatically invokes the correct =vcvarsall.bat=): - -[pre -> cd ['lib-root]\build # Build just the library (as a shared library by default). -> bjam - -> cd ['lib-root]\example # Build and run all examples (also automatically build the library if needed). -> bjam - -> cd ['lib-root]\test # Build and run all tests (also automatically build the library if needed). -> bjam -] - -From the example and test directories =bjam help= gives a list of options to build and run examples and tests individually, with some contracts turned off, using different compilers, with this library as a static or header-only library, etc. - -[heading Boost.QuickBook (This Documentation)] - -In general users will not need to rebuild this document so they can skip this section. - -Prior to running BJam to rebuild this documentation and regenerate its HTML pages, it is necessary to install and configure Boost from source as explained in the section above. -In addition, it is necessary to download and configure tools required by Boost.QuickBook as explained on the [@http://www.boost.org/doc/libs/release/doc/html/quickbook/install.html Boost.QuickBook website]. -Finally, it is necessary to install [@http://www.stack.nl/~dimitri/doxygen/download.html Doxygen] to some directory [^['doxygen-root]] and add the following to the =user-config.jam= file in your home directory (for example for Windows, but similarly for Linux, etc.): - -[pre -using doxygen : "['doxygen-root]/bin/doxygen.exe" ; -] - -Boost.QuickBook and BJam are now ready to rebuild this documentation and generate its HTML pages under the directory [^['lib-root]\doc\html]: -[footnote -In theory, it is possible to use Boost.QuickBook to build this documentation into a single PDF file instead of HTML pages, running =bjam pdf= from within the [^['lib-root]\doc] directory. -For that, Apache FOP and Java need to be installed as explained on the [@http://www.boost.org/doc/libs/1_65_0/doc/html/boostbook/getting/started.html Boost.Book website] and a command similar to =using fop : "C:/PROGRA~1/RenderX/XEP/xep.bat -valid" : "C:/PROGRA~1/Java/jre7/bin" ;= needs to be added to =user-config.jam= (actual paths might different on specific installations). -However, this is not configured by default and it might require extra effort to ensure that all links, code listings, tables, images, etc. correctly show in the generated PDF file. -] - -[pre -> cd ['lib-root]\doc # Build this documentation. -> bjam -] - -[endsect] - -[endsect] - diff --git a/doc/introduction.qbk b/doc/introduction.qbk deleted file mode 100644 index f91d343f..00000000 --- a/doc/introduction.qbk +++ /dev/null @@ -1,80 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Introduction] - -Contract Programming allows to specify preconditions, postconditions, and class invariants that are automatically checked when functions are executed at run-time. -These conditions assert program specifications within the source code itself allowing to find bugs more quickly during testing, making the code self-documenting, and increasing overall software quality (see __Contract_Programming_Overview__). - -For example, consider the following function `inc` that increments its argument `x` by `1` and let's write its contract using code comments (see [@../../example/features/introduction_comments.cpp =introduction_comments.cpp=]): - -[import ../example/features/introduction_comments.cpp] -[introduction_comments] - -The precondition states that at function entry the argument `x` must be strictly smaller than the maximum allowable value of its type (so it can be incremented by `1` without overflowing). -The postcondition states that at function exit the argument `x` must be incremented by `1` with respect to the /old value/ `x` had before executing the function indicated here by [^['oldof]`(x)` (note that postconditions shall be checked only when the execution of the function body did not throw an exception). - -Now let's program this function and its contract using this library (see [@../../example/features/introduction.cpp =introduction.cpp=] and __Non_Member_Functions__): - -[import ../example/features/introduction.cpp] -[introduction] - -When the above function `inc` is called, this library will: - -* First, execute the functor passed to `.precondition(...)` that asserts `inc` preconditions. -* Then, execute `inc` body (i.e., all the code that follows the `boost::contract::check c = ...` declaration). -* Last, execute the functor passed to `.postcondition(...)` that asserts `inc` postconditions (unless `inc` body threw an exception). - -For example, if there is a bug in the code calling `inc` so that the function is called with `x` equal to `std::numeric_limits::max()` then the program will terminate with an error message similar to the following (and it will be evident that the bug is in the calling code): - -[pre -precondition assertion "x < std::numeric_limits::max()" failed: file "introduction.cpp", line 17 -] - -Instead, if there is a bug in the implementation of `inc` so that `x` is not incremented by `1` after the execution of the function body then the program will terminate with an error message similar to the following (and it will be evident that the bug is in `inc` body): -[footnote -In this example the function body is composed of a single trivial instruction `++x` so it easy to check by visual inspection that it does not contain any bug and it will always increment `x` by `1` thus the function postcondition will never fail. -In real code, function bodies are rarely this simple and can hide bugs that make checking postconditions useful. -] - -[pre -postcondition assertion "x == *old_x + 1" failed: file "introduction.cpp", line 20 -] - -By default, when an assertion fails this library prints an error message such the ones above to the standard error `std::cerr` and terminates the program calling `std::terminate` (this behaviour can be customized to take any user-specified action including throwing exceptions, see __Throw_on_Failure__). -Note that the error messages printed by this library contain all the information necessary to easily and uniquely identify the point in the code at which the contract assertions fail. -[footnote -*Rationale:* -The assertion failure message printed by this library follows a format similar to the message printed by Clang when the C-style `assert` macro fails. -] - -[note -C++11 lambda functions are necessary to use this library without manually writing a significant amount of boiler-plate code to program the functors that assert the contracts (see __No_Lambda_Functions__). -Otherwise, this library does not use other C++11 features and should work on most modern C++ compilers (see __Getting_Started__). -] - -In addition to contracts for simple non-member functions as shown the in the example above, this library allows to program contracts for constructors, destructors, and member functions. -These can check class invariants and can also /subcontract/ inheriting and extending contracts from base classes (see [@../../example/features/introduction_public.cpp =introduction_public.cpp=] and __Public_Function_Overrides__): -[footnote -The `pushable` base class is used in this example just to show subcontracting, it is somewhat arbitrary and it will likely not appear in real code. -] - -[import ../example/features/introduction_public.cpp] -[introduction_public] - -[heading Language Support] - -The authors of this library advocate for contracts to be added to the core language. -Adding contract programming to the C++ standard has a number of advantages over any library implementation (shorter and more concise syntax to program contracts, specify contracts in declarations instead of definitions, enforce contract constant-correctness, expected faster compile- and run-time, vendors could develop static analysis tools to recognize and check contracts statically when possible, compiler optimizations could be improved based on contract conditions, etc.). - -Unfortunately, detailed and complete proposals to add contracts to the C++ standard such as __N1962__ were rejected by the C++ standard committee and it is not clear if the current proposal for adding contracts to C++ __P0380__ will actually be accepted by the standard. -[footnote -The authors find attractive the syntax that uses C++11 attributes `[[...]]` to specify contracts as indicated in __P0380__. -] -In any case, at least for now __P0380__ only supports pre- and postconditions while lacking basic features such as class invariants and old values in postconditions, not to mention the lack of more advanced features like subcontracting, all these features are instead supported by this library (see __Feature_Summary__ for a detailed comparison between the features supported by this library and the ones listed in different contract programming proposals, see __Bibliography__ for a list of references considered in designing and implementing this library including the vast majority of contract programming proposals submitted to the C++ standard committee). - -[endsect] - diff --git a/doc/main.qbk b/doc/main.qbk deleted file mode 100644 index 89ef5653..00000000 --- a/doc/main.qbk +++ /dev/null @@ -1,155 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[library Boost.Contract - [quickbook 1.5] - [version 1.0] - [authors [Caminiti lorcaminiti@gmail.com, Lorenzo]] - [copyright 2008-2017 Lorenzo Caminiti] - [license Distributed under the Boost Software License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at [@http://www.boost.org/LICENSE_1_0.txt])] -] - -[def __Introduction__ [link boost_contract.introduction Introduction]] -[def __Full_Table_of_Contents__ [link boost_contract.full_table_of_contents Full Table of Contents]] - -[def __Getting_Started__ [link boost_contract.getting_started Getting Started]] -[def __This_Documentation__ [link boost_contract.getting_started.this_documentation This Documentation]] -[def __Compilers_and_Platforms__ [link boost_contract.getting_started.compilers_and_platforms Compilers and Platforms]] -[def __Code_Organization__ [link boost_contract.getting_started.code_organization Code Organization]] -[def __Install_and_Compile__ [link boost_contract.getting_started.install_and_compile Install and Compile]] - -[def __Contract_Programming_Overview__ [link boost_contract.contract_programming_overview Contract Programming Overview]] -[def __Assertions__ [link boost_contract.contract_programming_overview.assertions Assertions]] -[def __Benefits_and_Costs__ [link boost_contract.contract_programming_overview.benefits_and_costs Benefits and Costs]] -[def __Function_Calls__ [link boost_contract.contract_programming_overview.function_calls Function Calls]] -[def __Public_Function_Calls__ [link boost_contract.contract_programming_overview.public_function_calls Public Function Calls]] -[def __Constructor_Calls__ [link boost_contract.contract_programming_overview.constructor_calls Constructor Calls]] -[def __Destructor_Calls__ [link boost_contract.contract_programming_overview.destructor_calls Destructor Calls]] -[def __Constant_Correctness__ [link boost_contract.contract_programming_overview.constant_correctness Constant-Correctness]] -[def __Specification_vs_Implementation__ [link boost_contract.contract_programming_overview.specification_vs__implementation Specification vs. Implementation]] -[def __On_Contract_Failure__ [link boost_contract.contract_programming_overview.on_contract_failure On Contract Failure]] -[def __Feature_Summary__ [link boost_contract.contract_programming_overview.feature_summary Feature Summary]] - -[def __Tutorial__ [link boost_contract.tutorial Tutorial]] -[def __Non_Member_Functions__ [link boost_contract.tutorial.non_member_functions Non-Member Functions]] -[def __Preconditions__ [link boost_contract.tutorial.preconditions Preconditions]] -[def __Postconditions__ [link boost_contract.tutorial.postconditions Postconditions]] -[def __Return_Value__ [link boost_contract.tutorial.return_value Return Value]] -[def __Old_Values__ [link boost_contract.tutorial.old_values Old Values]] -[def __Exception_Guarantees__ [link boost_contract.tutorial.exception_guarantees Exception Guarantees]] -[def __Class_Invariants__ [link boost_contract.tutorial.class_invariants Class Invariants]] -[def __Constructors__ [link boost_contract.tutorial.constructors Constructors]] -[def __Destructors__ [link boost_contract.tutorial.destructors Destructors]] -[def __Public_Functions__ [link boost_contract.tutorial.public_functions Public Functions]] -[def __Virtual_Public_Functions__ [link boost_contract.tutorial.virtual_public_functions Virtual Public Functions]] -[def __Public_Function_Overrides__ [link boost_contract.tutorial.public_function_overrides__subcontracting_ Public Function Overrides]] -[def __Public_Function_Overrides_Subcontracting__ [link boost_contract.tutorial.public_function_overrides__subcontracting_ Public Function Overrides (Subcontracting)]] -[def __Base_Classes__ [link boost_contract.tutorial.base_classes__subcontracting_ Base Classes]] -[def __Base_Classes_Subcontracting__ [link boost_contract.tutorial.base_classes__subcontracting_ Base Classes (Subcontracting)]] -[def __Static_Public_Functions__ [link boost_contract.tutorial.static_public_functions Static Public Functions]] - -[def __Advanced__ [link boost_contract.advanced Advanced]] -[def __Pure_Virtual_Public_Functions__ [link boost_contract.advanced.pure_virtual_public_functions Pure Virtual Public Functions]] -[def __Optional_Return_Value__ [link boost_contract.advanced.optional_return_value Optional Return Value]] -[def __Private_and_Protected_Functions__ [link boost_contract.advanced.private_and_protected_functions Private and Protected Functions]] -[def __Friend_Functions__ [link boost_contract.advanced.friend_functions Friend Functions]] -[def __Function_Overloads__ [link boost_contract.advanced.function_overloads Function Overloads]] -[def __Lambdas_Loops_Code_Blocks__ [link boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__ Lambdas, Loops, Code Blocks]] -[def __Lambdas_Loops_Code_Blocks_and_constexpr__ [link boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__ Lambdas, Loops, Code Blocks (and `constexpr`)]] -[def __Implementation_Checks__ [link boost_contract.advanced.implementation_checks Implementation Checks]] -[def __Old_Copies_at_Body__ [link boost_contract.advanced.old_copies_at_body Old Copies at Body]] -[def __Named_Overrides__ [link boost_contract.advanced.named_overrides Named Overrides]] -[def __Access_Specifiers__ [link boost_contract.advanced.access_specifiers Access Specifiers]] -[def __Throw_on_Failure__ [link boost_contract.advanced.throw_on_failure__and__noexcept__ Throw on Failure]] -[def __Throw_on_Failure_and_noexcept__ [link boost_contract.advanced.throw_on_failure__and__noexcept__ Throw on Failure (and `noexcept`)]] - -[def __Extras__ [link boost_contract.extras Extras]] -[def __Old_Value_Requirements__ [link boost_contract.extras.old_value_requirements__templates_ Old Value Requirements]] -[def __Old_Value_Requirements_Templates__ [link boost_contract.extras.old_value_requirements__templates_ Old Value Requirements (Templates)]] -[def __Assertion_Requirements__ [link boost_contract.extras.assertion_requirements__templates_ Assertion Requirements]] -[def __Assertion_Requirements_Templates__ [link boost_contract.extras.assertion_requirements__templates_ Assertion Requirements (Templates)]] -[def __Volatile_Public_Functions__ [link boost_contract.extras.volatile_public_functions Volatile Public Functions]] -[def __Move_Operations__ [link boost_contract.extras.move_operations Move Operations]] -[def __Unions__ [link boost_contract.extras.unions Unions]] -[def __Disable_Contract_Checking__ [link boost_contract.extras.disable_contract_checking Disable Contract Checking]] -[def __Assertion_Levels__ [link boost_contract.extras.assertion_levels Assertion Levels]] -[def __Disable_Contract_Compilation__ [link boost_contract.extras.disable_contract_compilation__macro_interface_ Disable Contract Compilation]] -[def __Disable_Contract_Compilation_Macro_Interface__ [link boost_contract.extras.disable_contract_compilation__macro_interface_ Disable Contract Compilation (Macro Interface)]] -[def __Separate_Body_Implementation__ [link boost_contract.extras.separate_body_implementation Separate Body Implementation]] -[def __No_Lambda_Functions__ [link boost_contract.extras.no_lambda_functions__no_c__11_ No Lambda Functions]] -[def __No_Lambda_Functions_No_CXX11__ [link boost_contract.extras.no_lambda_functions__no_c__11_ No Lambda Functions (No C++11)]] -[def __No_Macros__ [link boost_contract.extras.no_macros__and_no_variadic_macros_ No Macros]] -[def __No_Macros_and_No_Variadic_Macros__ [link boost_contract.extras.no_macros__and_no_variadic_macros_ No Macros (and No Variadic Macros)]] - -[def __Reference__ [@reference.html Reference]] -[def __Examples__ [link boost_contract.examples Examples]] -[def __Release_Notes__ [link boost_contract.release_notes Release Notes]] -[def __Bibliography__ [link boost_contract.bibliography Bibliography]] -[def __Acknowledgments__ [link boost_contract.acknowledgments Acknowledgments]] - -[def __AND__ [link and_anchor [^['AND]]]] -[def __OR__ [link or_anchor [^['OR]]]] - -[def __Bright04__ [link Bright04_anchor \[Bright04\]]] -[def __Bright04b__ [link Bright04b_anchor \[Bright04b\]]] -[def __C2__ [link C2_anchor \[C2\]]] -[def __Chrome__ [link Chrome_anchor \[Chrome\]]] -[def __Cline90__ [link Cline90_anchor \[Cline90\]]] -[def __CodeContracts__ [link CodeContracts_anchor \[CodeContracts\]]] -[def __iContract__ [link iContract_anchor \[iContract\]]] -[def __Nana__ [link Nana_anchor \[Nana\]]] -[def __Hoare73__ [link Hoare73_anchor \[Hoare73\]]] -[def __Jcontract__ [link Jcontract_anchor \[Jcontract\]]] -[def __Lindrud04__ [link Lindrud04_anchor \[Lindrud04\]]] -[def __Maley99__ [link Maley99_anchor \[Maley99\]]] -[def __Meyer97__ [link Meyer97_anchor \[Meyer97\]]] -[def __Mitchell02__ [link Mitchell02_anchor \[Mitchell02\]]] -[def __N1613__ [link N1613_anchor \[N1613\]]] -[def __N1866__ [link N1866_anchor \[N1866\]]] -[def __N1962__ [link N1962_anchor \[N1962\]]] -[def __N2081__ [link N2081_anchor \[N2081\]]] -[def __N2914__ [link N2914_anchor \[N2914\]]] -[def __N3613__ [link N3613_anchor \[N3613\]]] -[def __P0380__ [link P0380_anchor \[P0380\]]] -[def __SPARKAda__ [link SPARKAda_anchor \[SPARKAda\]]] -[def __SpecSharp__ [link SpecSharp_anchor \[SpecSharp\]]] -[def __Stroustrup94__ [link Stroustrup94_anchor \[Stroustrup94\]]] -[def __Stroustrup13__ [link Stroustrup13_anchor \[Stroustrup13\]]] -[def __Tandin04__ [link Tandin04_anchor \[Tandin04\]]] - -[def __substitution_principle__ [@http://en.wikipedia.org/wiki/Liskov_substitution_principle substitution principle]] - -[:['["Our field needs more formality, but the profession has not realized it yet.]]] -[:['-- Bertrand Meyer (see __Meyer97__ page 400)]] - -This library implements -[@http://en.wikipedia.org/wiki/Design_by_contract Contract Programming] (a.k.a., Design by Contract or DbC) -[footnote -Design by Contract (DbC) is a registered trademark of the Eiffel Software company and it was first introduced by the Eiffel programming language (see __Meyer97__). -] -for the C++ programming language. -All Contract Programming features are supported by this library: subcontracting, class invariants (also for static and volatile member functions), postconditions (with old and return values), preconditions, customizable actions on assertion failure (e.g., terminate the program or throw exceptions), optional compilation of assertions, disable assertions while already checking other assertions (to avoid infinite recursion), and more (see __Feature_Summary__). - -[note -In one of its previous revisions, this library passed Boost formal review and it was accepted into the Boost libraries (see [@https://groups.google.com/forum/?fromgroups=#!topic/boost-list/jQ7OjAmos_Y]). -However, the authors have not had time to add this library to a Boost release yet. -] - -This library source is hosted at [@https://github.com/lcaminiti/boost-contract]. - -[include introduction.qbk] -[include full_table_of_contents.qbk] -[include getting_started.qbk] -[include contract_programming_overview.qbk] -[include tutorial.qbk] -[include advanced.qbk] -[include extras.qbk] -[include examples.qbk] -[xinclude reference.xml] -[include release_notes.qbk] -[include bibliography.qbk] -[include acknowledgments.qbk] - diff --git a/doc/release_notes.qbk b/doc/release_notes.qbk deleted file mode 100644 index f465ddd8..00000000 --- a/doc/release_notes.qbk +++ /dev/null @@ -1,171 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Release Notes] - -This section contains notes on all releases of this library (from the latest to the oldest). - -[section Release 0.5.0] - -September 2, 2017 - -Notes: - -# Using plain C++ code instead of macros to program contracts. - # The removed macros very hard to use because they required programmers to learn a domain-specific embedded language that replaced the usual C++ syntax for declaring functions and classes. - # The removed macros also made the code less readable, increased compilation time (because of extensive preprocessor meta-programming), and gave cryptic compiler errors. - # However, the removed macros more correctly specified contracts in code declarations instead of definitions, and they completely removed extra code when contracts were disabled (both of those can be done by the current version of this library but at the cost of manually writing some boiler-plate code which was previous automatically handled by the macros instead, see __Separate_Body_Implementation__ and __Disable_Contract_Compilation__). -# Simplified the library by removing some extra features that were not directly related to contract programming, specifically: - # Removed loop variants (because these are rarely if ever used). - # Removed named and deduced parameters (because these can be programmed directly using [@http://www.boost.org/doc/libs/release/libs/parameter/doc/html/index.html Boost.Parameter]). - # Removed concepts (because these can be programmed directly using [@http://www.boost.org/doc/libs/1_65_0/libs/concept_check/concept_check.htm Boost.ConceptCheck]). - # Removed emulation of virtual specifiers `override`, `final`, and `new` (because `override` can be programmed directly using C++11, while `final` and `new` are rarely if ever used). - # Removed `static_assert` emulation (because this can be programmed directly using C++11, or using [@http://www.boost.org/doc/libs/1_65_0/doc/html/boost_staticassert.html Boost.StaticAssert]). -# Ensuring that old values and return values are copied only once even when subcontracting is used with multiple inheritance. -# Improved template meta-programming algorithm that searches the inheritance tree for subcontracting when multiple inheritance is used. -# Exception specifications and function-try blocks apply also to exceptions thrown by the contracts, and not just to exceptions thrown by the body. -# Added contracts for exception guarantees (using `.except(...)`, etc.). -# Added predefined assertion levels for "audit" and "axiom". -# Added `call_if` and `condition_if` (assertions requirements were supported also by previous revisions of this library but they were handled by internal code generated by the contract macros). - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_5_0 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.4.1] - -[note -This revision of the library passed Boost formal review and it was accepted into the Boost libraries (see [@https://groups.google.com/forum/?fromgroups=#!topic/boost-list/jQ7OjAmos_Y]). -However, the authors have not had time to add this library to a Boost release yet. -] - -August 20, 2012 - -Notes: - -# Using non-fix-spaced font in Full Table of Contents section. -# Added a couple of notes to the documentation. -# Changed `CONTRACT_MEMBER_BODY(class_type, function_name)` to `class_type::CONTRACT_MEMBER_BODY(function_name)` so the macro can also be used to declare derived classes avoiding using the library syntax even when the base class has contracts. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_4_1 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.4.0] - -June 4, 2012 - -Notes: - -# Simplified syntax by reducing extra parenthesis to the bare necessary minimum (using some of the preprocessor parsing techniques originally introduced by Boost.LocalFunction). -# Postcondition old values only copy the old-of expression (e.g., copy just vector size instead of entire vector). -This improves performance and introduces the `ConstantCopyConstructible` requirement just for the old value expression type (e.g., a vector might not be copyable while its size always is because it is an integral type). -Removed the `copyable` tag. -# Body defined outside the macros (so compiler-errors for definitions retain their usual meaning). -# Added `CONTRACT_CLASS` macro and removed the need to duplicate declaration elements (do not repeat function declaration, do not repeat class name in function declaration, etc). -# Using `_TPL` macros so to reduce compile-time (instead of internally making all templates contract functions so to use `typename` freely). -# Overloading no longer requires unique parameter names. -# Added C++11-like virtual specifiers. -# Added constant assertions plus constant-expressions for select assertion if-conditions and for loop variants. -# Added named and deduced parameters. -# Added concept checking. -# Removed the interface to use the library without the macro (programmers were required to write too much boiler-plate code for the non-macro interface to be actually usable, plus supporting both the macro and non-macro interfaces limited what the macros could do). - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_4_0 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.3.490] - -March 7, 2010 - -Notes: - -# Added support and examples for `volatile`, `auto`, `explicit`, `export`, `extern`, `friend`, `inline`, `struct`, and `throw` (for exception specifications). -# Documented that `union` cannot be contracted. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_3_490 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.3.469] - -February 21, 2010 - -Notes: - -# Removed use of `self`, `variable.now`, and `variable.old` in writing contracts. -Object `this` and variables are now accessed as usual in member functions. -`CONTRACT_OLDOF(variable)` is used to access old values in postconditions. -# Added `(precondition)`, `(postcondition)`, and `(body)` to specify contracts within the function signature sequence. -If no preconditions then `(precondition) ({...})` is simply omitted from the sequence (same for postconditions, body is mandatory instead). -For non-void functions, users can name the result argument with `(postcondition) (result-name) ({...})`. -# Changed contract class template to use same syntax as Boost.Function (i.e., `F` function type). -# Added support for free functions and static member functions. -# Added support for subcontracting with multiple inheritance. -# Added static class invariants which are always checked (also at constructors entry, destructor exit, and by static member functions). -# Added block invariants and Eiffel-like loop variants. -# Added handlers to customize action on contract failure (default to `std::terminate()`). -# Removed feature for automatic contract documentation using Doxygen (this is not compatible with added `(precondition)`, `(postcondition)`, and `(body)` because Doxygen preprocessor is not capable to handle Boost.Preprocessor sequences). -# Rewritten entire documentation (now using Boost.QuickBook instead of Doxygen). - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_3_469 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.2.190] - -November 21, 2009 - -Notes: - -# Compiled using both GCC (Linux and Cygwin) and MSVC (Windows XP). -# Required to use void to specify empty function argument list. -This is to comply with C++03 standard that does not allow to pass empty macro parameters so it does not support empty preprocessor sequences `()`. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_2_190 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.1.126] - -June 17, 2009 - -Notes: - -# Completed first documentation draft. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_1_126 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.1.55] - -April 19, 2009 - -Notes: - -# Reorganized files to cleanup root directory. -# Added installation program. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_1_55 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[section Release 0.1.50] - -April 19, 2009 - -Notes: - -# First public release. - -Released [@https://github.com/lcaminiti/boost-contract/tree/release/0_1_50 files] (e.g., select "Clone or download" and then "Download ZIP"). - -[endsect] - -[endsect] - diff --git a/doc/src/boost.xml b/doc/src/boost.xml deleted file mode 100644 index effced04..00000000 --- a/doc/src/boost.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - The Boost C++ Libraries BoostBook Documentation Subset - - - What's Included in This Document - - This document represents only a subset of the full Boost - documentation: that part which is generated from BoostBook or - QuickBook sources. Eventually all Boost libraries may use these - formats, but in the meantime, much of Boost's documentation is not - available here. Please - see http://www.boost.org/libs - for complete documentation. - - - - Documentation for some of the libraries described in this document is - available in alternative formats: - - - HTML - - - - - PDF - - - - - - - - The Boost C++ Libraries (BoostBook Subset) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Boost Tools - - - Boost developers, testers, and maintainers have developed various programs to - help with the administration of the Boost Libraries. Like everything else about - Boost, these tools are available in source form, and are part of the regular - Boost distribution. - - - Users may find these tools useful when porting Boost libraries to a new platform, - or for use with their own applications. - - - - - - - - - - - - - diff --git a/doc/src/boostbook.css b/doc/src/boostbook.css deleted file mode 100644 index d42b3c02..00000000 --- a/doc/src/boostbook.css +++ /dev/null @@ -1,700 +0,0 @@ - -/*============================================================================= -Copyright (c) 2004 Joel de Guzman -http://spirit.sourceforge.net/ - -Copyright 2013 Niall Douglas additions for colors and alignment. -Copyright 2013 Paul A. Bristow additions for more colors and alignments. - -Distributed under the Boost Software License, Version 1.0. (See accompany- -ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -=============================================================================*/ - -/*============================================================================= -Body defaults -=============================================================================*/ - - body - { - margin: 1em; - font-family: sans-serif; - } - -/*============================================================================= -Paragraphs -=============================================================================*/ - - p - { - text-align: left; - font-size: 10pt; - line-height: 1.15; - } - -/*============================================================================= -Program listings -=============================================================================*/ - - /* Code on paragraphs */ - p tt.computeroutput - { - font-size: 9pt; - } - - pre.synopsis - { - font-size: 9pt; - margin: 1pc 4% 0pc 4%; - padding: 0.5pc 0.5pc 0.5pc 0.5pc; - } - - .programlisting, - .screen - { - font-size: 9pt; - display: block; - margin: 1pc 4% 0pc 4%; - padding: 0.5pc 0.5pc 0.5pc 0.5pc; - } - - /* Program listings in tables don't get borders */ - td .programlisting, - td .screen - { - margin: 0pc 0pc 0pc 0pc; - padding: 0pc 0pc 0pc 0pc; - } - -/*============================================================================= -Headings -=============================================================================*/ - - h1, h2, h3, h4, h5, h6 - { - text-align: left; - margin: 1em 0em 0.5em 0em; - font-weight: bold; - } - - h1 { font-size: 140%; } - h2 { font-weight: bold; font-size: 140%; } - h3 { font-weight: bold; font-size: 130%; } - h4 { font-weight: bold; font-size: 120%; } - h5 { font-weight: normal; font-style: italic; font-size: 110%; } - h6 { font-weight: normal; font-style: italic; font-size: 100%; } - - /* Top page titles */ - title, - h1.title, - h2.title - h3.title, - h4.title, - h5.title, - h6.title, - .refentrytitle - { - font-weight: bold; - margin-bottom: 1pc; - } - - h1.title { font-size: 140% } - h2.title { font-size: 140% } - h3.title { font-size: 130% } - h4.title { font-size: 120% } - h5.title { font-size: 110% } - h6.title { font-size: 100% } - - .section h1 - { - margin: 0em 0em 0.5em 0em; - font-size: 140%; - } - - .section h2 { font-size: 140% } - .section h3 { font-size: 130% } - .section h4 { font-size: 120% } - .section h5 { font-size: 110% } - .section h6 { font-size: 100% } - - /* Code on titles */ - h1 tt.computeroutput { font-size: 140% } - h2 tt.computeroutput { font-size: 140% } - h3 tt.computeroutput { font-size: 130% } - h4 tt.computeroutput { font-size: 130% } - h5 tt.computeroutput { font-size: 130% } - h6 tt.computeroutput { font-size: 130% } - - -/*============================================================================= -Author -=============================================================================*/ - - h3.author - { - font-size: 100% - } - -/*============================================================================= -Lists -=============================================================================*/ - - li - { - font-size: 10pt; - line-height: 1.3; - } - - /* Unordered lists */ - ul - { - text-align: left; - } - - /* Ordered lists */ - ol - { - text-align: left; - } - -/*============================================================================= -Links -=============================================================================*/ - - a - { - text-decoration: none; /* no underline */ - } - - a:hover - { - text-decoration: underline; - } - -/*============================================================================= -Spirit style navigation -=============================================================================*/ - - .spirit-nav - { - text-align: right; - } - - .spirit-nav a - { - color: white; - padding-left: 0.5em; - } - - .spirit-nav img - { - border-width: 0px; - } - -/*============================================================================= -Copyright footer -=============================================================================*/ - .copyright-footer - { - text-align: right; - font-size: 70%; - } - - .copyright-footer p - { - text-align: right; - font-size: 80%; - } - -/*============================================================================= -Table of contents -=============================================================================*/ - - div.toc - { - margin: 1pc 4% 0pc 4%; - padding: 0.1pc 1pc 0.1pc 1pc; - font-size: 80%; - line-height: 1.15; - } - - .boost-toc - { - float: right; - padding: 0.5pc; - } - - /* Code on toc */ - .toc .computeroutput { font-size: 120% } - - /* No margin on nested menus */ - - .toc dl dl { margin: 0; } - -/*============================================================================= -Tables -=============================================================================*/ - - .table-title, - div.table p.title - { - margin-left: 4%; - padding-right: 0.5em; - padding-left: 0.5em; - } - - .informaltable table, - .table table - { - width: 92%; - margin-left: 4%; - margin-right: 4%; - } - - div.informaltable table, - div.table table - { - padding: 4px; - } - - /* Table Cells */ - div.informaltable table tr td, - div.table table tr td - { - padding: 0.5em; - text-align: left; - font-size: 9pt; - } - - div.informaltable table tr th, - div.table table tr th - { - padding: 0.5em 0.5em 0.5em 0.5em; - border: 1pt solid white; - font-size: 80%; - } - - table.simplelist - { - width: auto !important; - margin: 0em !important; - padding: 0em !important; - border: none !important; - } - table.simplelist td - { - margin: 0em !important; - padding: 0em !important; - text-align: left !important; - font-size: 9pt !important; - border: none !important; - } - -/*============================================================================= -Blurbs -=============================================================================*/ - - div.note, - div.tip, - div.important, - div.caution, - div.warning, - p.blurb - { - font-size: 9pt; /* A little bit smaller than the main text */ - line-height: 1.2; - display: block; - margin: 1pc 4% 0pc 4%; - padding: 0.5pc 0.5pc 0.5pc 0.5pc; - } - - p.blurb img - { - padding: 1pt; - } - -/*============================================================================= -Variable Lists -=============================================================================*/ - - div.variablelist - { - margin: 1em 0; - } - - /* Make the terms in definition lists bold */ - div.variablelist dl dt, - span.term - { - font-weight: bold; - font-size: 10pt; - } - - div.variablelist table tbody tr td - { - text-align: left; - vertical-align: top; - padding: 0em 2em 0em 0em; - font-size: 10pt; - margin: 0em 0em 0.5em 0em; - line-height: 1; - } - - div.variablelist dl dt - { - margin-bottom: 0.2em; - } - - div.variablelist dl dd - { - margin: 0em 0em 0.5em 2em; - font-size: 10pt; - } - - div.variablelist table tbody tr td p, - div.variablelist dl dd p - { - margin: 0em 0em 0.5em 0em; - line-height: 1; - } - -/*============================================================================= -Misc -=============================================================================*/ - - /* Title of books and articles in bibliographies */ - span.title - { - font-style: italic; - } - - span.underline - { - text-decoration: underline; - } - - span.strikethrough - { - text-decoration: line-through; - } - - /* Copyright, Legal Notice */ - div div.legalnotice p - { - text-align: left - } - -/*============================================================================= -Colors -=============================================================================*/ - - @media screen - { - body { - background-color: #FFFFFF; - color: #000000; - } - - /* Syntax Highlighting */ - .keyword { color: #0000AA; } - .identifier { color: #000000; } - .special { color: #707070; } - .preprocessor { color: #402080; } - .char { color: teal; } - .comment { color: #800000; } - .string { color: teal; } - .number { color: teal; } - .white_bkd { background-color: #FFFFFF; } - .dk_grey_bkd { background-color: #999999; } - - /* Links */ - a, a .keyword, a .identifier, a .special, a .preprocessor - a .char, a .comment, a .string, a .number - { - color: #005a9c; - } - - a:visited, a:visited .keyword, a:visited .identifier, - a:visited .special, a:visited .preprocessor a:visited .char, - a:visited .comment, a:visited .string, a:visited .number - { - color: #9c5a9c; - } - - h1 a, h2 a, h3 a, h4 a, h5 a, h6 a, - h1 a:hover, h2 a:hover, h3 a:hover, h4 a:hover, h5 a:hover, h6 a:hover, - h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited - { - text-decoration: none; /* no underline */ - color: #000000; - } - - /* Copyright, Legal Notice */ - .copyright - { - color: #666666; - font-size: small; - } - - div div.legalnotice p - { - color: #666666; - } - - /* Program listing */ - pre.synopsis - { - border: 1px solid #DCDCDC; - } - - .programlisting, - .screen - { - border: 1px solid #DCDCDC; - } - - td .programlisting, - td .screen - { - border: 0px solid #DCDCDC; - } - - /* Blurbs */ - div.note, - div.tip, - div.important, - div.caution, - div.warning, - p.blurb - { - border: 1px solid #DCDCDC; - } - - /* Table of contents */ - div.toc - { - border: 1px solid #DCDCDC; - } - - /* Tables */ - div.informaltable table tr td, - div.table table tr td - { - border: 1px solid #DCDCDC; - } - - div.informaltable table tr th, - div.table table tr th - { - background-color: #F0F0F0; - border: 1px solid #DCDCDC; - } - - .copyright-footer - { - color: #8F8F8F; - } - - /* Misc */ - span.highlight - { - color: #00A000; - } - } - - @media print - { - /* Links */ - a - { - color: black; - } - - a:visited - { - color: black; - } - - .spirit-nav - { - display: none; - } - - /* Program listing */ - pre.synopsis - { - border: 1px solid gray; - } - - .programlisting, - .screen - { - border: 1px solid gray; - } - - td .programlisting, - td .screen - { - border: 0px solid #DCDCDC; - } - - /* Table of contents */ - div.toc - { - border: 1px solid gray; - } - - .informaltable table, - .table table - { - border: 1px solid gray; - border-collapse: collapse; - } - - /* Tables */ - div.informaltable table tr td, - div.table table tr td - { - border: 1px solid gray; - } - - div.informaltable table tr th, - div.table table tr th - { - border: 1px solid gray; - } - - table.simplelist tr td - { - border: none !important; - } - - /* Misc */ - span.highlight - { - font-weight: bold; - } - } - -/*============================================================================= -Images -=============================================================================*/ - - span.inlinemediaobject img - { - vertical-align: middle; - } - -/*============================================================================== -Super and Subscript: style so that line spacing isn't effected, see -http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=1&postId=5341 -==============================================================================*/ - -sup, -sub { -height: 0; -line-height: 1; -vertical-align: baseline; -position: relative; - -} - -/* For internet explorer: */ - -* html sup, -* html sub { -vertical-align: bottom; -} - -sup { -bottom: 1ex; -} - -sub { -top: .5ex; -} - -/*============================================================================== -Indexes: pretty much the same as the TOC. -==============================================================================*/ - - .index - { - font-size: 80%; - padding-top: 0px; - padding-bottom: 0px; - margin-top: 0px; - margin-bottom: 0px; - margin-left: 0px; - } - - .index ul - { - padding-left: 3em; - } - - .index p - { - padding: 2px; - margin: 2px; - } - - .index-entry-level-0 - { - font-weight: bold; - } - - .index em - { - font-weight: bold; - } - - -/*============================================================================== -Alignment and coloring use 'role' feature, available from Quickbook 1.6 up. -Added from Niall Douglas for role color and alignment. -http://article.gmane.org/gmane.comp.lib.boost.devel/243318 -*/ - -/* Add text alignment (see http://www.w3schools.com/cssref/pr_text_text-align.asp) */ -span.aligncenter -{ - display: inline-block; width: 100%; text-align: center; -} -span.alignright -{ - display: inline-block; width: 100%; text-align: right; -} -/* alignleft is the default. */ -span.alignleft -{ - display: inline-block; width: 100%; text-align: left; -} - -/* alignjustify stretches the word spacing so that each line has equal width -within a chosen fraction of page width (here arbitrarily 20%). -*Not* useful inside table items as the column width remains the total string width. -Nor very useful, except to temporarily restrict the width. -*/ -span.alignjustify -{ - display: inline-block; width: 20%; text-align: justify; -} - -/* Text colors. -Names at http://www.w3.org/TR/2002/WD-css3-color-20020219/ 4.3. X11 color keywords. -Quickbook Usage: [role red Some red text] - -*/ -span.red { inline-block; color: red; } -span.green { color: green; } -span.lime { color: #00FF00; } -span.blue { color: blue; } -span.navy { color: navy; } -span.yellow { color: yellow; } -span.magenta { color: magenta; } -span.indigo { color: #4B0082; } -span.cyan { color: cyan; } -span.purple { color: purple; } -span.gold { color: gold; } -span.silver { color: silver; } /* lighter gray */ -span.gray { color: #808080; } /* light gray */ diff --git a/doc/src/docutils.css b/doc/src/docutils.css deleted file mode 100644 index 620cf861..00000000 --- a/doc/src/docutils.css +++ /dev/null @@ -1,275 +0,0 @@ -/* -:Author: David Goodger -:Contact: goodger@python.org -:Date: $Date$ -:Revision: $Revision$ -:Copyright: This stylesheet has been placed in the public domain. - -Default cascading style sheet for the HTML output of Docutils. - -See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to -customize this style sheet. -*/ - -/* used to remove borders from tables and images */ -.borderless, table.borderless td, table.borderless th { - border: 0 } - -table.borderless td, table.borderless th { - /* Override padding for "table.docutils td" with "! important". - The right padding separates the table cells. */ - padding: 0 0.5em 0 0 ! important } - -.first { - /* Override more specific margin styles with "! important". */ - margin-top: 0 ! important } - -.last, .with-subtitle { - margin-bottom: 0 ! important } - -.hidden { - display: none } - -a.toc-backref { - text-decoration: none ; - color: black } - -blockquote.epigraph { - margin: 2em 5em ; } - -dl.docutils dd { - margin-bottom: 0.5em } - -/* Uncomment (and remove this text!) to get bold-faced definition list terms -dl.docutils dt { - font-weight: bold } -*/ - -div.abstract { - margin: 2em 5em } - -div.abstract p.topic-title { - font-weight: bold ; - text-align: center } - -div.admonition, div.attention, div.caution, div.danger, div.error, -div.hint, div.important, div.note, div.tip, div.warning { - margin: 2em ; - border: medium outset ; - padding: 1em } - -div.admonition p.admonition-title, div.hint p.admonition-title, -div.important p.admonition-title, div.note p.admonition-title, -div.tip p.admonition-title { - font-weight: bold ; - font-family: sans-serif } - -div.attention p.admonition-title, div.caution p.admonition-title, -div.danger p.admonition-title, div.error p.admonition-title, -div.warning p.admonition-title { - color: red ; - font-weight: bold ; - font-family: sans-serif } - -/* Uncomment (and remove this text!) to get reduced vertical space in - compound paragraphs. -div.compound .compound-first, div.compound .compound-middle { - margin-bottom: 0.5em } - -div.compound .compound-last, div.compound .compound-middle { - margin-top: 0.5em } -*/ - -div.dedication { - margin: 2em 5em ; - text-align: center ; - font-style: italic } - -div.dedication p.topic-title { - font-weight: bold ; - font-style: normal } - -div.figure { - margin-left: 2em ; - margin-right: 2em } - -div.footer, div.header { - clear: both; - font-size: smaller } - -div.line-block { - display: block ; - margin-top: 1em ; - margin-bottom: 1em } - -div.line-block div.line-block { - margin-top: 0 ; - margin-bottom: 0 ; - margin-left: 1.5em } - -div.sidebar { - margin-left: 1em ; - border: medium outset ; - padding: 1em ; - background-color: #ffffee ; - width: 40% ; - float: right ; - clear: right } - -div.sidebar p.rubric { - font-family: sans-serif ; - font-size: medium } - -div.system-messages { - margin: 5em } - -div.system-messages h1 { - color: red } - -div.system-message { - border: medium outset ; - padding: 1em } - -div.system-message p.system-message-title { - color: red ; - font-weight: bold } - -div.topic { - margin: 2em } - -h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, -h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { - margin-top: 0.4em } - -h1.title { - text-align: center } - -h2.subtitle { - text-align: center } - -hr.docutils { - width: 75% } - -img.align-left { - clear: left } - -img.align-right { - clear: right } - -ol.simple, ul.simple { - margin-bottom: 1em } - -ol.arabic { - list-style: decimal } - -ol.loweralpha { - list-style: lower-alpha } - -ol.upperalpha { - list-style: upper-alpha } - -ol.lowerroman { - list-style: lower-roman } - -ol.upperroman { - list-style: upper-roman } - -p.attribution { - text-align: right ; - margin-left: 50% } - -p.caption { - font-style: italic } - -p.credits { - font-style: italic ; - font-size: smaller } - -p.label { - white-space: nowrap } - -p.rubric { - font-weight: bold ; - font-size: larger ; - color: maroon ; - text-align: center } - -p.sidebar-title { - font-family: sans-serif ; - font-weight: bold ; - font-size: larger } - -p.sidebar-subtitle { - font-family: sans-serif ; - font-weight: bold } - -p.topic-title { - font-weight: bold } - -pre.address { - margin-bottom: 0 ; - margin-top: 0 ; - font-family: serif ; - font-size: 100% } - -pre.literal-block, pre.doctest-block { - margin-left: 2em ; - margin-right: 2em } - -span.classifier { - font-family: sans-serif ; - font-style: oblique } - -span.classifier-delimiter { - font-family: sans-serif ; - font-weight: bold } - -span.interpreted { - font-family: sans-serif } - -span.option { - white-space: nowrap } - -span.pre { - white-space: pre } - -span.problematic { - color: red } - -span.section-subtitle { - /* font-size relative to parent (h1..h6 element) */ - font-size: 80% } - -table.citation { - border-left: solid 1px gray; - margin-left: 1px } - -table.docinfo { - margin: 2em 4em } - -table.docutils { - margin-top: 0.5em ; - margin-bottom: 0.5em } - -table.footnote { - border-left: solid 1px black; - margin-left: 1px } - -table.docutils td, table.docutils th, -table.docinfo td, table.docinfo th { - padding-left: 0.5em ; - padding-right: 0.5em ; - vertical-align: top } - -table.docutils th.field-name, table.docinfo th.docinfo-name { - font-weight: bold ; - text-align: left ; - white-space: nowrap ; - padding-left: 0 } - -h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, -h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { - font-size: 100% } - -ul.auto-toc { - list-style-type: none } diff --git a/doc/src/images/alert.png b/doc/src/images/alert.png deleted file mode 100644 index b4645bc7e7cd81f2818bf22aa898e95f89f7b154..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 603 zcmeAS@N?(olHy`uVBq!ia0vp^l0YoR!3-ps5|6h4Ddu7)&kzm{j@u9Y9{{=Y1AIbU zf%JpT46~{k9zA+AbLPwdAIsS2PzO_vNDmfMEtWH9&ip^auzMPVqn%}CB7>9&!}iGx z-;Xhv8px)lrL9@BCcs5vO&5cqu9T{h?38MTlmG^xxVH_1kB|46nGCkpmetkOTpSE4 zavV>eK0UdRp(B^!=?;d>5QYoO7|ac%0{lFz^%?x_8RR7yVthEP3>A&_q|CG#WW*RW zl{o(Y|IZtA$qVR2(~=;+U?7)dz)-XG0w_#43p^r=85p=efH0%e8j~47LDdr1h?3y^ zw370~qErUo#N?v<+|-oJLS?-v|XG0|S%xvNh*{8XkJOIEGZr$-Qt} zs7XP9Ey3he(pHrYspZRf78PH9`FH+W)~#!9NQ>E(|7f+bS8dIEdt&+3)9k$5zE@_n zwwz6h>zL57n052?|A&@wF+B45-}O%P&a!K2U&3G9nvuNo>8jg5#pWKJFg+#ZM_3KF z@0!U*M+MgC=JZ@&d`GA4#mi|OP1Q3WUuyYq=o{O;ODgJig+1&Ot|jSj5iH+p{qlah z-+>>`onNNZu_SEo{1c_>E?8^dWc*|KzHYTkoV#ab9htMb`jx;F%~$-4S3IxI_4a$B t(zNWy?!(WO+m-mQI!w5#7{UFM>Ew3T@2Uk;6oH;)@O1TaS?83{1OOIu3ZVc1 diff --git a/doc/src/images/blank.png b/doc/src/images/blank.png deleted file mode 100644 index 764bf4f0c3bb4a09960b04b6fa9c9024bca703bc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 374 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRdwrEa{HEjtmSN`?>!lvNA9*>Uz33 zhE&XXd(lylL4oIh!GZnHecj|txT>yO8>^qY%(y?B;Tppl#t7yOYze#vq#8^aMzDZb YLK^d5CO(feU_df>y85}Sb4q9e0Beb;@5Jms&t_+qirbvUVh|&#BatJPvqeMAG3eJI2P~{ToLa~KgB*G#^M#2_a3)VYn zVgvz1M%rd}-qW9r=_zaNV-N&yold8HOHftSx7PZF znWv3J5s?VPuss+I+C&6q#(KSmloGvO?*KD1ilVq*tyW{LH5!R%28alCU1K(zVKSM( zIR_#-JRt<)I7YwUPn1$)t@RT#D|H;v7=y)Pfubl7MbX&`M1*d)3jm2RW~{Zwi6BW5 z - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/10.png b/doc/src/images/callouts/10.png deleted file mode 100644 index 0426f516a497db7f9a989ae412c381123c882a59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 485 zcmVye?*7-J8XwLb#oWGHAsf2pa!fFY62Q0 z;mh~sbZC{ErT1M9yl|fLa(G!7hF#A2`>Lu`ydhOplks@`lQAalo|fnN2VK{{wcG9H zTY#b{eg{GDnTTHQ5REaWv|6p^U@&Mh#y~_!(-f+z!m=!!&u45l8;nLH*tY%dbUHl; zL4Z3%xzibAkW#|;eavPv2qBOp2^Nb5%CdaSUa#k9n)Vz7!4nZ_%Ik=69OG~};Cj8n zFbsrYh;Fxw$z*~~r-Su+4bwDh5bZUt3;;luWw0y@oOA5=dklv|0Duqzx7$qs_)$wxRTZ)pymR;BV1>g5SZnxW9 zN=Z^m;+&I|lB%jADJ2y}K}Asz=bWM_DwoUU*VSs}Jc>j_Ri5WX6h;3nk(9E^^Zfhc b@<06n&dl<{Ml4d|00000NkvXXu0mjfA|==h diff --git a/doc/src/images/callouts/10.svg b/doc/src/images/callouts/10.svg deleted file mode 100644 index 4740f587..00000000 --- a/doc/src/images/callouts/10.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/11.png b/doc/src/images/callouts/11.png deleted file mode 100644 index 821afc4fa84787cc97485b71e9f2078f45c93dca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 410 zcmV;L0cHM)P)M+td|6n+lpimUPx=_1S)c4H7YUPG|K7G}+Q zXD3BY$LW0J{_Y!?Z)RXbkxz7K`tz)v9=YBoPVL+Dl#6|9v864%XTq&y%0>7v#V81+C6pQ~&?~07*qoM6N<$ Ef)+u)Bme*a diff --git a/doc/src/images/callouts/11.svg b/doc/src/images/callouts/11.svg deleted file mode 100644 index 09a0b2cf..00000000 --- a/doc/src/images/callouts/11.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/12.png b/doc/src/images/callouts/12.png deleted file mode 100644 index 7cec72720fa9bb6f49fc4b405f7e36f20abe7fbd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 488 zcmVP)PuxtyZYjYA&U;&lvlvl%n)GViZMKE|)kS zkFYEYm&*m+ZWonG1>^A;S(d@JZ2)kiDC#rD@FH+s7fF(UQVPQ`V4DBV62~#pG)1S= z0U-poZG&^}uGi}y+Ot5@G-O!@%d((p+5?_Wr)am^s8*{00M0p1rxOP-eGy10k!2Yi z#{mFrHXDpaBeYsAl*?rR!0mQJ6h-`SIJ_4Mg>Nq_2qB=9g75nfLSQ%?Vm_ZEj$&j0IHOdd7hsai^YGRNC+YG eJpcU+1HfO$s^?_o4trMs0000 - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/13.png b/doc/src/images/callouts/13.png deleted file mode 100644 index 5b41e02a670f020ae62b7854482c4ba1980d73cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 509 zcmV4)gxr*N=Me5VesZgwj%cYwtNqcZr1 zC_xao_jajoUYEXSJjwZ;bCQPyLGYn0%a1|`74MX)s;6GB_lFQtKYCi8=bv<4|7n`0 z@g7hV#ep&QO-lLlKr}*#(rh-3ZntX?LLjBY`Fw_|s<3Sv$Kw%U7{anFbUK~R;cyr; z#_&LthfW9q=N!K8V>+Fpu4^Pog5`1vAq0XTz;3rgtJQKfO&c@DzDOxG?d^$i9AmrP z;(EQpvMk*1cl7&xn5K!vVgUf4lmdVo$MKjkh9|&vU7SuQXqpCH*I^h2Hk%D*vl$%6 z!C)`|Aq13C)OGFd_xtb4TR>41q-hGvvY;pmIOk}$+Zc^TNRk9X2mnA`*T}N02Jrg{ z5JDhLQ`okRs;V%b&yi&rvMd9o6pEstsw%{BTwgAimqw%U_2~u9Ii!^EJP)d>!f_l- zCKFIfF&qv-2zeUzJZ}fz_dl=K>zs2gIp?x0OUXHxLI_z^mAu_ - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/14.png b/doc/src/images/callouts/14.png deleted file mode 100644 index de5bdbd3eb8be01d27b6f1a345d586d0c4d61b2a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 499 zcmVt^dUO<1U`T*_)UESUECTZgDyfaHIPO@ zV~8gA-qWSZ=hE+t2hQ)D1An$&uiuqr`9UeA;f>NX?a=G>elfjW3O+&NU1ON~b(liBt_qW?^90URG z2*2x$F-R%l`#z@ADTEMUjDazRG)*y?Ot9PS&~CR~UDwA!5PT*gU4MOI9LI>F2*8=YK-YB`hJhqWuv{)N7z~gk2^_}( zV+^)!LkQvS_xo@BHNZJXmSwOk3sOqVW;0Y(g~eil%jJSR&jA2J2;_M#04$#Xr4+I( zgX1{RG!4Vy5Uo}VQ52!m>40;Ns;Usju{fPhFQ#dJd3r%g2_k~$dElI*-|wTUD&%>N z(P#wD`O~oHdB5TN{-^DBTSzHMN=ao|l9ZB^Qlyl6^vbfNFbu2JYW01y*|?7&5s@m2 p;u?nGe?ugtR7Fwzd~E(#e*x=4{y$G>PWJ!+002ovPDHLkV1hgS;QRmp diff --git a/doc/src/images/callouts/14.svg b/doc/src/images/callouts/14.svg deleted file mode 100644 index 469aa974..00000000 --- a/doc/src/images/callouts/14.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/15.png b/doc/src/images/callouts/15.png deleted file mode 100644 index 3fd6ac38603390bf6f9bbfdb85ddb203e2edc421..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 507 zcmVBYKkWd<`JW7;@NWpWE6kA22-~|X(5OQHtARz%p zgo})YY|I%?ny^`#?35$THzUn2T-SYK6o$hgE|&|GQZNhy)oRs}QuZCk`NYgpzCO|SeXLe1 zoX=5sUIS^G zA`C+qh5;hNcs#~#x5IY3#p!fHqtU?ac7yNxDhPt-d_MpA;Q}H8Go#sTBAd;k)9GL| z8UX;h-7cPGb1bv51I>iHMUVVItx*O__)|j$@AFn3E*o<#KtO&1T;` x&$C{F#LQ_FMe%aE{BMYeD2<}%$IIrw^#|YO0JIScbaVg!002ovPDHLkV1ffM - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/16.svg b/doc/src/images/callouts/16.svg deleted file mode 100644 index 01d6bf81..00000000 --- a/doc/src/images/callouts/16.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/17.svg b/doc/src/images/callouts/17.svg deleted file mode 100644 index 0a04c556..00000000 --- a/doc/src/images/callouts/17.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/18.svg b/doc/src/images/callouts/18.svg deleted file mode 100644 index 1cb891b3..00000000 --- a/doc/src/images/callouts/18.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/19.svg b/doc/src/images/callouts/19.svg deleted file mode 100644 index e6fbb179..00000000 --- a/doc/src/images/callouts/19.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/2.png b/doc/src/images/callouts/2.png deleted file mode 100644 index f7c1578846cd7e67f148e7bbe3178ec170050e48..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 446 zcmV;v0YUzWP)g%HYe&5tuzq8hs@J33d((l1w@Pmj<(Q}ki?_Jk@sMTtf zw*YCH{*qFDX6DBN;t-LjR;!hMzhBAo9NX;{Ns_?#eKea*5D@@?nUN$(_k2Fjq?9Ni zqM$P~*6TG+rxT1Zn9t`h#(;=GL=Zxt(P*I6YIPjPnMo->GPC16S8TW27>~!$T4T4{ z!CL#`3q*u^y$%4KIF4shO56>E5a@Qh0DvF}FdB{Ey6&qx6cEqzI?Vj#g@G{!tJMlb zgvn$AA;c>{@$P!P8UWwL^X787M4F};4u}67&aw<~9GlDK@>njHKiv(YD8gc~faiG# z!w}Qy6un;Wzr()o|3nZ39}b6u(pvNFcDq-WWo)gzm)4q($78nHY`%tJ*eRe6Gh3xp o8b#4xm5bzgZk1Bs?wkMQ38E9=PG^kAEC2ui07*qoM6N<$g4YPrD*ylh diff --git a/doc/src/images/callouts/2.svg b/doc/src/images/callouts/2.svg deleted file mode 100644 index 07d03395..00000000 --- a/doc/src/images/callouts/2.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/20.svg b/doc/src/images/callouts/20.svg deleted file mode 100644 index ccbfd403..00000000 --- a/doc/src/images/callouts/20.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/21.svg b/doc/src/images/callouts/21.svg deleted file mode 100644 index 93ec53fd..00000000 --- a/doc/src/images/callouts/21.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/22.svg b/doc/src/images/callouts/22.svg deleted file mode 100644 index f48c5f3f..00000000 --- a/doc/src/images/callouts/22.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/23.svg b/doc/src/images/callouts/23.svg deleted file mode 100644 index 66242129..00000000 --- a/doc/src/images/callouts/23.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/24.svg b/doc/src/images/callouts/24.svg deleted file mode 100644 index a3d55253..00000000 --- a/doc/src/images/callouts/24.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/25.svg b/doc/src/images/callouts/25.svg deleted file mode 100644 index 56614a97..00000000 --- a/doc/src/images/callouts/25.svg +++ /dev/null @@ -1,21 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/26.svg b/doc/src/images/callouts/26.svg deleted file mode 100644 index 56faeaca..00000000 --- a/doc/src/images/callouts/26.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/27.svg b/doc/src/images/callouts/27.svg deleted file mode 100644 index a75c8121..00000000 --- a/doc/src/images/callouts/27.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/28.svg b/doc/src/images/callouts/28.svg deleted file mode 100644 index 7f8cf1a3..00000000 --- a/doc/src/images/callouts/28.svg +++ /dev/null @@ -1,23 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/29.svg b/doc/src/images/callouts/29.svg deleted file mode 100644 index cb63adf1..00000000 --- a/doc/src/images/callouts/29.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/3.png b/doc/src/images/callouts/3.png deleted file mode 100644 index 3ff0a93931515bb97a045dfa61a8530d87e458fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 431 zcmV;g0Z{&lP)?w-3fw;Fb-ls zDri;RUK#8kv6dIk;e17_)v9tnpMMx*Y&>|jZU1k#+kc5jU2l$*@~7*%uccC{@JNuR z=|3UFGc%8`5{HPaVzF3gG#Ul1H5Q8nk|aSGhNx63AR+(&Gb2for`>Kh6hh!Cv95Mz z#%wl26h%- - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/30.svg b/doc/src/images/callouts/30.svg deleted file mode 100644 index dc43ba1e..00000000 --- a/doc/src/images/callouts/30.svg +++ /dev/null @@ -1,22 +0,0 @@ - - - - -]> - - - - - - - - - diff --git a/doc/src/images/callouts/4.png b/doc/src/images/callouts/4.png deleted file mode 100644 index 6aa29fc0b48c17aa6ce5540e1af5c00510c33ff7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 441 zcmV;q0Y?6bP)1BH{J6*Ukh&=Hmk zRECzB?yd`#@n#QU|E!Aozxu0ay*5o+uKTCg>-{Doo%e)N>T9`N{#mQl zDxU$a*Xx^<@&_}&`kN4wpI>%IqLW}MIG_VIWeN-2>; zoSaTXAR-uJFqup+8jWC#x%C~#L8H+?tJU&_5JM^DcV-r%7*T7D*=&aGc8h+$k5Z}h z;RGT=y2!)DNiZId zk)|oEwRfMXwMLR88o;j`!1sL&1_N9!7XU!B*}QAcvJ7z?>(lA<;(6X97K_EV-EOC> zwam=CTrN2bL%ydpO*x99EDXcv&1T~R`1b>51^@&>@S!foE^ZEjU=IL-nXOXl8b#6F j$hnL$Rw?ybGy}k2rA_2 - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/5.png b/doc/src/images/callouts/5.png deleted file mode 100644 index 36e785867ad9b06bb5da296fee61b67cd8159ded..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 423 zcmV;Y0a*TtP)s#AqNWNL+{%m!bruZt@^q`VMYNAEFDN!c`Zp`V!qpMaG}43yDw*Mu`(* zCbz2uThU&a&4u&vojYu`S~+nXKc;Ca@XrV#zFpV-WQ--*&QMDAOw)X`ZM*azAc~?d zDdh_hjWdYB7~_^@m72|FNo$S8VuAgBk7~7wPNxITIRJo&a5x+uw%hGcN{I}@Gdg1o z%jFWY*$iQ?@7|P`` z05p8xA4(~a8)&V;ImciyK)>J5O>RMIwOWISUUP#W2;jOd9LK@wbh>-YBuNm4VFKVI zH`r`8m`o-J!w}Qy6y0tYrfFV<&*w9I-%o-d7#EAh=N!;(w_)2hMxzmk2%hKVKX5DD zYPB|b1tA1H&qJ@*L!nTB5CTN>OZ#sa01P5Zl~U1qy}sL9Yn>{k-Y>%d@B>ihzNus- RRfYfn002ovPDHLkV1oUuv|0cF diff --git a/doc/src/images/callouts/5.svg b/doc/src/images/callouts/5.svg deleted file mode 100644 index ca7a9f22..00000000 --- a/doc/src/images/callouts/5.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/6.png b/doc/src/images/callouts/6.png deleted file mode 100644 index c943676beafa0562916b058c169951febcd3cddb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 431 zcmV;g0Z{&lP)2x}6wAN@OL1SlT zq-l!d@d)P}cDo(C_aGt=5rQCqQVQeoIFeFswANpkS;|ImKA(}MDdzJz27>|OIED~! zYat?pVF&fG5i@@eULRJg71rxDq9{V1 z=O32ooI_Pr4#2O6Kq&=lEvl+QS(Z>r{TII9@5r*u<$32$t61k>phVHje&-69M_ zOeT}3aFQf{9wiDPuv{*&SS-+LwIGB5Grx)b9tHr(%(b=ldN>?D{22he_qDb5=W7@M Z{sBv`yEO&CdT0Ou002ovPDHLkV1o2ux|09^ diff --git a/doc/src/images/callouts/6.svg b/doc/src/images/callouts/6.svg deleted file mode 100644 index 783a0b9d..00000000 --- a/doc/src/images/callouts/6.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/7.png b/doc/src/images/callouts/7.png deleted file mode 100644 index 20940de30d2146b73118a08905955162fe985f68..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 397 zcmV;80doF{P)^QMQBulp-}gU=C{Aa}81s!lqHiS0W-t%ynn-<=Y3{Rlv1MG?LtZkX1=)gZx{d+ rGh1U!IGfG>ygNw}Ym9k2g#q9P_H(VTcF&$q00000NkvXXu0mjfg$Ay% diff --git a/doc/src/images/callouts/7.svg b/doc/src/images/callouts/7.svg deleted file mode 100644 index 59b3714b..00000000 --- a/doc/src/images/callouts/7.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/8.png b/doc/src/images/callouts/8.png deleted file mode 100644 index d8e34d4a09f6dca4f9c22e626d9f9d82b969b02c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 434 zcmV;j0ZsmiP)2AuM{XfkN9S(EO_B7zVCVHjdQpD(18TdnnH=bV%s&@>J9`#qv4f)D~(mcd&4 zVg({X5Cj0QD2igMwT8TJhGB>}jsXCZ$prGB|9~*_BG2=u+m9^EFdmPw*=$hPHR3o1 zGrx*3Gped$06%UwxLhvqeIG=Gs;UqK0fZ0_;ihR&6a}Bp=jXv-@a4uUrH~{E(lkXF zhFGuH@I3F$uu|&R4VX@+h@uGAS_mP~@Au)HdolL^VE~ZMIcto$9*@U|aqp{bTWgH@ cejf&azhINZs#OUR!~g&Q07*qoM6N<$f@$x%rT_o{ diff --git a/doc/src/images/callouts/8.svg b/doc/src/images/callouts/8.svg deleted file mode 100644 index c1803a3c..00000000 --- a/doc/src/images/callouts/8.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - - -]> - - - - - - - - diff --git a/doc/src/images/callouts/9.png b/doc/src/images/callouts/9.png deleted file mode 100644 index abe636072b61306fbcd6157b95dfdf7e86a77e5d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 420 zcmV;V0bBlwP)J?lRHzhELZiNz|1T-iU zCV!@@1hs;1In4LXdqeB>`avo6nCH2PJ26c& - - - -]> - - - - - - - - diff --git a/doc/src/images/caution.png b/doc/src/images/caution.png deleted file mode 100644 index 5b7809ca4a9c8d778087522e5ce04b6e90099595..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1250 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM3?#3wJbQ|Pftew|C&U%V<=|it5MYpyU{F+K zFf?Rva$<;zVn|MA$j)XcE@r5%W@u>vqT-$&hMpcE*)wGd!;~q-Q>IkUnZqz=PVt;M zK*p3gbLK2v%CK~4^3tV1#?q}@8MbbX+PXD)>(;G%_cH9=n|$sZ!?|yxmE{-7;w@N47?rU=3X_NkV zU|o{PnRTZ;lXp4>+)hZU_|Lw%*va*6=<@jI@BP^`_OsZ?pZg-2AaGf|;i2L0<>du@ zeRrO4er03}pLSxdREd>pap^;~&E+}=JYKy#vHnLI=Z$}pPyA_`zG;G~<$`Br2do;7 z$Heivv0AeyJYVI({@6?X6r+V~XS2Cs!|bddDqJz@2lKf$~4dA1c%lfOT+5KMUSWi#X5(9ePxx_W1Bsf2+N)z4*}Q$iB}K{RAP diff --git a/doc/src/images/caution.svg b/doc/src/images/caution.svg deleted file mode 100644 index 4bd586a0..00000000 --- a/doc/src/images/caution.svg +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - Attenzione - - - - pulsante - - - - - Open Clip Art Library - - - - - Architetto Francesco Rollandin - - - - - Architetto Francesco Rollandin - - - - image/svg+xml - - - en - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/src/images/draft.png b/doc/src/images/draft.png deleted file mode 100644 index 0084708c9b8287c51efa6b40b8d492854191455e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17454 zcmXwh2{_c>_y1e^C}m43S&}RzTQstU#!g0*n6YJ1aTS}>RLe1z8LVo z`rtm$Vp5JW1|R$HTrs@@LGR)Z?>PPkL8l=j-77Z&G8Tsi{RV4sPaGi)BBI`)`R~Q` z*=O$N8oBahuA1ujq=ONsH^Z$;Z@?A2zPOR;+t7%GvNscPQvtyu^ z^(He{(TNfAz{D>S76#pNt`V=aFm{t&tF)Lut!iq>3RU|!!{xbB|2@69Az7({KpgFX zBHUL)|7ydZKc0k%azcGA&PuCQV*kD$bT{P;b?=`M@6C_|b6!~s9j#tuU~e9n-MCHj zfV5S(js_`kv|ivaLE*6pY!G%r11u^qOVBw|g29`m16#D?@yi>zc0bwz%G@ za2kvxn$XS7{2WQ_ju!==VTs+`V&L;sVz(Pl4+J?F&ZZv3KoKW2c?bBtGq5)oRM?*)usx_-H@47Cu#_qL+2eow%ZDy0=bsNsUP&ms8wSUp@nG86W_bQDmNMRgINC`_}NgC zCcqF_Ta|ScVvPu;|0KG{NIio~DaGYcHYq4AEiIzkxEPqs@0$Z$*)*@J$yP3ObX$%T zzRS=t%7(g3t{Q*^ zEyTxT$*5+N*(plL90Bl6`Nb^WdKn_Pvpb{prO$Iu<5}~-EnXK7fy@_2c89d+ZhJ|)%qTOcbj#K2|l1B!3n*4em>_| zs0+)H9*C!kU%yVP5l({XnQMeRu}L5Sj@SNhX<@4AzfhMZW{P&$t(3w4cF;s3a!PkRM$$6I_u>8qK3>fr(_ zv-Y*v{SjgTfq|+BcyYvbM!vF^@bCsN)N`rpJ$><_Gs5*qVfQ0@761Os;NFEBr2V@4l75H}1u*H-x1FzIyrv zX4-neRxZt~y^&-x>*hYlIJHqt-rL&^c9<9eB-5QN-kNin&S^e!8s9rIjX$~r#FHSZ zPPGHSJ7NH?>J1WXHMp6{3_m_JHFb(pJM-&G@!UzwMZ19kYDMv8^_@35=1Qp*GU^C$ znS!nuvPQ5{W^@`l=K{0vn9d5B4sd@GNsqwYt13N;s_n$M5sF(Y{Gu{$f)Pqq6>`4( zoK6ZojptUz?t{2OQ@f4d24!GwYi6y465k8gmK^#vxd{Il-lBt^R7pE@jfteJwgkQ(YBxT%22tXdci&(7P>~Iov zlAF+-uyinD*mU_C1!Z!%vFE`wQx$H0WX*IMeKiv()c!!|Br&A#iWksE5wy*|X}DYF zOkmbb)NtBhwAgAQQ)W7>BzBj)^ec8BETv8dt~1Wtd}pfRmKnoYyMymV`fvW*bjTy@ zNFqchp{S-_%)XBfUmWyYYl$xVgQtxEVn358@gKtpQuu~+-Kl-33E21oa-Fi&oBI&`1N%T=`T3uD7xjR z1Q5DaVd-rOkkqXdK@Yti1APh3TN{S1DknOaE4Vdk=o-MQ!`zf#3^vm0RTp!s>(8+I z(BKlybb>#^&dE#xTWKkB5>RG$`5m60nzI~B_{R+DtsN)(K1(tUpuVHL0)mIKnUfCR zGE=xGXN@3g`N9QSG|T0c&wxuu*Qg<*+`PlfSfJAKfkWnRsVJ$bx1$Z`o)r~6%k4&i z<9I5}9(ypb2w!#-r7*;K+DjakI~Af;0mNtDxBc4R3|&8W^=h6KIf?>|@$@)*tlfRZ zrCkhM8ZMxnVd%Q>wKHQ6h;cwwxcI6738osp@h30JoAC1Si}3tS%4m{iuKSkF9xsrA%;wLv z8A#j|uifcVGx>ptY|-u;nJ$&yw-19u5smA=3C-sC-n~XzIV= z*~{{V0<$*x$DP?_zs?b?-Dsw+U(_(rI4}YY;n`g??R&MWiSNSHJ{;g>QuE+91GpRE zd9DfqUKVfdeAUwO7il>!iH(N~Y+WTTbX3b$$01o$aei(SD8PN9Ig|tehF6`&rMrwH z6C(}UhO7r4V(nXd&uyraV5X$iUUKSF7E#U?bu;$RHwXn03D2wdZR{}kbxlVH%&8F=8tR+X zZ7kKlMpt29EK0Mnb~Bm{1y*D227__FT~$T7>%Bs>RxQrlgI55^$os$sc`ic?+hwHQ zy%C%qRZZ?xjTT>R%HJvzYPmTbNJa&lc4N}*?d^eJ+TgWWrby|-X?$RL63$ocD0=1z zq>bD(K@l*w5V0aAqv-^DtQq(*B!;KK;S)?XERW0Z8_eB7>{FG!W0Tmu$$a@l#~e@t zb7eAjZ0Z_IN~+HjldvP|xLYiL+|mn)Q;HmqDMG^&^)mW(%Xyb~AG4Jkd@~F091U{i zRg(Zi(!S357h;^+d50bWLHO{(l58O+_d192vyD-Oh|kx|qkk|71w!Jdg*R ze=X`e#>jQ1n83%L37gJmxi{uYC;jRU__qGnk430EXC8CcRU^h&pyhVlHM8x(ce}=L+^|Pv zi|35MNQw6wsl4bw0P{NiUo&-{is+V{iXV*G{_L^ONZ@`H!#JZ@}t;bpd`Z>sx8;y zHg4#YSJ*anpi2Do=jWPejhaoGWKx!&jJeOVaku|#u8?8fCKc>EQ4j zn#0h@X_`cW22kHot+mSQz%;tAI|=i92)Mglsf!Nu*>=_g&(G0d>km#k&)3TllY#^u z02UV-NFuEUi@}-x=ETTTKA`X~EX5jv8~B<}HTK+*9&OvU2dkm`_BX*1VwV7Ij{pg= zxZNaUqPlcVYHAyHFof?m;I-ZD4bN%(@@2Td(VgI3 z{*lWmv$RZ|smov=_kGDznn+>_uX{A6;y}7pk@d`(Lh6{gFvrA5pAdMmu#G*QM1tQg z2^Fb6c;#}e`;nd&oQKh@*-zW!9ICOL;OFgA2-lpdOKmA=Bp;B_eB?c_df>veT)HW_ zs^sQQf+2B6j;5$>ZG`htEUcU*ioNkd+t(slRq00x_hk@N@P79aTAmlqe^(+dfnlOAm^WQavYofR?D70kyE!Q*mr z=MN`!PH<&(t6*5^bfSkgq80c+f6zkhX=!PVf1h^9o$GPX_wJAXim3%oV$)U9uWEOS zFZ=#iF~Q2FVvon!cVc(IvVedI_~ko1I5_AWe$&m4Pfz2dCm|J!YrHng`j<_W)9N6m zB@dJSV}^c#gL?<*=59v;JS=y@jX-JNZOq4)l)5={d`D-W!H@43<=pJ8Cgd+PhIgZ0 z&1}v2D7JC5c5m#$OqX|BP;TfUn_N`fm(NOG0@Nct5f0=5t?)gK>f*TZCP8 zE~vAz*f8;aNltIEzGmjk2?*gK)Xp4zr=6}59u!nRQiIH`r`BWA&&b%MJ+5|@JL))( z@lrFw!p1WBNbZB0IBSb692ygY3^VVnsCLI=p1DJ|9{R_viTo;ObrMJc9HN|9uopn6 zRxJ;a=NLyqW+8?@vXq*8_pkle?wWh-VSoPI3KIY*(nFq-Do;;Op#DRi6cuGIH zS7vFz0{w!T_jHtX9_!if-#4x3C9rYkU+2(KU|U3m|Bg{GCEc)G`)=}$uCcQ=o5}DE z4Qf|tZ$U3T&S;B0h&i3`PkyvL2&sK4L#)80)82naNsAnG!T4hTE7tIKfou;^sdejO z2^s6dG*bi~@XEf#g^+->YY)^i=j)rM{NpB6Os``bQrQDn`1IcCuH_tZo5u_RDCH9} z{A(qdv9-0;w%911g+6sdttId7K8LSzQx$iqDz9QJ%qEV5yOmP%C1^8VJ~&}mU03FL z5oO`+?_NbVx$89Jw_-65lS!LLL^<~>akOrQ*k8YT2f4npv!ne5LrBe1G zio4QV3V(pOPhsqCE2}mF#DXWKYCS~L->zo*5E`io01;dT5!%$~no!XU5w!2{HcD?P z$hkcJN$uNC-y%aa0(KSOy?hfCDA$n{jchN?d(tgsICQ1t%qbWQv5cv{T zBj3*W2{Wy5d$(v$@2djHMZWKG0-|MBp}dhVgo z`Vtvp{;P+IYGFXmo{Vm!Z+%cSOfN(pk`H&G(lF_arZgk!S9%x!bxKv`i?_8}mLXr- zfr-&54|LC~#MV?wRQm-EFSRGh4UA`d#pe!1bE-N?4{$Ro_JUO#b#A&ZN*AR84Q}u< zvAY2P2=^9%#QQFnV=U#iNT(o73@pmXuFN9 zR?J5~@ZQvv3RK1HlYa(JZ^_%8l~?wwv#lhDjuMeJDC(xS8@gFpX*CRJe8FTVfJFLE z`L1aE-QBK9wh8Lf=pv(3olJVvrY$Ug*U6Z?{29OF(VGVhgGPXNls7&Qa&U0KV+QnI zZN%rly6U%&wr&4qxD-ujjGO;@!kTH7t&RXS%qN%jTu85~jgj|mC`qh(pxU=LV<8nb z2*g-&X|S0`7pDK6F8O&>ow7=M28`!FRi!}mwg<&m&wRfJeJ}DJr|iWg3+r~FUb+VH z+^&Un8v5io|7I+;!f+OL&4~5g{fgrz&*uKPkBlbI#PEevl|9*Y;=ZITUOO{Xx3C?Q zjzzGgf??gQ$0$6k$=bjrn_FR?Ye1m&Alpp zIR2qAum=_rBrlX|_n?Z@`qf(Z0Kxll;~uBw&`7z9Rouxf&+){$ zT5l^SU3Q)C3!P4v<8`92?@GD3FQ>)aS@lWl&S_BItaudFE*~l)`|-f4TB#FImiY-_6&9CJ9!>+TEFxeaHO)c zvYblCdx~?kBnWI3y61_CZ7mPPn2!+y?I{+aqiJZV?FagXcV{P$qIQQ}eE8YeF~}-C z?~`EwR@Cieg6$PyJheqdg_twn9zXuoot>29+0UEtNnjKl>TgTSUIvF?r06FMW=5%U zVd7m{^kQJvRLT(~FbI!5QPR|t;QS06HwuN4s*dj5LYaTRDxc}ZbrgWm^`&@BlD%v{ z@k_@S)~9!76hB8Mu>D387Pt4nO+z=`W~vOK4w3_J5I>vM30q#&d2?0jd#W0;VqxAg z{*lOi191%V8^8z#kba|g@ zf4GgGK?gk~`S@>iRci6!kr&;RW(POG$iTAEX&_W3#)}zCBeQ12R}+C0SYWFB65117 zYx=X?gFD^+O{W+m*yAfTKmH~iyJk_ORwrFE`7|!~oOPP-{gCa4!U@A4tRgdFHX_Yj zXQ(+MhO_<^GRY)^`TEi#V?93xP#4UrcMTTD68zJ5m{DboqT=!RTMbx!3!QK?HvU2k za26tqP;3Z8*MmUwL{1I(@xTcd(1T(ot# zQ8@|QB&oA%VI6gn^=!_v)SeO)d`3{ewC>T3XM2ZqXV?iJKc$ft~<<46c!aV(J1mq1tLFMB0Q_){R1qliEw)EIh?S*NbRo*>YaPx z2D-q!@M}X!8+eqQe9(&`vcyr9*&Oc9DxIi1?hcoq6i$Ah{XCaH^2(3TA1)Kpu+!qk zA@V)hERaLu1FN%*CTT?U)U3}+-q2_=P0!NO%*+f=0%Wimi9$O7C`K!{L9kB*slT?q zUcI7*#C3?0;`R1E9%YCjZ^&A%sl;VB6)!NN8!ilSF2s{jaYk8%7*iwJVYB!}O?`NH z3i_o?`Ay@F!YSHq7T_a4Hx}qC1`Ys?_byXR)+^(UW^H6<{Jzm;NPkU97r0{^fT(G3 zA;><1llKwo;%)@{#|9*KE2Dmt;(B|5Xn)(d7V2nr5OXUnA1y_!SW`EtahHzmtl7EE z%djW%*H&HXZ5G=Zciw~l@@5<9~SRg`>1sdv54 zxFT-jCM&GG@`Q{Ed)0jXg#Q(;FzY%A{D;AwhdaxE884#bo;|{{h3OhPo0zbfk;Dak z&K2NDkc8^wVPB=SuB`+^8?cY^RCi~h^*4EmEc?J58r@|g3@t=ykaw*U{ z7v;3}@P2CDd|+0TV}fa|3wl21cs|OFu95chX_S0!)zbD}eUfC(!|&!sVnQ$17U~i3 z0k=jQ+>~NKF!oc>Kff(i>j!z@pZJbZ5Qp)A$c?DsJ8AAv!O6p8|34Q%YV*_nJIhup zmQ_{jUUf_x$nzc!4cNy^2`mY?*);JNgVn<>CsVJYluh4fgd_lF1||t597+ld|`Ww&*4Hb;}rzPmefkY`>P)eSO9!dk2T9lx>3Nj5=Mz z>r&3-+b)2!U(?WAgFX*rf@W9Zs)AS~lgtt0D77}&rQM~)i0CR!i>JVNn(;mN6vgZBRDJTdsnC?L>2H3nvZSp}#S z6*9#|of{57Sm7ktIRid*9b3ZPg&%fX92~R}5M69&e`W5`q8wIvKfBufD8f~ti%ujG zOKrw=EiJwBQ@H^*Kw5USk7cR`7;^B0t+_@D3FT&XdE}c8tK%QmNSn;A8RAsMn%(|0 z_}jjAHPj3;YFouX*X_FojE7Cjxz=b5i*s)&Yd&bUzA+NKT|Zgbdbmf54f|QjdK38q zi<5!1eI+@#xyQUC|DfNCc{vl9E=gF^==yjQil0#7c-)K`hM1O%+v4rCu<4wKEeA0> zEp7n)lZbgQlME&N{V?)eCoEp(d6K!Ss;kAyp#QBJcej|g)B$R7KOOkifc9VnF zpKF%Ab3TXaX3pJr!NN3W-J#nLcKyGkvKH+HgbCYH}OT?)qCnEf9AXZkAVH3MBfRj~6fiIx9-31EklLu#&A>uM1w2k;x{p z6SI?Q5Rg<8S^)#s7ktzJn2#%93?7_*{LTCC-tM45qH{l**RpP#OJ?_o|&r9_@2w=JQ0!~pTA3FNiUVF zjRt1OxG5gVaVzD&sIKBRWsLqX)%Dkp^<7D*ZZlOm3zvdK^caRuw0>+%#d)V}r&k&S9MyDr!%#@BU!SxwyIS8y<#pz4TMM)V&d^NaNs%w$r@xK#Z3m-2Z*B z!#C;VD$dR|<3`KMGMYA6xX-+QD(`rW%C9UZWiLh9%$D1dG#BLbF0BPZF6E_5rP3E_PtxKxwhc&v~_AC^KGDil_tZ4XGnVb_$U_s<> zm8kOFv>8SO#Z#<$=3;#hN0AoE1Eo}p(7cFS7Qu%^IP-@56DRm6;s!W0R~nyzVbeB3 zPAN{zeWb;hUGr&tp1Tb%L(Z#nGF@88afdvP=TZ9_k=he-T;vK+PJ?P6ZmqD(qF2)s za2N9|Lc_5Nh35`gW$V?KI?Em}*YAvfg$3DWNG(QvSZl?m(ctUi;Jj>c8s=iGQ_8IM5DCuHH6)h}yp2H=v=D>3DC$o5 zULiAntcT_b0+|=uYSp|RU-2AMnA6H6X~WBacfvSg6(!cva9ZpD*PX&B$NOGVW7m4Z zwa-Ri?VbD4_e>?M_?{Gp5;i_LZoeQ02^su&$#yDX?_v;bcFNw!ZP<6Xv&q9brr24? z|MPgFAc|V;-ru*smLhtJwEd+tn+gNbYoIlb_Kua^3mizF_sOpaD<1}%2z%fRbie!kaalVI{ zp@PyqhIH`4Lsqp;dXPhYq~D8f_H6FmSVw-c0o;ya;C8Y>viOHkmc!hn^U?c42ZCH^ zPvXs&ZghbhD2ne4J#b17FiS1I9RZ}k{S#@9{3>3owZjjy1{zN14ROf_w3vGo{JOw_ z5LgnbR;Hy3#ZJxN6{=$yTGHlT+Ef*p(!2*(M=pwq@gO`fH0Dr=&t+`4T`zSS&3H_CR^wcr&oGobo(9^R&aR88N zpw8q{)!yFVT7gxPn;IJlWjTZ@;6^gu0o~Co*Y0Z@emdc=ZP)|VUtU{c#1q@-m_(_F zc1`xg?iSXAbKiaJX8bOLsLi6+@?>^2T?51nOC5Th3E$~E6NxFrub(x#dXlO?;HtC3wTw{sEq|t|$syXv8Tfi8aLLm->hWZycx7?T zJAi@9^p4)TX$*q+{W7YJe2KLA=_$$-H9nhPJihFrO_S8hL+vnyy}LF)%0Bq3`+#x! z9*bF7ccIkdCZ@bjMt&SE&fg93dDU%csbne!aFMjR)C1<>dSOfAuTm{~rfOo&wrBMJ zi&P9Lc>oaIV)w+sO?^X8sjG-$-RvZfqbMm$3ez1Ue{7OHR`>b6Zq=_PrYSjFxJ0op{4-*e>HCa+ltbeRL&8rk zOpJhZ9$>74+^4>aDY$y1{+F~p?}C)d=kkO*yn}m+Ajw3dOKVp@e;LX1bbqRk?i+lw z|D*uJfF@Z)tVkhWM8?V&E# zyTmdhV1UEb^kae@-je}deN9LG-8T#3h1#ojCe(gby>*zW``~(Lb6U7b%MwpdqEq(K zEAS{$i7H)RbG~^`>SjFQj+Y?^Ft_1`?au+^$%R3VO1zaZ&?NS4Ry^!zZ^1c#NF#h@ z0TD8T#jmQSaL?JG8@5uub}qy}n+?f&XZkDn47o*x8=R+CS@9|@+5Sc{deuI{#-k@8 zGwVmk8dyt-NdoEExb}uMJCH}0UCrJi0uMR>5}ISY3=oBH&_hoY1^&b)i~yE}u?si% z-PVt&T)q;ZjLX0sQ_TA3bY0+hmGSl}+yLQsMKtH(tvC4_;^TC@vXLuNNTcgL$DnOmGiLhtBsMO^AN`&cRypL?h%J zBiGYxSf4}dsU(n)My$~2GQ(fLVZL#U{ho7-j1j?+)IK2=G zzXCkvL!y~{frb8dl#NEpiJ)7iad@m8(PH3p4?x|-%d5zWr95 z{rZdqX#)sbTEuODXWBnoDA=^8YbJDSV-L>lfASXZ8D5y&t!Z16)p2XHLUQ||$XzhY z(ZNTOhU=WEWxG?AOmpj8K~s1|a(9*t@!RB$%7U*=_M=t5`sWAFyuz~O>Pcjl@Xup- zgO1W}S3KEY&FGc`(1n6n{`G2ikZF>bki9HXRA3j<&l!tlbJ90F>rt$!$g75+5bn&= zjyM80QWmZjI!*;6oH#S|oUcV47FQsDUj%8+H$#7kjT51X^Jtx)%R6|}%#Dzl{ml^0 zsv`Nn-|Bz+48SiLI79mr$g&j&34dbw@n{EdZCF)Q;Eel#;Nmcdr^kRV94rNTeQ>Vz znJP$)fOxR055Bx)K9o5)r}JEv*;cD>C^DQx@@g87^oPS)Thwn;1zXm|@zi=;a?}5h8y* z6>(bt{|;@&f#h3nUIC~HE_8P)0gPfgF)Iz@RlCu`TI%(q~$n4sNz_?{|9BnSz}B&7{#_ zK1qBPIgO|{V&NqKX{rq+Kghb{e3jx$f^oK<{_owdP6x{tVp%vtu+-oKp~{XTyKKwM zX$Z`c@2!q%PLTgNKUeKOH3e?Z#(AjRAjfx2O^o-wLC-f~kXBCsjG2SB4k!3w&_%ssqiht1fi`gwthS zZRJxsc=Hc02T0kCbeye6=v`L}H=CcUFBS95I`opHXTIPR!vcLUKAVpo{skf;5|%cj zKZYwozQ@0;jmm7Ewzi zo<*oL>r^0lz>yz>?Cy#9!RQ(wwu(u2d3jTu6aCREon8S6b$ev_gGij5MEh0OwVHeY z3JMHR>*HK->0zGG9~TkshQO@B>eP?{hJE$f;3N>uRLhJ}P~ZraSC!2Z-m?eb14#V` z%Wf}!yyU^lkZyZXi204#!G+O?Q@ceB{!4N<(Xh3BuOxshEnNU26-F#`#RIs>N}(pBW@Si2rp;jR0tbkkeB?zr zS^vJtRoNXb>y}tW?zt}O@HIPqMztv8X1Mb1o1(k)Qcp6Pr6uU+Wr|!Hv7+$?#M_2O z8ozNt-UfLk4P2gUH6A!~G!t9m9h^|<)O4k5$cNw60eE=UoqqjQ71i%yE>IF5MMw53 zoVZpnlyb}7VoR-eL}JL|uKeGZGj%Bhl-tR>S%pT0QE3%}REJ4vlQXBz;^otxhg?Ch z8XD=ERaU!$Uo=nzVP$E_ymK_%iP6+MG{s;{Y7rF$-fQvmr}-!7R+5kFfp=OE?phks zAIRMnzl_f-n|fdFUx?=;*-?y8#j=PGKPpOOOfX}Ic6w;#a)+T)JYU|+Xv2w$zY|)U zEeeU^HM+hO--oSU>4i-+iF%MO_+IX?wo`R@!WLpS_grU1%73579~%ph(hCzw#gqKS z33(@oiGv3~@~gXqf5#i|_#YMm|B*Feu_oGLserI4H_P&w_AZb(3Isb~x3Ld2CgpT^#omehU$@8! zZ37~|Sa6Xc;y@q!+6z@#hh!4ucXrj8>Qxso@J<)u1I)@I5I^A46Xis^4@P!i0{?O+ zk)CZ~poU|sFD2L)#iE|&ssJ3xPipy!K=bolV9l|2Z(i}*43Z1Wl>m~3P4rKR z;{jYf=VLJmi^x2<{AMKuKw`P)#B;8nQBOIhHy->XNo^z$xthq*cY@X>W!5<4<@4FX zNAk9jj2q$VscrAdjGHmRtbN?guU-Ze<)BHW%*jo5k{5v?@U7yU_yhoD$uz_q-~545jZuxv;JUQ*eFqk?xfP@lh~jP(N?2I0NIZ-q zDGD#GS$Z5%#81&o5Ufv=)9xJ28~UMS`u^V4={bp#DxfwlU7@e?)*KGps|+y(T@tnr z9A#fLvb5wqpXG&eyWHhX@kN1}iO>(98#j(F*qUrT%3$LWY&VnO9gyxolrhty?u8%M zar#N)92>LMOfsB>_D%XweB1a5z8o_t7nV53zGhsGH=Ml{GE->_3^aZ?i1k+KH{Bi* zY{{urjeCUUx{4awMMqbyudOM4lcFe}f0kQxel&TCX;q8#ItaBSss?l>cfYcppL667 zS>TiWKH{ZWLw~L%seSo-t#ZVhl2DGsZb6V3qms|C<$Uq?0!WD znTe>ujm8kZr!xr(ULadh!(KEI*eP2e8ztmktEMSwD&hN43ddd7xbRW-tc40~ z19$nWlggKs>s;Od2Iq;+HaSzqE~nHmhvFSvxIn|naZo8v~4WofUl z>!4oJlcv$-(Hu&G#ZJ_w5Z)n~Rwk6YVkfc4?7^k&H4vyEOMEwEPa;GC(@sG9UK0l< zym3g}=fXdvShWk}JWOfm_hXjhW6NC8L44=y9MCIOFwlD^9541durm zIjxI`e%J5;RSEZ-PK64!Z$8JYxg)OYus$7X)=3YXtpuw8`FEZoHX-T27L3^3mCkP{ z&5K05BG=29L~TDoxs)Ze8YnCtB6r6s5%IM>J{E>lKnexjk zF8wpQnq>*y(C;*VyBSQLL0w@L?tQ?-PuO>uDOcCX?6xMc;$ZyH<_&W`uj1gXTP$N^ zG4Xa31VfrYj;M^;f(-Tw`<_7wa3DmU;dQiQf z7NxutM)uz=k#Ko!M0*iv^qY@@ibmclp2|7Ykd5wdL5{;9N3m~n4g=tUwe;P zI25w!A{9r;$eMW>q{hpo19Bk1pe=P>6r$o%=>7_cjN&Tm5M|IJuUvH+AK${CJX4oU zgO6^=eBKAuGz|tm+nSrK8|c$@b06AJVIe41Kb6p*)`8SjV>XRLlD=n zxmF_SZPNO?HOkAGmreqZP`zhDat0zvL6TUJs#jj+mv!eE2D(4H^wQ8v?J{{F_uNf{ z3Guwlmr_Y+?1xwv+DlCV!Qxf3`85lI9<3MYLPv#eKnDUu^wHQ zc>gm5549XSAWHZ;ccVn65dF5Y_!SFO%Z|}Q(6SZUI=Dtc;z5Ty%nrLYb#L*-Yh(x- zSIj@A+IWZB(0~zQg=&PNK%${P5hZ>29oZHuVGWHXY$x1YFsQbXHgN={wk@*qqJ+Nq zd)egXY~a_ZOiJe;TU+HKlsyJTMfblt8%od5*(H)*Q$D;z+^%AQ4mXPuX2k}%-4;79 zmQ1FAba2Ra`Bcxdj1l&?kFD%K^S3JRgKXK4^qjwecz_P2uJ-l zC)Qvqm+~M!v43_gwKDlR1nJf$++0o6yE@XCdZL3q)UgB#ypJ#vJ8S*1wxK1+=6B}+ zXR*cqf>giPZZtBQvI{Zak5z&s<%W6@C}Kc7|Jd$GBC>hYST1Qs6_hTGb>DuR924B0 zN83(4+CxS$>H&|*-r;Fo4NfL83)iN!YZ&TeJH98$Hv6Ebv4bJ|{_ja0c;iH3BS>3^ zpqgshmx8R31o2gdvH`OqjyW=UU6imxAx*C0^Zy99KL{oAvkpUJI(*CnkaZUKS|miv7yJG9ATWhm{X zmhwPou-YzMm|1!Q!U)jjx%z~gla=8UD)w?G&Zaq~DL{YDwlSN`Dnf>gnqOEH6`e=5 zK`qGvB4v}6phVXVBt;`Goq9`6$1(ekF#8@rQR!O?lVvgou3PA{Mrgg$a_qp=fEaM+ zd)RS3^IyJ;lNL~f*%#*d`QhDdtk^TrNIS|sGACrecpC80;-?Fs23-ZoFWU}~?O7@t zRJMKubhf|4AK65+^Yw8fyef3O1aA8v$s3mu7PHe^U+V4qu@K`r&lUl#^MSr$PX__o zkc4H6xZrmj{B9ymd8uZ1l@104i9rzScjn&(C@ri42@jd|ET?03nMCrOz62_&EiK<& zSBCb#CxX4Kax$9yU;Qik2A;XS4l0o}3esA}H7YGS`LFZ+Cp-+Ao3iV`;Y2#t+RBw4 zx0Nc0Q9y%mXU8X3P%JXaJSA=%)~{Chg+d_{`+@cih8jx$RRzetz1P5XI7rt8+K9*g zkSIZ8rn1WK#9AdD3qWOXE$*F3Ot={(vVp^%iu~vZN~NYgy8_O?l!!1aW}T^|BNP&6 z0?qjrcZN zmjmPbA_FH7lrCAL1d^70)DpX)@;aCfO87MXaxB1q=%jAw{{D`eJ!d-BNT7BMlMWP}{ZZ&o`DY!}ep;HhTV*iZR2Rod;vAPt=MM&iugW*ReqJUt5Qt_q8>ioMMBX>R9!hDFUD-8$eYs z1-TtSGqXUHgLC2i8u*t{Y|w|+jMebIyJ4s^A?cD}pz_yAd)%*nkt{$;7Zl-taBgGY z3@mR5iYU7aF`|s8$6+Otgv24;=D;){kh=%;5zgNp{HcTraHisq6ZRfb zGW_De>QlN^)>%P;wg-4IfgjGe)9@8oA5f2u;i&iuD70ZYZG>GVyG?KsVh7^@q^+_&<9k|1f{n8Ys}&4 zar=)5U>;^OAAH~;qzbCyEiJ*~gbv|vsZP*7fI2Zi@i+OI%Qu*&(tT@erO6Mb(Z$59 zguP#oe4eqid_2;#q}qW|`vO7O$`jJe$IvZwKK6c?Xzh#3XO?(!b^2k4;!# zYGW=JqVe>I?z~`PT4Q2xwFFNu6ey9UCv31nPenw9f8bRc#Vg5bJF+YgK;aIo$ualP wqI_@;Bx5sQADwv9=?)5}0VhV#cC~Kt`tEf9DgFWeNC#x3htMsB-+J`_0Fi|iga7~l diff --git a/doc/src/images/home.png b/doc/src/images/home.png deleted file mode 100644 index 5584aacb097a80e66a5320312b6e4eb017af1a06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 358 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7T3?v)swEqJs=3*z$5DpHG+YkL80J$mwJ|V8+ zB7)tW9nKDRM~@s%h>KBER+u?+=H<(mwr$-K=fo0^iDsNj}a zlv - - - - - - - -]> - - - - - - - - - - - - - - diff --git a/doc/src/images/important.png b/doc/src/images/important.png deleted file mode 100644 index 12c90f607a1b27ddde0a7d922ae255e8c90e883e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 722 zcmV;@0xkWCP)Gdz_qOoSb{LwMwNgp7=gl$4aErG%}mjHRWNrKOy`y@b8JoTa6ut*xc4t*y1SwY|N)#>U3Z&d%1> z*52OU=jZ3|@9+2b_y7O@tTMkk%M`~Kg@u8&dg_P^_0l3yQb639!jLZt^Lx<-O17UeeJ z-|=!77W(jGx&e#?FOku-gKofoU0$~4M+dhLFueEauP`}l7LV=;lsOdn%WHure=x;k`m0(bF&MU#) z-qv#^n8(MjB|ykioqII#+`g4no-MU=BK|Sahu_3M_-d*=7hq=~t?^}A)G7 zbairN0An*{V`DL9V>K}|HDobmIW;*pIW=W9HaTQ6F*7kTGI9=S@Bjb+07*qoM6N<$ Ef=i}M4FCWD diff --git a/doc/src/images/important.svg b/doc/src/images/important.svg deleted file mode 100644 index dd84f3fe..00000000 --- a/doc/src/images/important.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - -]> - - - - - - - - - - - - - - - diff --git a/doc/src/images/next.png b/doc/src/images/next.png deleted file mode 100644 index 59800b4e87f60c0e3383ede2b384b9be0f5ffe8d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 336 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7T3?v)swEqJs=3*z$5DpHG+YkL80J$mwJ|V8+ zB7)tW9mdAS+qP~A^!HU$R#>ro>7z#vFJHct5EtX@VE6z3e?1}lM4)<}k|4ieAQuK0 zgzld^2NdTl@Q5sCVBi)4Va7{$>;3=*RZCnWN`mv#O3D+9QW<;`lZ*0mQ&Tb%72Gn5 zQp@v;vWpdbBNU7b3{2X~)|>}w5Cds&E=o--$;{7F2+7P%WiT|*H!#*WFgd=yhZCqG z!qdeuq+(9;4PKV1Hyx6gnJ3)X*T8%1&d~!CcvGht8EkNzY0cztDB;<=un7h&oMQJ5 zOnAh^!sYOgmxqZbU_wKJkwW(@g)2%k8?y8!<$B~f6iH61Ubv5eVdat_!+^S!9H1Qx Mp00i_>zopr0Jz|Gn*aa+ diff --git a/doc/src/images/next.svg b/doc/src/images/next.svg deleted file mode 100644 index 75fa83ed..00000000 --- a/doc/src/images/next.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -]> - - - - - - - - - - - diff --git a/doc/src/images/next_disabled.png b/doc/src/images/next_disabled.png deleted file mode 100644 index 10a8c59d7b3741260b7bfe918b62d0670cad8433..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1110 zcmY+@U1(Ba7zgmjDRvTtQ&L$$oM7uF2)$_$L2619oS2=UZrYjBy6mRGh`_UtKA{mr z&7hmQ>n7-KH(k`l3W_tgna$01TCHhYnyqEo%+oU}@c)DNeRv<Aw4@Ln z93k3vZsg(J43U|lVL3RF9xoOO*=)8_spRvsnW@QgsZ^`gs@1Bl&*gH{hGA%$HjdJ0 z0!^YRltHf%-=x_aG>vj-2F;>8dW+_ej^3ep^d5ac3+N+SL}4$&L!O*Z;pbcwggWI6Ht znSIeG^MqH2daRdq_j=NKWUEDx?&yZ{K(t0hNp-olr%gM()V(P|g0v^Rdp~d9J+QaF z!E^J*7D+vMK=CJy#-QLKKFMEfm#>;6HRZnKq86dtH6)t7^tAr+x)|r>qo?RMm@+$*>08dLHng9R* diff --git a/doc/src/images/note.png b/doc/src/images/note.png deleted file mode 100644 index d0c3c645ab9af6318035b026dd86944b9ddc9114..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 490 zcmeAS@N?(olHy`uVBq!ia0vp^5+KY0Bp8m$B&h%?rX+877Y2q^y~;)m42&$EE{-7; zw^Ao5PC9JB<666~wbh%Oo7tJ0_rGWfi({a(qjR96>_P4H$tJl=Pxd^1p6`8M?=jE( z!hchf6<8Mi`NHe6`iia69>!lxe4C2-S>+Wvj;l63k!MNSb9|1+f-i>irDi|a^uLl% z^#-f2#pQ2lC%m~9m9JWJZL3|T8FRX>A78<>cU{Z6XGFG336=OLGkw25|29|RG_k%U z>j|M}Ih2i#-w+9_ - - - - - - - - - - - -]> - - - - - - - - - - - - - - - - - - - diff --git a/doc/src/images/prev.png b/doc/src/images/prev.png deleted file mode 100644 index d88a40f923e3c554125f01cd366707c60cfcad04..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 334 zcmeAS@N?(olHy`uVBq!ia0vp^!XV7T3?v)swEqJs=3*z$5DpHG+YkL80J$mwJ|V8+ zB7$jYX~xFJ+qQ05v3zNuzpt9I!sW}Cx;s0Z9qba~V*daCKl2PvGf+KGNswPKkP8D0 zLif*|1B!DNctjR6FmMZjFyp1Wb$@_@swJ)wCBgY=CFO}lsSLh}$wm3OsVSL>3T~N2 zspa`a*~JRJ5eh~I1}5!gYt92Th=DXX7o{eaWaj57gkwm>gfq&(JZLf6ZeXy%aV8%R&r1O{j}20XTDX{IIykaj z4Nx#hVBm6cU}k1+>Qw1kB6gA`rFdeFa~bob(-ZFQzAc!;#K4>y+$E64`2%PJgQu&X J%Q~loCIAR&aHIeL diff --git a/doc/src/images/prev.svg b/doc/src/images/prev.svg deleted file mode 100644 index 6d88ffdd..00000000 --- a/doc/src/images/prev.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -]> - - - - - - - - - - - diff --git a/doc/src/images/prev_disabled.png b/doc/src/images/prev_disabled.png deleted file mode 100644 index ab3c17e02d156e7494dbab2f9cd66af46af2358c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1109 zcmY+@QAkr^6bJBgcW-U!1{X&)qK7M_5M*o=8THWJ+-L(GYZ=trG_;qf9*iP{hOHkvdvc6%2vA_iD3U9-0yJDcRs#*KhAd};6H4s z+g3+J7N6H0vA^EQ+H!#9vbD6`Ds$w15^-3cW^4D2@1tYP~^k(L0ny@6iX8LwWQOEu&AU zfQo1ZeMa02wZ5RQ=o?x^-x0S~tsm$oT0_531^q^UP!(}k|Km7w>=EA^b6?PZ^nZ>c zHKa9-^N)RQXXnMy?rd*3eEalZV2h}d<7uSYUol!mlhPcO#b+0y%6jsu%~o|iC&Tqk zjZ&+ugrhej$H%%!n2hY4Bw5`RXuNjl<&!a&&LzU`dgFGUS~a!}3S4TRbC4w09~9k9 z);;a{R+T2~>V^|?*&xZWmO@B-pr0ES45n;vpEFE`ily1KnYZ`aRH^GBuiSf29T*)S kmrP2ur(nL^B6b$eQ zaTOO4T)k@LniZub1%Y8f*1x{4x_4{3i<3oNO~t)?cMWybC-tSAKHfEHLVsF{-%ks|7 zjDPxIwu_^_r<>iTb(LLhafxxBUq39{v3=XjnKLh+@6Sy0Xlrc@39wrE41I-`%@*_H`vT)Rk40g{7sX z`FNVTJ6okB1!txP#zY2wc(d5s)2XE)>ihSl4mQR?K~7U9WB`>-?C(j83rmc1F39y? zzq)+;=Gy(c8ka3y($mw@(UR0yUs+Qb`ct-`85ma4B|(0{|49c7L~4o1Q3?TC!&%@F zSTaI#9`SV_9+c( zW;eO@wl|k#YcHt%5b*DNxDw|SUx{9YOXh`gE=j?bXD{#?S~XQQJ?8HZ6@8!dXRi6f zFs(-mE_w-be$Bq$tZlXB;`6;hFXYS9RpKXpuq=q{RQb~W-D%-&g`@1Dljl5NzBeuH zd3B|Jc-c9=PwD+{`aRe5YtcxAH&Vh)Vt}-<~+7jfdx*(to}? W^F^#dfhRDm89ZJ6T-G@yGywo=2(Kal diff --git a/doc/src/images/tip.png b/doc/src/images/tip.png deleted file mode 100644 index 5c4aab3bb3543191c360387c4af9a3cbaa051345..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 449 zcmeAS@N?(olHy`uVBq!ia0vp^l0YoM0VEi-?r};1DW)WEcNYeRRlUkaK;CUn7srr_ zTcwkB3m#VBagbEhuIO1a$!w|j^feEHv@=+|woj32oF*6|l<3XH$!T}Lao)e6jJhoQ z_vr?OZVprC|7iZ8xaicUR0b&zR-JdP408=+?zC0Rn8IN&QLTWhMIcU0X8P7uUN4WB zR_?a_;&p>ll{>(OzfJ4N{OX={Q&zNgO}j31DC;|ya^r9Fjd348&p+!^cT+^sws+=& zCu*T*mRNK3PE;$BNx$Fa_9(Y=&DoXLMFRd#U31O)<`W^F&-o=xbIqK-c?mr!bmn>! zky6TW;ML~4nXw$T{yra=OteL6G!=B;0=?;6;u=vBoS#-wo>-L1;Gm(b>6x3Dp6Z*J zo|&AjV4`QFXQ5zesc&GRZ(yj9T$EW{Qt6OeSzMBtte0A>mr`1gpI4%noS!>!m*Ngk zP=bxiOwUU!DFvFBnrfM1VQy}0X_lO7WM-b2nq**TZkb|inr2~`WR#dJWc*7VsEZGz hD*$LMgOO>4k%_i}w!yxSoa=!y44$rjF6*2UngF(YpwIvS diff --git a/doc/src/images/tip.svg b/doc/src/images/tip.svg deleted file mode 100644 index cd437a5e..00000000 --- a/doc/src/images/tip.svg +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - lamp - - - - office - - lamp - - - - - Open Clip Art Library - - - - - Sergio Luiz Araujo Silva - - - - - Public Domain - - - set 2005 - image/svg+xml - - - en - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/doc/src/images/toc-blank.png b/doc/src/images/toc-blank.png deleted file mode 100644 index 6ffad17a0c7a78deaae58716e8071cc40cb0b8e0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 318 zcmeAS@N?(olHy`uVBq!ia0vp^{6Ngf!VDzk7iOmbDT4r?5LY1G0LBeqssYGrXgF}- zKtn^rf1vn(hW}s+NCR0w;4iG^2^42c@^*J&=wOxg0CMC!T^vIyZYBTtzyH6zKuy9A zentg0F+qV0g#~P97#OBpaJrNsxA6f`rE`gEL`iUdT1k0gQ7VIjhO(w-Zen_>Z(@38 za<+nro{^q~f~BRtfrY+-p+a&|W^qZSLvCepNoKNMYO!8QX+eHoiC%Jk?!;Y+JAlS% zfsM;d&r2*R1)7&;o@#7ik&>8{Vv?F>U|?x(ZfKHZYGz`bmXczeoR*Z-Hs=yh7cWRx f0MJ?nL(>XNZ3Ars^Rf>h;}|?${an^LB{Ts5OHX0g diff --git a/doc/src/images/toc-minus.png b/doc/src/images/toc-minus.png deleted file mode 100644 index abbb020c8e2d6705ebc2f0fc17deed30f2977a46..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^{6Ngf0VEhsJkjh1QcOwS?k)@rt9q4-G!sMP)HD-wQzH`-1CumMgJctv6pLi@6hos# qqtv?{|7HPo@q%;(0Ig*(G_A1IHqbUOFZ%#8j=|H_&t;ucLK6V~f=xvL diff --git a/doc/src/images/toc-plus.png b/doc/src/images/toc-plus.png deleted file mode 100644 index 941312ce0dab168e0efcc5b572e387259880e541..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^{6Ngf0VEhsJkjh1QcOwS?k)@rt9q49T#T`K7w7|w?rspM=lmg95OfodLFfd9rOi4*hH8wIdOfpPPHA_l1 vPBO4aOiebg{S^Z=hXV#3jn*#4_ x=vj5p^wF)?xpx*Du6ddKc=uuXxWffq{6A*KyDFWJxdXJF!PC{xWt~$(69DY=mmvTE diff --git a/doc/src/images/up.svg b/doc/src/images/up.svg deleted file mode 100644 index d31aa9c8..00000000 --- a/doc/src/images/up.svg +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -]> - - - - - - - - - - - diff --git a/doc/src/images/up_disabled.png b/doc/src/images/up_disabled.png deleted file mode 100644 index e22bc8712192df3a8faa3264b0ec71ff3aaaa96c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1115 zcmY+@Z)^*37zgl2dzmw~oK$GMafp#cWXs;jyt!6uYtl7UeZec8`SV6X{7De9Dw2(4 zm>26}32(gcW*OddFPdfV_NT?wYHgXdTAfl#H+r5D$$dY`-IIHMf0Ezb_xin_j)wY; z^+eR*>U8+HT56YQ=DTxXyvjv5Ve7IHJsG&Xy#F3Q%RQaGE}~1@h=SLMDmvFJ(fJml zT!5&3h-ky9p~u59A~Sj2e&_VmWGa=4$F*XyxL7D;GnsO^oJh>ZqBHq?zEmnDlXI0y zMc4I7gDEtPW>6Hx&`b0Ry+#^}qc><4CD2?%a47s&%&rYXwnm@^2oK6>2RiC(}ybQxc@;;j!lN7xJKGXK5u*58HCq zi)yn~zbYIeQ(ynxTdSHPs@k~jXquO=uiH1eY2@@XO+VY(#*4k%x7x*t?&AUCt?S$* rDO!X~;(e<^-4?Sb9}HJ}I(CrQLYik+oARjr0iT6jPLE^M9tiybIrJyp diff --git a/doc/src/images/warning.png b/doc/src/images/warning.png deleted file mode 100644 index 1c33db8f34a8b42b373179b46a2d8d8a10e061a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1241 zcmeHH+e?!H6#vDtmgHCxG{Q}12(7`~)|MMe^RnTlY0JD#q1sIwW1DTCqzzwWg@Q=t zBC2Iceu@w4LHM97Gb5%*E%9MN*%m}jvs!{N@Pd8$H}vS?TsRzlzr#5kPPe|YG%fXL zDu6VdR$WC$&Oc)^X#ZjK-7LU>{!F!o39xr+d_Vw5fMTEwpb-s#9q<5Nzz6gIepyU?Lctpr{ZK zVzWaWPAC)#17S8h%;AIuf(Q_yeIybEqS0s^i1YdJcsv0ln9M{Xkpz;-I_^=P))~D~!!Hvpq{Dl8O{rN@cECkt>#DncX%I(O&3i_YgL-$m$VU zT3cLBLS%M1`o{TBX}S|Tbhc)vk!Yp)%rdDd&my(RPsxl%lU$)tC?(1~WuEwClUQn! n$Q8O{Mxt@ukkcT{K0> diff --git a/doc/src/images/warning.svg b/doc/src/images/warning.svg deleted file mode 100644 index fc8d7484..00000000 --- a/doc/src/images/warning.svg +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - -]> - - - - - - - - - - - - - diff --git a/doc/src/minimal.css b/doc/src/minimal.css deleted file mode 100644 index 401b73e5..00000000 --- a/doc/src/minimal.css +++ /dev/null @@ -1,22 +0,0 @@ -/* - - © Copyright Beman Dawes, 2007 - - Distributed under the Boost Software License, Version 1.0. - See www.boost.org/LICENSE_1_0.txt - -*/ - -/******************************************************************************* - Body -*******************************************************************************/ - -body { font-family: sans-serif; margin: 1em; } - -/******************************************************************************* - Table -*******************************************************************************/ - -table { margin: 0.5em; } - -/*** end ***/ \ No newline at end of file diff --git a/doc/src/reference.css b/doc/src/reference.css deleted file mode 100644 index 6826962a..00000000 --- a/doc/src/reference.css +++ /dev/null @@ -1,11 +0,0 @@ -/*============================================================================ - Copyright 2003-2004 Douglas Gregor - Distributed under the Boost Software License, Version 1.0. (See accompany- - ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -============================================================================*/ - -PRE.synopsis { - background-color: #e0ffff; - border: thin solid blue; - padding: 1em -} \ No newline at end of file diff --git a/doc/tutorial.qbk b/doc/tutorial.qbk deleted file mode 100644 index f6ac702b..00000000 --- a/doc/tutorial.qbk +++ /dev/null @@ -1,848 +0,0 @@ - -[/ Copyright (C) 2008-2017 Lorenzo Caminiti] -[/ Distributed under the Boost Software License, Version 1.0 (see accompanying] -[/ file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).] -[/ See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html] - -[section Tutorial] - -This section is a guide to basic usages of this library. - -[section Non-Member Functions] - -Contracts for non-member functions are programmed using [funcref boost::contract::function]. -For example (see [@../../example/features/non_member.cpp =non_member.cpp=]): - -[import ../example/features/non_member.cpp] -[non_member] - -All necessary header files of this library are included by `#include `. -Alternatively, programmers can selectively include only the header files they actually need among =boost/contract/*.hpp= (see __Getting_Started__). - -It is possible to specify preconditions, postconditions, and exception guarantees for non-member functions (see __Preconditions__, __Postconditions__, and __Exception_Guarantees__). - -The [funcref boost::contract::function] function returns an RAII object that must always be assigned to a local variable of type [classref boost::contract::check] (otherwise this library will generate a run-time error, see [macroref BOOST_CONTRACT_ON_MISSING_CHECK_DECL]). -[footnote -The name of this local variable is arbitrary, but `c` is often used in this documentation. -] -Furthermore, C++11 `auto` declarations cannot be used here and the [classref boost::contract::check] type must be explicitly specified (otherwise this library will generate a compile-time error). -The function body is programmed right after the declaration of the RAII object. - -[note -In some cases, it might be necessary to program some code before the contract. -For example for acquiring resources that will be used while checking the contract like old values, but also to lock mutexes (or other synchronization mechanisms) in multi-threaded programs. -] - -At construction, the [classref boost::contract::check] RAII object for non-member functions does the following (enclosing function entry): - -# Check preconditions, by calling the nullary functor [^['r]]`()` passed to `.precondition(`[^['r]]`)`. - -At destruction instead (enclosing function exit): - -# If the function body did not throw an exception: - # Check postconditions, by calling the nullary functor [^['s]]`()` passed to `.postcondition(`[^['s]]`)`. -# Else: - # Check exception guarantees, by calling the nullary functor [^['e]]`()` passed to `.except(`[^['e]]`)`. - -This ensures that non-member function contracts are correctly checked at run-time (see __Function_Calls__). -(Also note that functions will correctly check their contracts even when they are called via function pointers, function objects, etc.) - -[note -A non-member function can avoid calling [funcref boost::contract::function] for efficiency but only when it has no preconditions, no postconditions, and no exception guarantees. -] - -[endsect] - -[section Preconditions] - -When preconditions are specified, they are programmed using a functor [^['r]] passed to `.precondition(`[^['r]]`)` that can be called with no parameters as [^['r]]`()`. -Contracts that do not have preconditions simply do not call `.precondition(...)`. -Preconditions must appear before postconditions and exception guarantees when these are all present (see __Postconditions__ and __Exception_Guarantees__). - -C++11 lambda functions are convenient to program preconditions, but any other nullary functor can be used (see __No_Lambda_Functions__). -[footnote -Lambda functions with no parameters can be programmed in C++11 as `[...] () { ... }` but also equivalently as `[...] { ... }`. -This second from is often used in this documentation omitting the empty parameter list `()` for brevity. -] -For example, for [funcref boost::contract::function] (same for public functions, but destructors do not have preconditions and constructors use [classref boost::contract::constructor_precondition] instead, see __Destructors__ and __Constructors__): - - boost::contract::check c = boost::contract::function() // Same for all other contracts. - .precondition([&] { // Capture by reference or value... - BOOST_CONTRACT_ASSERT(...); // ...but should not modify captures. - ... - }) - ... - ; - -The precondition functor should capture all the variables that it needs to assert the preconditions. -These variables can be captured by value when the overhead of copying such variables is acceptable. -[footnote -In this documentation preconditions often capture variables by reference to avoid extra copies. -] -In any case, precondition assertions should not modify the value of the captured variables, even when those are captured by reference (see __Constant_Correctness__). - -Any code can be programmed in the precondition functor, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex preconditions that might be buggy and also slow to check at run-time). -It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program precondition assertions because this enables the library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__): - - BOOST_CONTRACT_ASSERT(``/boolean-condition/``) - // Or, if boolean-condition contains commas `,` not already within parenthesis `()`... - BOOST_CONTRACT_ASSERT((``/boolean-condition/``)) // ...use extra parenthesis. - -This library will automatically call the failure handler [funcref boost::contract::precondition_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are `false` and, more in general, if calling the functor specified to `.precondition(...)` throws any exception. -By default, this failure handler prints an error message to `std::cerr` and terminates the program calling `std::terminate` (see __Throw_on_Failure__ to change the failure handler to throw exceptions, exit the program with an error code, etc.). - -[note -Contracts are most useful when their assertions only use public members that are accessible to the caller so the caller can properly check and use the contract. -In particular, preconditions of a public function or constructor that use non-public members are essentially incorrect because they cannot be fully checked by the caller (in fact, Eiffel generates a compile-time error in this case). -However, this library does not enforce such a constraint and it leaves it up to programmers to only use public members when programming contracts, and especially when asserting preconditions (see __Specification_vs_Implementation__). -] - -[endsect] - -[section Postconditions] - -When postconditions are specified, they are programmed using a functor [^['s]] passed to `.postcondition(`[^['s]]`)` that can be called with no parameters as [^['s]]`()`. -Contracts that do not have postconditions simply do not call `.postcondition(...)`. -Postconditions must appear after preconditions but before exception guarantees when these are all present (see __Preconditions__ and __Exception_Guarantees__). - -C++11 lambda functions are convenient to program postconditions, but any other nullary functor can be used (see __No_Lambda_Functions__). -For example, for [funcref boost::contract::function] (but same for all other contracts): - - boost::contract::check c = boost::contract::function() // Same for all other contracts. - ... - .postcondition([&] { // Capture by reference... - BOOST_CONTRACT_ASSERT(...); // ...but should not modify captures. - ... - }) - ... - ; - -The postcondition functor should capture all variables that it needs to assert the postconditions. -In general, these variables should be captured by reference and not by value (because postconditions need to access the value that these variables will have at function exit, and not the value these variables had when the postcondition functor was first constructed). -Postconditions can also capture return and old values (see __Return_Value__ and __Old_Values__). -In any case, postcondition assertions should not modify the value of the captured variables (see __Constant_Correctness__). - -Any code can be programmed in the postcondition functor, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex postconditions that might be buggy and slow to check at run-time). -It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program postcondition assertions because this enables the library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__): - - BOOST_CONTRACT_ASSERT(``/boolean-condition/``) - // Or, if boolean-condition has commas `,` not already within parenthesis `()`... - BOOST_CONTRACT_ASSERT((``/boolean-condition/``)) // ...use extra parenthesis. - -This library will automatically call the failure handler [funcref boost::contract::postcondition_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are `false` and, more in general, if calling the functor specified via `.postcondition(...)` throws any exception. -By default, this failure handler prints an error message to `std::cerr` and terminates the program calling `std::terminate` (see __Throw_on_Failure__ to change the failure handler to throw exceptions, exit the program with an error code, etc.). - -For non-void virtual public functions and public function overrides, the functor [^['s]] passed to `.postcondition(`[^['s]]`)` is not a nullary functor, instead it is a unary functor taking a variable holding the return value as its one parameter [^['s]]`(`[^['result]]`)` (this is to properly support subcontracting, see __Virtual_Public_Functions__ and __Public_Function_Overrides__). - -[endsect] - -[section Return Value] - -In non-void functions, postconditions can access the function return value to program assertions. -In this case, programmers are responsible to declare a local variable before the contract and to assign it to the return value at function exit (when the function does not throw an exception). -[footnote -The name of the local variable that holds the return value is arbitrary, but `result` is often used in this documentation. -] -For example, for [funcref boost::contract::function] (but same for all other contracts): - - ``/return-type/`` result; // Must be assigned to return value. - boost::contract::check c = boost::contract::function() // Same for all other contracts. - ... - .postcondition([&] { // Also capture `result` reference... - BOOST_CONTRACT_ASSERT(result ...); // ...but should not modify captures. - ... - }) - ... - ; - -At any point where the enclosing function returns, programmers are responsible to assign the result variable to the expression being returned. -This can be easily done by making sure that /all/ `return` statements in the function are of the form: - - return result = ``/expression/``; // Assign `result` at each return. - -The functor used to program postconditions should capture the result variable by reference and not by value (because postconditions must access the value the result variable will have at function exit, and not the value the result variable had when the postcondition functor was first constructed). -The return value should never be used in preconditions, old value copies, or exception guarantees (because the return value is not yet correctly evaluated and set when preconditions are checked, old values are copied, or if the function throws an exception). -In any case, programmers should not modify the result variable in the contract assertions (see __Constant_Correctness__). - -It is also possible to declared the result variable using `boost::optional` when the function return type does not have a default constructor, or if the default constructor is too expensive or undesirable to execute when declaring the result variable (see __Optional_Return_Value__). - -Non-void virtual public functions and public function overrides must always declare and use a result variable even when postconditions do not directly use the function return value (this is to properly support subcontracting, see __Virtual_Public_Functions__ and __Public_Function_Overrides__). - -[endsect] - -[section Old Values] - -When old values are used in postconditions or in exception guarantees, programmes are responsible to declare local variables before the contract and to assign them to related old value expressions using [macroref BOOST_CONTRACT_OLDOF]. -[footnote -The name of a local variable that holds an old value is arbitrary, but [^old_['variable-name]] is often used in this documentation. -] -For example, for [funcref boost::contract::function] (but same for all other contracts): - - boost::contract::old_ptr<``/type/``> old_``/name/`` = BOOST_CONTRACT_OLDOF(``/expression/``); - boost::contract::check c = boost::contract::function() // Same for all other contracts. - ... - .postcondition([&] { // Capture by reference... - BOOST_CONTRACT_ASSERT(*old_``/name/`` ...); // ...but should not modify captures. - ... - }) - .except([&] { // Capture by reference... - BOOST_CONTRACT_ASSERT(*old_``/name/`` ...); // ...but should not modify captures. - ... - }) - ; - -Old values are handled by this library using the smart pointer class template [classref boost::contract::old_ptr] (so programmers do not directly manage allocation and deallocation of the pointed memory). -[footnote -*Rationale:* -Old values are optional values because they need to be left uninitialized in case postconditions and exception guarantees are disabled defining [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] and [macroref BOOST_CONTRACT_NO_EXCEPTS] to avoid old value copies in that case (so a pointer or better a `boost::optional` can be used for that). -In addition, old values need to be pointers internally allocated by this library so that they are never copied twice even when calling an overridden function multiple times to check preconditions, postconditions, etc. to implement subcontracting (so a smart pointer class template was used). -] -The pointed old value is automatically qualified as `const` (so old values cannot be mistakenly changed by contract assertions, see __Constant_Correctness__). -This library ensures that old value pointers are always not null by the time postconditions and exception guarantees are checked (so programmers can safely dereference these pointers in postcondition and exception guarantee assertions using `operator*` or `operator->` without having to check if old value pointers are not null first). - -Old values should not be used in preconditions and this library does not guarantee that old value pointers are always not null when preconditions are checked. -[footnote -For example, old value pointers might be null in preconditions when postconditions and exception guarantees are disabled defining [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] and [macroref BOOST_CONTRACT_NO_EXCEPTS], when checking an overridden virtual public function contract via subcontracting, and possibly in other cases. -] -See __Old_Copies_at_Body__ for delaying the assignment of old values until after class invariants (for constructors, destructors, and public functions) and preconditions are checked (this allows to program old value expressions under the simplifying assumption that class invariant and precondition assertions are satisfied already). - -[macroref BOOST_CONTRACT_OLDOF] is a variadic macro and it takes an extra parameter when used in virtual public functions or public function overrides (see __Virtual_Public_Functions__ and __Public_Function_Overrides__). -C++11 auto declarations can be used with [macroref BOOST_CONTRACT_OLDOF] for brevity `auto `[^old_['variable-name] = BOOST_CONTRACT_OLDOF(['expression])]. -See __No_Macros__ to program old values without using [macroref BOOST_CONTRACT_OLDOF] (e.g., on compilers that do not support variadic macros). - -[note -This library ensures that old values are copied only once. -This library also ensures that old values are never copied when postconditions and exception guarantees are disabled defining both [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] and [macroref BOOST_CONTRACT_NO_EXCEPTS] (note that both these two macros must be defined, defining only [macroref BOOST_CONTRACT_NO_POSTCONDITIONS] or only [macroref BOOST_CONTRACT_NO_EXCEPTS] is not sufficient to prevent the run-time cost of old value copies). -] - -[endsect] - -[section Exception Guarantees] - -When exception guarantees are specified, they are programmed using a functor [^['e]] passed to `.except(`[^['e]]`)` that can be called with no parameters as [^['e]]`()`. -Contracts that do not have exception guarantees simply do not call `.except(...)`. -Exception guarantees must appear after both preconditions and postconditions when these are all present (see __Preconditions__ and __Postconditions__). - -C++11 lambda functions are convenient to program exception guarantees, but any other nullary functor can be used (see __No_Lambda_Functions__). -For example, for [funcref boost::contract::function] (but same for all other contracts): - - boost::contract::check c = boost::contract::function() // Same for all other contracts. - ... - .except([&] { // Capture by reference... - BOOST_CONTRACT_ASSERT(...); // ...but should not modify captures. - ... - }) - ; - -The exception guarantee functor should capture all variables that it needs to assert the exception guarantees. -In general, these variables should be captured by reference and not by value (because exception guarantees need to access the value that these variables will have when the function throws, and not the value these variables had when the exception guarantee functor was first constructed). -Exception guarantees can also capture old values (see __Old_Values__) but they should not access the return value instead (because the return value will not be properly set when the function throws an exception). -In any case, exception guarantee assertions should not modify the value of the captured variables (see __Constant_Correctness__). - -[note -In real code, it might be difficult to program meaningful exception guarantees without resorting to expensive old value copies that will slow down execution. -Therefore, the authors recognize that exception guarantees, even if supported by this library, might not be used often in practice (and they are not used in most of the examples listed in the rest of this documentation). -Instead, exception guarantees might be useful in those cases when they can be programmed just reusing the old value copies already present because used by postconditions. -] - -Any code can be programmed in the exception guarantee functor, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex exception guarantees that might be buggy and slow to check at run-time). -It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program exception guarantee assertions because this enables the library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__): - - BOOST_CONTRACT_ASSERT(``/boolean-condition/``) - // Or, if boolean-condition has commas `,` not already within parenthesis `()`... - BOOST_CONTRACT_ASSERT((``/boolean-condition/``)) // ...use extra parenthesis. - -This library will automatically call the failure handler [funcref boost::contract::except_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are `false` and, more in general, if calling the functor specified via `.except(...)` throws any exception. -By default, this failure handler prints an error message to `std::cerr` and terminates the program calling `std::terminate` (see __Throw_on_Failure__ to change the failure handler to exit the program with an error code or to take some other custom action). - -[important -While it is technically possible for programmers to specify an exception guarantee handler that throws an exception in case of an exception guarantee failure, this will force C++ to terminate the program anyway. -That is because the handler will throw an exception while there is already an active exception on the stack (the exception thrown by the function body that caused the exception guarantees to be checked in the first place). -Therefore, programmers should not change the exception guarantee failure handler to throw exceptions. -] - -[endsect] - -[section Class Invariants] - -When class invariants are specified, they are programmed in a public `const` function named `invariant` taking no argument and returning `void`. -Classes that do not have invariants, simply do not declare the `invariant` function. -[footnote -This library uses template meta-programming (SFINAE-based introspection techniques) to check invariants only for classes that declare a member function named [macroref BOOST_CONTRACT_INVARIANT_FUNC]. -] -For example: - - class a { - public: // Must be public. - void invariant() const { // Must be const. - BOOST_CONTRACT_ASSERT(...); - ... - } - - ... - }; - -This member function must be `const` because contracts should not modify the object state (see __Constant_Correctness__). -This library will generate a compile-time error if the `const` qualifier is missing (unless [macroref BOOST_CONTRACT_PERMISSIVE] is defined). - -Any code can be programmed in the `invariant` function, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex invariants that might be buggy and slow to check at run-time). -It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program class invariant assertions because this enables the library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__): - - BOOST_CONTRACT_ASSERT(``/boolean-condition/``) - // Or, if boolean-condition has commas `,` not already within parenthesis `()`... - BOOST_CONTRACT_ASSERT((``/boolean-condition/``)) // ...use extra parenthesis. - -This library will automatically call failure handlers [funcref boost::contract::entry_invariant_failure] or [funcref boost::contract::exit_invariant_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are `false` and, more in general, if the `invariant` function throws an exception when invariants are checked at function entry or exit respectively. -By default, these handlers print an error message to `std::cerr` and terminate the program calling `std::terminate` (see __Throw_on_Failure__ to change these failure handlers to throw exceptions, exit the program with an error code, etc.). - -See __Access_Specifiers__ to avoid making the `invariant` member function `public`. -[footnote -In this documentation the `invariant` member function is often declared `public` for simplicity. -However, in production code it might not be acceptable to augment the public members of a class adding the `invariant` function (and that can be avoided using [classref boost::contract::access] as explained in __Access_Specifiers__). -] -See [macroref BOOST_CONTRACT_INVARIANT_FUNC] to use a name different from `invariant` (e.g., because `invariant` clashes with other names in user-defined classes). - -[note -Contract assertions are not checked (not even class invariants) when data members are accessed directly (this is different from Eiffel where even accessing public data members checks class invariants). -Therefore, it might be best for both `class`es and `struct`s (and also `union`s, see __Unions__) that have invariants to have no mutable public data members and to access data members publicly only via appropriate public functions (e.g., setters and getters) that can check the class invariants. -] - -See __Volatile_Public_Functions__ to program invariants for classes with `volatile` public functions. - -[heading Static Class Invariants] - -When static class invariants are specified, they are programmed in a public `static` function named `static_invariant` taking no argument and returning `void`. -Classes that do not have static class invariants, simply do not declare the `static_invariant` function. -[footnote -This library uses template meta-programming (SFINAE-based introspection techniques) to check static invariants only for classes that declare a member function named [macroref BOOST_CONTRACT_STATIC_INVARIANT_FUNC]. -] -For example: - - class a { - public: // Must be public. - static void static_invariant() { // Must be static. - BOOST_CONTRACT_ASSERT(...); - ... - } - - ... - }; - -This member function must be `static` (and it correctly cannot access the object `this`). -This library will generate a compile-time error if the `static` classifier is missing (unless the [macroref BOOST_CONTRACT_PERMISSIVE] macro is defined). - -Any code can be programmed in the `static_invariant` function, but it is recommended to keep this code simple using mainly assertions and if-statements (to avoid programming complex static invariants that might be buggy and slow to check at run-time). -It is also recommended to use [macroref BOOST_CONTRACT_ASSERT] to program the assertions because this enables the library to print informative error messages when the asserted conditions are evaluated to be false (this is not a variadic macro, see __No_Macros__): - - BOOST_CONTRACT_ASSERT(``/boolean-condition/``) - // Or, if condition has commas `,` not already within parenthesis `()`... - BOOST_CONTRACT_ASSERT((``/boolean-condition/``)) // ...use extra parenthesis. - -This library will automatically call failure handlers [funcref boost::contract::entry_invariant_failure] or [funcref boost::contract::exit_invariant_failure] if any of the [macroref BOOST_CONTRACT_ASSERT] conditions are `false` and, more in general, if the `static_invariant` function throws an exception when invariants are checked at function entry or exit respectively. -By default, these handlers print an error message to `std::cerr` and terminate the program calling `std::terminate` (see __Throw_on_Failure__ to change these failure handlers to throw exceptions, exit the program with an error code, etc.). - -See __Access_Specifiers__ to avoid making `static_invariant` member function `public`. -[footnote -In this documentation the `static_invariant` member function is often declared `public` for simplicity. -However, in production code it might not be acceptable to augment the public members of a class adding the `static_invariant` function (and that can be avoided using [classref boost::contract::access] as explained in __Access_Specifiers__). -] -See [macroref BOOST_CONTRACT_STATIC_INVARIANT_FUNC] to use a name different from `static_invariant` (e.g., because `static_invariant` clashes with other names in user-defined classes). -[footnote -*Rationale:* -In C++, it is not possible to overload a member function based on the `static` classifier. -Therefore, this library has to use different names for the member functions checking non-static and static class invariants (namely [macroref BOOST_CONTRACT_INVARIANT_FUNC] and [macroref BOOST_CONTRACT_STATIC_INVARIANT_FUNC]). -] - -[endsect] - -[section Constructors] - -Contracts for constructors are programmed using the [funcref boost::contract::constructor] function and the [classref boost::contract::constructor_precondition] base class. -For example (see [@../../example/features/public.cpp =public.cpp=]): - -[import ../example/features/public.cpp] -[public_class_begin] -[public_constructor] -[public_class_end] - -It is not possible to specify preconditions using `.precondition(...)` for constructors (this library will generate a compile-time error if `.precondition(...)` is used on the object returned by [funcref boost::contract::constructor]). -Constructor preconditions are specified using the [classref boost::contract::constructor_precondition] base class instead (but the considerations from __Preconditions__ apply also to the precondition functor passed to [classref boost::contract::constructor_precondition]). -Programmes should not access the object `*this` from constructor preconditions (because the object does not exists yet before the constructor body is executed). -[footnote -See __No_Lambda_Functions__ to enforce this constraint at compile-time (but still not recommended because of extra boiler-plate code). -] -Constructors without preconditions simply do not explicitly initialize the [classref boost::contract::constructor_precondition] base (in fact [classref boost::contract::constructor_precondition] default constructor checks no contract). -When [classref boost::contract::constructor_precondition] is used: -[footnote -There is a MSVC bug that was fixed in MSVC 2013 for which lambdas cannot be used in constructor member initialization lists for templates. -On MSVC compilers with that bug, an extra (static) member function can be used (together with `bind` and `cref` as needed) to program constructor preconditions instead of using lambdas (see __No_Lambda_Functions__). -] - -* It should be specified as the /first/ class in the inheritance list (so constructor preconditions are checked before initializing any other base class or data member). -* Its inheritance access specifier should always be `private` (so this extra base class does not alter the public inheritance tree of the derived class). -* It takes the derived class as template parameter (the Curiously Recursive Template Pattern (CRTP) is used here to avoid ambiguity errors with multiple inheritance). -[footnote -*Rationale:* -The [classref boost::contract::constructor_precondition] takes the derived class as its template parameter so the instantiated template type is unique for each derived class. -This always avoids base class ambiguity errors even when multiple inheritance is used. -Note that virtual inheritance could not be used instead of the template parameter here to avoid ambiguity errors (because virtual bases are initialized only once by the out-most derived class, and that would not allow to properly check preconditions of all base classes). -] - -[note -A class can avoid inheriting from [classref boost::contract::constructor_precondition] for efficiency but only when all its constructors have no preconditions. -] - -It is possible to specify postconditions for constructors (see __Postconditions__). -Programmers should not access the old value of the object `*this` in constructor postconditions (because the object did not exist yet before the constructor body was executed). -[footnote -See __No_Lambda_Functions__ to enforce this constraint at compile-time (but still not recommended because of extra boiler-plate code). -] -The [funcref boost::contract::constructor] function takes `this` as a parameter (because constructors check class invariants, see __Class_Invariants__). - -The [funcref boost::contract::constructor] function returns an RAII object that must always be assigned to a local variable of type [classref boost::contract::check] (otherwise this library will generate a run-time error, see [macroref BOOST_CONTRACT_ON_MISSING_CHECK_DECL]). -Furthermore, C++11 `auto` declarations cannot be used here and the [classref boost::contract::check] type must be explicitly specified (otherwise this library will generate a compile-time error). -The constructor body is programmed right after the declaration of the RAII object. - -At construction, the [classref boost::contract::check] RAII object for constructors does the following (enclosing constructor entry): - -# Check static class invariants, by calling [^['type-of]]`(*this)::static_invariant()` (but not non-static class invariants because the object does not exist yet). - -At destruction instead (enclosing constructor exit): - -# Check static class invariants, by calling [^['type-of]]`(*this)::static_invariant()`. -# If the constructor body did not throw an exception: - # Check non-static class invariants, by calling `this->invariant()`. - # Check postconditions, by calling the nullary functor [^['s]]`()` passed to `.postcondition(`[^['s]]`)`. -# Else: - # Check exception guarantees, by calling the nullary functor [^['e]]`()` passed to `.except(`[^['e]]`)`. - -This together with C++ object construction mechanism of base classes and the use of [classref boost::contract::constructor_precondition] ensures that the constructor contracts are correctly checked at run-time (see __Constructor_Calls__). - -[note -A constructor can avoid calling [funcref boost::contract::constructor] for efficiency but only when it has no postconditions, no exception guarantees, and its class has no invariants (even if [funcref boost::contract::constructor] is not used by a derived class, contracts of base class constructors will still be correctly checked by C++ object construction mechanism). - -The default constructor and copy constructor automatically generated by C++ will not check contracts. -Therefore, unless these constructors are not public or they have no preconditions, no postconditions, no exception guarantees, and their class has no invariants, programmers should manually define them using [funcref boost::contract::constructor] and [classref boost::contract::constructor_precondition]. -Similar considerations apply to all other constructors automatically generated by C++ (e.g., move constructor). -] - -Private and protected constructors can omit [funcref boost::contract::constructor] (because they are not part of the public interface of the class so they are not required to check class invariants, see __Constructor_Calls__). -They could still use [classref boost::contract::constructor_precondition] to check preconditions before member initializations, and even use [funcref boost::contract::function] (but not [funcref boost::contract::constructor]) to only check postconditions and exception guarantees without checking class invariants and without calling `.precondition(...)` (see __Private_and_Protected_Functions__). -For example: - - class a : private boost::contract::constructor_precondition { - protected: - // Contract for a protected constructor (same for private constructors). - a() : // Still use this base class to check constructor preconditions. - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(...); - ... - }) - { - // Following will correctly not check class invariants. - boost::contract::check c = boost::contract::function() - // Do not use `.precondition(...)` here. - .postcondition([&] { - BOOST_CONTRACT_ASSERT(...); - ... - }) - .except([&] { - BOOST_CONTRACT_ASSERT(...); - ... - }) - ; - - ... // Constructor body. - } - - ... - }; - -[endsect] - -[section Destructors] - -Contracts for destructors are programmed using [funcref boost::contract::destructor]. -For example (see [@../../example/features/public.cpp =public.cpp=]): - -[public_class_begin] -[public_destructor] -[public_class_end] - -It is not possible to specify preconditions for destructors (this library will generate a compile-time error if `.precondition(...)` is used here because destructors can be called at any time after construction so they have no precondition). -It is possible to specify postconditions for destructors (see __Postconditions__, and also __Static_Public_Functions__ for an example). -Programmers should not access the object `*this` in destructor postconditions (because the object no longer exists after the destructor body has been executed). -[footnote -See __No_Lambda_Functions__ to enforce this constraint at compile-time (but still not recommended because of extra boiler-plate code). -] -The [funcref boost::contract::destructor] function takes `this` as a parameter (because destructors check class invariants, see __Class_Invariants__). - -The [funcref boost::contract::destructor] function returns an RAII object that must always be assigned to a local variable of type [classref boost::contract::check] (otherwise this library will generate a run-time error, see [macroref BOOST_CONTRACT_ON_MISSING_CHECK_DECL]). -Furthermore, C++11 `auto` declarations cannot be used here and the [classref boost::contract::check] type must be explicitly specified (otherwise this library will generate a compile-time error). -The destructor body is programmed right after the declaration of the RAII object. - -At construction, the [classref boost::contract::check] RAII object for destructors does the following (enclosing destructor entry): - -# Check static and non-static class invariants, by calling ['[^type-of]]`(*this)::static_invariant()` __AND__ `this->invariant()`. - -At destruction instead (enclosing destructor exit): - -# Check static class invariants, by calling [^['type-of]]`(*this)::static_invariant()`. -# If the destructor body did not throw an exception: - # Check postconditions, by calling the nullay functor [^['s]]`()` passed to `.postcondition(`[^['s]]`)`. -# Else (even if destructors should generally be programmed not to throw in C++): - # Check non-static class invariants, by calling `this->invariant()` (because the object was not successfully destructed). - # Check exception guarantees, by calling the nullary functor [^['e]]`()` passed to `.except(`[^['e]]`)`. - -This together with C++ object destruction mechanism of base classes ensures that destructor contracts are correctly checked at run-time (see __Destructor_Calls__). - -[note -A destructor can avoid calling [funcref boost::contract::destructor] for efficiency but only when it has no postconditions, no exception guarantees, and its class has no invariants (even if [funcref boost::contract::destructor] is not used by a derived class, contracts of base class destructors will still be correctly checked by C++ object destruction mechanism). - -The default destructor automatically generated by C++ will not check contracts. -Therefore, unless the destructor is not public or it has no postconditions, no exception guarantees, and its class has no invariants, programmers should manually define it using [funcref boost::contract::destructor]. -] - -Private and protected destructors can omit [funcref boost::contract::destructor] (because they are not part of the public interface of the class so they are not required to check class invariants, see __Destructor_Calls__). -They could use [funcref boost::contract::function] (but not [funcref boost::contract::destructor]) to only check postconditions and exception guarantees without checking class invariants and without calling `.precondition(...)` (see __Private_and_Protected_Functions__). -For example: - - class a { - protected: - // Contract for a protected destructor (same for private destructors). - virtual ~a() { - // Following will correctly not check class invariants. - boost::contract::check c = boost::contract::function() - // Do not use `.precondition(...)` here. - .postcondition([&] { - BOOST_CONTRACT_ASSERT(...); - ... - }) - ; - - ... // Destructor body. - } - - ... - }; - -[endsect] - -[section Public Functions] - -Contracts for public functions are programmed using [funcref boost::contract::public_function]. -In this section, let's consider public functions that are not static, not virtual, and do not override any function from base classes. -For example (see [@../../example/features/public.cpp =public.cpp=]): - -[public_class_begin] -[public_function] -[public_class_end] - -It is possible to specify preconditions, postconditions, and exception guarantees for public functions (see __Preconditions__, __Postconditions__, and __Exception_Guarantees__). -When called from non-static public functions, the [funcref boost::contract::public_function] function takes `this` as a parameter (because public functions check class invariants, see __Class_Invariants__). - -The [funcref boost::contract::public_function] function returns an RAII object that must always be assigned to a local variable of type [classref boost::contract::check] (otherwise this library will generate a run-time error, see [macroref BOOST_CONTRACT_ON_MISSING_CHECK_DECL]). -Furthermore, C++11 `auto` declarations cannot be used here and the [classref boost::contract::check] type must be explicitly specified (otherwise this library will generate a compile-time error). -The public function body is programmed right after the declaration of the RAII object. - -At construction, the [classref boost::contract::check] RAII object for public functions does the following (enclosing public function entry): - -# Check static and non-static class invariants, by calling [^['type-of]]`(*this)::static_invariant()` __AND__ `this->invariant()`. -# Check preconditions, by calling the nullary functor [^['r]]`()` passed to `.precondition(`[^['r]]`)`. - -At destruction instead (enclosing public function exit): - -# Check static and non-static class invariants, by calling [^['type-of]]`(*this)::static_invariant()` __AND__ `this->invariant()` (even if the function body threw an exception). -# If the function body did not throw an exception: - # Check postconditions, by calling the nullary functor [^['s]]`()` passed to `.postcondition(`[^['s]]`)`. -# Else: - # Check exception guarantees, by calling the nullary functor [^['e]]`()` passed to `.except(`[^['e]]`)`. - -This ensures that public function contracts are correctly checked at run-time (see __Public_Function_Calls__). - -[note -A public function can avoid calling [funcref boost::contract::public_function] for efficiency but only when it has no preconditions, no postconditions, no exception guarantees, it is not virtual, it does not override any virtual function, and its class has no invariants. - -The default copy assignment operator automatically generated by C++ will not check contracts. -Therefore, unless this operator is not public or it has no preconditions, no postconditions, no exception guarantees, and its class has no invariants, programmers should manually define it using [funcref boost::contract::public_function]. -Similar considerations apply to all other operations automatically generated by C++ (move operator, etc.). -] - -[endsect] - -[section Virtual Public Functions] - -Contracts for public functions are programmed using [funcref boost::contract::public_function]. -In this section, let's consider public functions that are virtual but that do not override any function from base classes. -For example (see [@../../example/features/public.cpp =public.cpp=]): - -[public_class_begin] -[public_virtual_function] -[public_class_end] - -Virtual public functions must declare an extra trailing parameter of type [classref boost::contract::virtual_]`*` with default value `0` (i.e., `nullptr`). -[footnote -The name of this extra parameter is arbitrary, but `v` is often used in this documentation. -] -This extra parameter is the last parameter and it has a default value so it does not alter the calling interface of the virtual function (in practice, callers will rarely, if ever, have to explicitly deal with this extra parameter, a part from when manipulating the virtual function type directly for function pointer type-casting, etc.). -Programmers must pass the extra virtual parameter as the very first argument to all [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::public_function] calls in the virtual public function definition. -[footnote -*Rationale:* -The [classref boost::contract::virtual_]`*` parameter is used by this library to determine that a function is virtual (in C++ it is not possible to introspect if a function is declared `virtual`). -Furthermore, this parameter is internally used by this library to pass result and old values that are evaluated by the overriding function to overridden virtual functions in base classes, and also to check preconditions, postconditions, and exception guarantees of overridden virtual functions to implement subcontracting. -] - -When called from virtual public functions, the [funcref boost::contract::public_function] function takes `this` as a parameter (because public functions check class invariants, see __Class_Invariants__). -For virtual public functions returning `void`: - - // In a void virtual public function (that does not override). - boost::contract::check c = boost::contract::public_function(v, this) // No result parameter... - .precondition([&] { ... }) - .postcondition([&] { ... }) // ...so nullary functor. - .except([&] { ... }) - ; - -For virtual public functions not returning `void`, programmers must also pass a reference to the function return value as the second argument to [funcref boost::contract::public_function]. -In this case, the library will pass this return value reference to the postcondition functor that must therefore take one single argument matching the return type, otherwise this library will generate a compile-time error (the functor parameter can be a constant reference `const&` to avoid extra copies of the return value): -[footnote -*Rationale:* -The extra function result parameter taken by the functor passed to `.postcondition(...)` is used by this library to pass the return value evaluated by the overriding function to all its overridden virtual functions when subcontracting. -] - - // In a non-void virtual public function (that does not override). - ``['return-type]`` result; - boost::contract::check c = boost::contract::public_function(v, result, this) // Result parameter... - .precondition([&] { ... }) - .postcondition([&] (``['return-type]`` const& result) { ... }) // ...so unary functor. - .except([&] { ... }) - ; - -[important -It is the responsibility of the programmers to pass the extra virtual parameter `v` to all [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::public_function] calls within virtual public functions, and also to pass the return value reference after `v` to [funcref boost::contract::public_function] for non-void virtual public functions. -This library cannot automatically generate compile-time errors if programmers fail to do so (but in general this will prevent the library from correctly checking contracts at run-time). -[footnote -*Rationale:* -This library does not require programmers to specify the function type when using [funcref boost::contract::public_function] for non-overriding virtual public functions. -Therefore, this library does not know if the enclosing function has a non-void return type so it cannot check if the return value reference is passed as required for non-overriding virtual public functions. -Instead the function type is passed to this library for virtual public function overrides and that also allows this library to give a compile-time error if the return value reference is missing in those cases. -] -Remember: -[:Always pass the function parameter `v` as the first argument to [macroref BOOST_CONTRACT_OLDOF] and to [funcref boost::contract::public_function].] -[:Always pass the function return value to [funcref boost::contract::public_function] right after `v` (for non-void virtual public functions).] -] - -For the rest, considerations made in __Public_Functions__ apply to virtual public functions as well. - -[note -A virtual public function should always call [funcref boost::contract::public_function] (even if it has no preconditions, no postconditions, no exception guarantees, and its class has no invariants), otherwise this library will not be able to correctly use it for subcontracting. -] - -[endsect] - -[section Public Function Overrides (Subcontracting)] - -Contracts for public functions are programmed using [funcref boost::contract::public_function]. -In this section, let's consider public functions (virtual or not) that override virtual public functions from one or more public base classes. -For example (see [@../../example/features/public.cpp =public.cpp=]): -[footnote -In this documentation, function overrides are often marked with the code comment `/* override */`. -On compilers that support C++11 virtual specifiers, the `override` identifier can be used instead (`override` is not used in the documentation only because virtual specifiers are not widely supported yet, even by compilers that support C++11 lambda functions). -] - -[public_derived_class_begin] -[public_function_override] -[public_derived_class_end] - -The extra `typedef` declared using [macroref BOOST_CONTRACT_BASE_TYPES] is required by this library for derived classes and it is internally used detect base classes for subcontracting (see __Base_Classes__). - -When called from public function overrides, the [funcref boost::contract::public_function] function template takes an explicit template argument `override_`[^['function-name]] that must be defined using [macroref BOOST_CONTRACT_OVERRIDE]: - - BOOST_CONTRACT_OVERRIDE(``['function-name]``) - -This can be declared at any point in the public section of the enclosing class (see __Access_Specifiers__ to use [macroref BOOST_CONTRACT_OVERRIDE] in a non-public section of the class instead). -[macroref BOOST_CONTRACT_OVERRIDE] must be used only once in a class for a given function name and overloaded functions can reuse the same [^override_['function-name]] definition (see __Function_Overloads__). -[macroref BOOST_CONTRACT_NAMED_OVERRIDE] can be used to generate a name different than [^override_['function-name]] (e.g., to avoid generating C++ reserved names containing double underscores "`__`" for function names that already start with an underscore "`_`", see __Named_Overrides__). -For convenience [macroref BOOST_CONTRACT_OVERRIDES] can be used with multiple function names instead of repeating [macroref BOOST_CONTRACT_OVERRIDE] for each function name (on compilers that support variadic macros). -For example, for three functions named `f`, `g`, and `h` (but same for any other number of functions), the following: - - BOOST_CONTRACT_OVERRIDES(f, g, h) - -Is equivalent to: -[footnote -This library does not provider an equivalent of [macroref BOOST_CONTRACT_NAMED_OVERRIDE] that operates on multiple function names at once (simply because programmers will probably not use [macroref BOOST_CONTRACT_NAMED_OVERRIDE] often in the first place). -] - - BOOST_CONTRACT_OVERRIDE(f) - BOOST_CONTRACT_OVERRIDE(g) - BOOST_CONTRACT_OVERRIDE(h) - -This library will generate a compile-time error if there is no suitable virtual function to override in any of the public base classes for subcontracting. -[footnote -The compile-time error generated by the library in this case is similar in principle to the error generated by the C++11 `override` specifier, but it is limited to functions with the extra [classref boost::contract::virtual_]`*` parameter and searched recursively only in `public` base classes passed to [macroref BOOST_CONTRACT_BASE_TYPES] because only those are considered for subcontracting. -] - -Public function overrides must always list the extra trailing parameter of type [classref boost::contract::virtual_]`*` with default value `0` (i.e., `nullptr`), even when they are not declared `virtual` (because this parameter is present in the signature of the virtual function being overridden from base classes). -Programmers must pass the extra virtual parameter as the very first argument to all [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::public_function] calls in the public function override definition (see __Virtual_Public_Functions__). - -When called from public function overrides, the [funcref boost::contract::public_function] function takes a pointer to the enclosing function, the object `this` (because public function overrides check class invariants, see __Class_Invariants__), and references to each function argument in the order they appear in the function declaration. -[footnote -*Rationale:* -The object `this` is passed after the function pointer to follow `bind`'s syntax. -The function pointer and references to all function arguments are needed for public function overrides because this library has to call overridden virtual public functions to check their contracts for subcontracting (even if this library will not actually execute the bodies of the overridden functions). -] -For public function overrides returning `void`: - - // In a void public function override. - boost::contract::check c = boost::contract::public_function( - v, &``['class-name]``::``['function-name]``, this, // No result parameter... - ``['function-argument_1]``, ``['function-argument_2]``, ... - ) - .precondition([&] { ... }) - .postcondition([&] { ... }) // ...so nullary functor. - .except([&] { ... }) - ; - -For public function overrides not returning `void`, programmers must also pass a reference to the function return value as the second argument to [funcref boost::contract::public_function] (this library will generate a compile-time error otherwise). -[footnote -*Rationale:* -As for non-overriding virtual public functions, also public function overrides use the extra return value parameter to pass it to the overridden functions when subcontracting. -In the case of public function overrides this library also has the function pointer so it will generate a compile-time error if the function is non-void and programmers forget to specify the extra return value parameter (this extra error checking is not possible instead for non-overriding virtual public functions because their contracts do not take the function pointer as a parameter, see __Virtual_Public_Functions__). -] -In this case, the library will pass this return value reference to the postcondition functor that must therefore take one single argument matching the return type, otherwise this library will generate a compile-time error (the functor parameter can be a constant reference `const&` to avoid extra copies of the return value): - - // In non-void public function override. - ``['return-type]`` result; - boost::contract::check c = boost::contract::public_function( - v, result, &``['class-name]``::``['function-name]``, this, // Result parameter... - ``['function-argument_1]``, ``['function-argument_2]``, ... - ) - .precondition([&] { ... }) - .postcondition([&] (``['return-type]`` const& result) { ... }) // ...so unary functor. - .except([&] { ... }) - ; - -This library will throw [classref boost::contract::bad_virtual_result_cast] if programmers specify return values for public function overrides in derived classes that are not consistent with the return types of the virtual public functions being overridden in the base classes. -[footnote -*Rationale:* -The `boost::bad_any_cast` exception could not used here because it does not print the from- and to- type names (so it is not descriptive enough). -] - -[important -It is the responsibility of the programmers to pass the extra virtual parameter `v` to all [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::public_function] calls within public function overrides, and also to pass the return value reference after `v` to [funcref boost::contract::public_function] for non-void public function overrides. -This library cannot always generate compile-time errors if programmers fail to do so (but in general this will prevent the library from correctly checking contracts at run-time). -Remember: -[:Always pass the function parameter `v` as the first argument to [macroref BOOST_CONTRACT_OLDOF] and [funcref boost::contract::public_function].] -[:Always pass the function return value to [funcref boost::contract::public_function] right after `v` (for non-void public function overrides).] -] - -At construction, the [classref boost::contract::check] RAII object for public function overrides does the following (enclosing public function override entry): - -# Check static and non-static class invariants for all overridden bases and for the derived class in __AND__ with each other, by calling [^['type-of](['overridden-base_1])]`::static_invariant()` __AND__ [^['overridden-base_1]]`.invariant()` __AND__... [^['type-of](['overridden-base_n])]`::static_invariant()` __AND__ [^['overridden-base_n]]`.invariant()` __AND__ [^['type-of]]`(*this)::static_invariant()` __AND__ `this->invariant()`. -# Check preconditions for all overridden base functions and for the overriding derived function in __OR__ with each other, by calling the nullary functors [^['r_1]]`()` __OR__... [^['r_n]]`()` __OR__ [^['r]]`()` passed to `.precondition(`[^['r_1]]`)`, ... `.precondition(`[^['r_n]]`)`, `.precondition(`[^['r]]`)` for all of the overridden and overriding functions respectively. - -At destruction instead (enclosing public function override exit): - -# Check static and non-static class invariants for all overridden bases and for the derived class in __AND__ with each other, by calling [^['type-of](['overridden-base_1])]`::static_invariant()` __AND__ [^['overridden-base_1]]`.invariant()` __AND__... [^['type-of](['overridden-base_n])]`::static_invariant()` __AND__ [^['overridden-base_n]]`.invariant()` __AND__ [^['type-of]]`(*this)::static_invariant()` __AND__ `this->invariant()` (even if the function body threw an exception). -# If the function body did not throw an exception: - # Check postconditions for all overridden base functions and for the overriding derived function in __AND__ with each other, by calling the nullary functors [^['s_1]]`()` __AND__... [^['s_n]]`()` __AND__ [^['s]]`()` passed to `.postcondition(`[^['s_1]]`)`, ... `.postcondition(`[^['s_n]]`)`, `.postcondition(`[^['s]]`)` for all of the overridden and overriding functions respectively (or the unary functors [^['s_1]]`(`[^['result]]`)` __AND__... [^['s_n]]`(`[^['result]]`)` __AND__ [^['s]]`(`[^['result]]`)` for non-void public function overrides). -# Else: - # Check exception guarantees for all overridden base functions and for the overriding derived function in __AND__ with each other, by calling the nullary functors [^['e_1]]`()` __AND__... [^['e_n]]`()` __AND__ [^['e]]`()` passed to `.except(`[^['e_1]]`)`, ... `.except(`[^['e_n]]`)`, `.except(`[^['e]]`)` for all of the overridden and overriding functions respectively. - -This ensures that public function override contracts and subcontracts are correctly checked at run-time (see __Public_Function_Calls__). - -For the rest, considerations made in __Virtual_Public_Functions__ apply to public function overrides as well. - -[note -A public function override should always call [funcref boost::contract::public_function] (even if it has no preconditions, no postconditions, no exception guarantees, and its class has no invariants), otherwise this library will not be able to correctly use it for subcontracting. -] - -[endsect] - -[section Base Classes (Subcontracting)] - -In order for this library to support subcontracting, programmers must specify the bases of a derived class declaring a public member type named `base_types` via a `typedef` using [macroref BOOST_CONTRACT_BASE_TYPES]. -For example (see [@../../example/features/base_types.cpp =base_types.cpp=]): - -[import ../example/features/base_types.cpp] -[base_types] - -For convenience, a local macro named `BASES` can be used to avoid repeating the base list twice (first in the derived class declaration `class `[^['class-name]]` : `[^['base-list]] and then again when invoking [macroref BOOST_CONTRACT_BASE_TYPES]`(`[^['base-list]]`)`). -Being a local macro, `BASES` must be undefined using `#undef BASES` after it has been used to declare `base_types` (to avoid name clashes and macro redefinition errors). -[footnote -The name of this local macro is arbitrary, but `BASES` is often used in this documentation. -] - -[macroref BOOST_CONTRACT_BASE_TYPES] is a variadic macro and accepts a list of bases separated by commas (see __No_Macros__ to program `base_types` without using macros). -As already noted in __Constructors__, when the extra base [classref boost::contract::constructor_precondition] is used to program constructor preconditions, its inheritance access level must always be `private` and it must be specified as the very first base. - -[important -Each base passed to [macroref BOOST_CONTRACT_BASE_TYPES] must /explicitly/ specify its inheritance access level `public`, `protected`, or `private` (but `virtual` is optional and can be specified either before or after the access level as usual in C++). -[footnote -*Rationale:* -This library explicitly requires the inheritance access level because derived classes must subcontract only from public bases, but not from protected or private bases (see __Public_Function_Calls__). -Therefore, [macroref BOOST_CONTRACT_BASE_TYPES] inspects each inheritance access level (using preprocessor meta-programming) and removes non-public bases from the list of bases inspected for subcontracting (i.e., from `base_types`). -] -This library will generate a compile-time error if the first base is missing its inheritance access level, but this library will not be able to always generate an error if the access level is missing for bases after the first one. -It is the responsibility of the programmers to make sure that all bases passed to [macroref BOOST_CONTRACT_BASE_TYPES] explicitly specify their inheritance access level (inheritance access levels are instead optional in C++ because `private` is implicitly assumed for `class` types and `public` for `struct` types). -Remember: -[:Always explicitly specify the inheritance access level `public`, `protected`, or `private` for base classes of derived classes with contracts.] -] - -See __Access_Specifiers__ to avoid making the `base_types` member type `public`. -[footnote -In this documentation the `base_type` member type is often declared `public` for simplicity. -However, in production code it might not be acceptable to augment the public members of a class adding the `base_types` type (and that can be avoided using [classref boost::contract::access] as explained in __Access_Specifiers__). -] -See [macroref BOOST_CONTRACT_BASES_TYPEDEF] to use a name different from `base_types` (e.g., because `base_types` clashes with other names in user-defined classes). - -[endsect] - -[section Static Public Functions] - -Contracts for public functions are programmed using [funcref boost::contract::public_function]. -In this section, let's consider static public functions. -For example (see [@../../example/features/static_public.cpp =static_public.cpp=]): - -[import ../example/features/static_public.cpp] -[static_public] - -It is possible to specify preconditions, postconditions, and exception guarantees for static public functions (see __Preconditions__, __Postconditions__, and __Exception_Guarantees__). -However, when called from static public functions, [funcref boost::contract::public_function] cannot take the object `this` as a parameter (because there is no object `this` in static member functions) so the enclosing class type is is specified as an explicit template parameter (because the class type is necessary to check static class invariants, see __Class_Invariants__): - - // In a static public function. - boost::contract::check c = boost::contract::public_function<``[^['class-type]]``>() // Explicit class type template parameter. - .precondition([&] { ... }) - .postcondition([&] { ... }) - .except([&] { ... }) - ; - -The [funcref boost::contract::public_function] function returns an RAII object that must be assigned to a local variable of type [classref boost::contract::check] (otherwise this library will generate a run-time error, see [macroref BOOST_CONTRACT_ON_MISSING_CHECK_DECL]). -Furthermore, C++11 `auto` declarations cannot be used here and the [classref boost::contract::check] type must be explicitly specified (otherwise this library will generate a compile-time error). -The static public functions body is programmed right after the declaration of the RAII object. - -At construction, the [classref boost::contract::check] RAII object for static public functions does the following (enclosing static public function entry): - -# Check static class invariants, by calling [^['class-type]]`::static_invariant()` (but never non-static class invariants). -# Check preconditions, by calling the nullary functor [^['r]]`()` passed to `.precondition(`[^['r]]`)`. - -At destruction instead (enclosing static public function exit): - -# Check static class invariants, by calling [^['class-type]]`::static_invariant()` (even if the function body threw an exception, but never non-static class invariants). -# If the function body did not throw an exception: - # Check postconditions, by calling the nullary functor [^['s]]`()` passed to `.postcondition(`[^['s]]`)`. -# Else: - # Check exception guarantees, by calling the nullary functor [^['e]]`()` passed to `.except(`[^['e]]`)`. - -This ensures that static public function contracts are correctly checked at run-time (see __Public_Function_Calls__). -[footnote -Note that static public functions do not subcontract because they have no object `this` and therefore there is no inheritance. -] - -[note -A static public function can avoid calling [funcref boost::contract::public_function] for efficiency but only when it has no preconditions, no postconditions, no exception guarantees, and its class has no static invariants (the class can still have non-static invariants or base classes instead). -] - -[endsect] - -[endsect] - diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 deleted file mode 100644 index 5b0671dd..00000000 --- a/example/Jamfile.v2 +++ /dev/null @@ -1,85 +0,0 @@ - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -make help : : help_exit ; -explicit help ; - -test-suite features : - [ subdir-run features : introduction_comments ] - [ subdir-run features : introduction ] - [ subdir-run features : introduction_public ] - - [ subdir-run features : non_member ] - [ subdir-run features : lambda ] - [ subdir-run features : loop ] - [ subdir-run features : code_block ] - [ subdir-run features : public ] - [ subdir-run features : base_types ] - [ subdir-run features : static_public ] - [ subdir-run features : private_protected ] - [ subdir-run features : private_protected_virtual ] - [ subdir-run features : private_protected_virtual_multi ] - [ subdir-run features : check ] - - [ subdir-run features : friend ] - [ subdir-run features : friend_invariant ] - [ subdir-run features : old ] - [ subdir-run features : optional_result ] - [ subdir-run features : optional_result_virtual ] - [ subdir-run features : pure_virtual_public ] - [ subdir-run features : overload ] - [ subdir-run features : named_override ] - [ subdir-run features : move ] - [ subdir-run features : union ] - [ subdir-run features : volatile ] - [ subdir-run features : old_if_copyable ] - [ subdir-run features : condition_if ] - [ subdir-run features : call_if_cxx14 : # Requires C++14. - clang:-std=c++1y ] - [ subdir-run features : access ] - [ subdir-run features : separate_body ] - [ subdir-run features : throw_on_failure ] - [ subdir-run features : ifdef ] - [ subdir-run features : assertion_level ] - [ subdir-run features : ifdef_macro ] - [ subdir-run features : base_types_no_macro ] - [ subdir-run features : old_no_macro ] - [ subdir-run features : no_lambdas ] - [ subdir-run features : no_lambdas_local_func ] -; - -test-suite n1962 : - [ subdir-run n1962 : vector ] - [ subdir-run n1962 : sqrt ] - [ subdir-run n1962 : circle ] - [ subdir-run n1962 : equal ] - [ subdir-run n1962 : factorial ] - [ subdir-run n1962 : sum ] -; - -test-suite meyer97 : - [ subdir-run meyer97 : stack4_main ] - [ subdir-run meyer97 : stack3 ] -; - -test-suite mitchell02 : - [ subdir-run mitchell02 : stack ] - [ subdir-run mitchell02 : simple_queue ] - [ subdir-run mitchell02 : dictionary ] - [ subdir-run mitchell02 : customer_manager ] - [ subdir-run mitchell02 : name_list ] - [ subdir-run mitchell02 : courier ] - [ subdir-run mitchell02 : observer_main ] - [ subdir-run mitchell02 : counter_main ] -; - -test-suite cline90 : - [ subdir-run cline90 : stack ] - [ subdir-run cline90 : vector_main ] - [ subdir-run cline90 : vstack ] - [ subdir-run cline90 : calendar ] -; - diff --git a/example/cline90/calendar.cpp b/example/cline90/calendar.cpp deleted file mode 100644 index 70d618f7..00000000 --- a/example/cline90/calendar.cpp +++ /dev/null @@ -1,93 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_calendar -#include -#include - -class calendar { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(month() >= 1); - BOOST_CONTRACT_ASSERT(month() <= 12); - BOOST_CONTRACT_ASSERT(date() >= 1); - BOOST_CONTRACT_ASSERT(date() <= days_in(month())); - } - -public: - calendar() : month_(1), date_(31) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(month() == 1); - BOOST_CONTRACT_ASSERT(date() == 31); - }) - ; - } - - virtual ~calendar() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - int month() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return month_; - } - - int date() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return date_; - } - - void reset(int new_month) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(new_month >= 1); - BOOST_CONTRACT_ASSERT(new_month <= 12); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(month() == new_month); - }) - ; - - month_ = new_month; - } - -private: - static int days_in(int month) { - int result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(month >= 1); - BOOST_CONTRACT_ASSERT(month <= 12); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result >= 1); - BOOST_CONTRACT_ASSERT(result <= 31); - }) - ; - - return 31; // For simplicity, assume all months have 31 days. - } - - int month_, date_; -}; - -int main() { - calendar cal; - assert(cal.date() == 31); - assert(cal.month() == 1); - - cal.reset(8); // Set month - assert(cal.month() == 8); - - return 0; -} -//] - diff --git a/example/cline90/stack.cpp b/example/cline90/stack.cpp deleted file mode 100644 index 6a8d9f8c..00000000 --- a/example/cline90/stack.cpp +++ /dev/null @@ -1,92 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_stack -#include -#include - -// NOTE: Incomplete contract assertions, addressing only `empty` and `full`. -template -class stack - #define BASES private boost::contract::constructor_precondition > - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - -public: - explicit stack(int capacity) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(capacity >= 0); - }), - data_(new T[capacity]), capacity_(capacity), size_(0) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - BOOST_CONTRACT_ASSERT(full() == (capacity == 0)); - }) - ; - - for(int i = 0; i < capacity_; ++i) data_[i] = T(); - } - - virtual ~stack() { - boost::contract::check c = boost::contract::destructor(this); - delete[] data_; - } - - bool empty() const { - boost::contract::check c = boost::contract::public_function(this); - return size_ == 0; - } - - bool full() const { - boost::contract::check c = boost::contract::public_function(this); - return size_ == capacity_; - } - - void push(T const& value) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!full()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - - data_[size_++] = value; - } - - T pop() { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!full()); - }) - ; - - return data_[--size_]; - } - -private: - T* data_; - int capacity_; - int size_; -}; - -int main() { - stack s(3); - s.push(123); - assert(s.pop() == 123); - return 0; -} -//] - diff --git a/example/cline90/vector.hpp b/example/cline90/vector.hpp deleted file mode 100644 index 3954615f..00000000 --- a/example/cline90/vector.hpp +++ /dev/null @@ -1,100 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_vector -#ifndef VECTOR_HPP_ -#define VECTOR_HPP_ - -#include - -// NOTE: Incomplete contract assertions, addressing only `size`. -template -class vector - #define BASES private boost::contract::constructor_precondition > - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void invariant() const { - BOOST_CONTRACT_ASSERT(size() >= 0); - } - -public: - explicit vector(int count = 10) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(count >= 0); - }), - data_(new T[count]), - size_(count) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - }) - ; - - for(int i = 0; i < size_; ++i) data_[i] = T(); - } - - virtual ~vector() { - boost::contract::check c = boost::contract::destructor(this); - delete[] data_; - } - - int size() const { - boost::contract::check c = boost::contract::public_function(this); - return size_; // Non-negative result already checked by invariant. - } - - void resize(int count) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count >= 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - }) - ; - - T* slice = new T[count]; - for(int i = 0; i < count && i < size_; ++i) slice[i] = data_[i]; - delete[] data_; - data_ = slice; - size_ = count; - } - - T& operator[](int index) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index >= 0); - BOOST_CONTRACT_ASSERT(index < size()); - }) - ; - - return data_[index]; - } - - T const& operator[](int index) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index >= 0); - BOOST_CONTRACT_ASSERT(index < size()); - }) - ; - - return data_[index]; - } - -private: - T* data_; - int size_; -}; - -#endif // #include guard -//] - diff --git a/example/cline90/vector_axx.hpp b/example/cline90/vector_axx.hpp deleted file mode 100644 index e0c60b41..00000000 --- a/example/cline90/vector_axx.hpp +++ /dev/null @@ -1,100 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_vector_axx -// Extra spaces, newlines, etc. for visual alignment with this library code. - - - - - -template -class vector { - - - - - - - -legal: // Class invariants (legal). - size() >= 0; - - -public: - explicit vector(int count = 10) : - data_(new T[count]), - size_(count) - { - for(int i = 0; i < size_; ++i) data_[i] = T(); - } - - - - - - - - - - - virtual ~vector() { delete[] data_; } - - - - - int size() const { return size_; } - - - - - void resize(int count) { - T* slice = new T[count]; - for(int i = 0; i < count && i < size_; ++i) slice[i] = data_[i]; - delete[] data_; - data_ = slice; - size_ = count; - } - - - - - - - - - - - T& operator[](int index) { return data_[index]; } - - - - - - - - - - - T& operator[](int index) const { return data_[index]; } - - - - -axioms: // Preconditions (require) and postconditions (promise) for each func. - [int count; require count >= 0; promise size() == count] vector(count); - [int count; require count >= 0; promise size() == count] resize(count); - [int index; require index >= 0 && index < size()] (*this)[x]; // Op[]. - [int index; require index >= 0 && index < size()] (*this)[x] const; // Op[]. - -private: - T* data_; - int size_; -}; - -// End. -//] - diff --git a/example/cline90/vector_main.cpp b/example/cline90/vector_main.cpp deleted file mode 100644 index dac6facc..00000000 --- a/example/cline90/vector_main.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_vector_main -#include "vector.hpp" -#include - -int main() { - vector v (3); - assert(v.size() == 3); - - v[0] = 123; - v.resize(2); - assert(v[0] == 123); - assert(v.size() == 2); - - return 0; -} -//] - diff --git a/example/cline90/vstack.cpp b/example/cline90/vstack.cpp deleted file mode 100644 index 2af812e8..00000000 --- a/example/cline90/vstack.cpp +++ /dev/null @@ -1,237 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[cline90_vstack -#include "vector.hpp" -#include -#include -#include - -// NOTE: Incomplete contract assertions, addressing only `empty` and `full`. -template -class abstract_stack { -public: - abstract_stack() { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - // AXIOM as empty() cannot actually be checked here to avoid - // calling pure virtual function length() during construction). - BOOST_CONTRACT_ASSERT_AXIOM(empty()); - }) - ; - } - - virtual ~abstract_stack() { - boost::contract::check c = boost::contract::destructor(this); - } - - bool full() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == (length() == capacity())); - }) - ; - - return result = (length() == capacity()); - } - - bool empty() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result = (length() == 0)); - }) - ; - - return result = (length() == 0); - } - - virtual int length(boost::contract::virtual_* v = 0) const = 0; - virtual int capacity(boost::contract::virtual_* v = 0) const = 0; - - virtual T const& item(boost::contract::virtual_* v = 0) const = 0; - - virtual void push(T const& value, boost::contract::virtual_* v = 0) = 0; - virtual T const& pop(boost::contract::virtual_* v = 0) = 0; - - virtual void clear(boost::contract::virtual_* v = 0) = 0; -}; - -template -int abstract_stack::length(boost::contract::virtual_* v) const { - int result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (int const& result) { - BOOST_CONTRACT_ASSERT(result >= 0); - }) - ; - assert(false); - return result; -} - -template -int abstract_stack::capacity(boost::contract::virtual_* v) const { - int result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (int const& result) { - BOOST_CONTRACT_ASSERT(result >= 0); - }) - ; - assert(false); - return result; -} - -template -T const& abstract_stack::item(boost::contract::virtual_* v) const { - boost::optional result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - assert(false); - return *result; -} - -template -void abstract_stack::push(T const& value, boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!full()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - assert(false); -} - -template -T const& abstract_stack::pop(boost::contract::virtual_* v) { - boost::optional result; - boost::contract::old_ptr old_item = BOOST_CONTRACT_OLDOF(v, item()); - boost::contract::check c = boost::contract::public_function(v, result, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - .postcondition([&] (boost::optional const& result) { - BOOST_CONTRACT_ASSERT(!full()); - BOOST_CONTRACT_ASSERT(*result == *old_item); - }) - ; - assert(false); - return *result; -} - -template -void abstract_stack::clear(boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - }) - ; - assert(false); -} - -template -class vstack - #define BASES private boost::contract::constructor_precondition< \ - vstack >, public abstract_stack - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - BOOST_CONTRACT_OVERRIDES(length, capacity, item, push, pop, clear) - - void invariant() const { - BOOST_CONTRACT_ASSERT(length() >= 0); - BOOST_CONTRACT_ASSERT(length() < capacity()); - } - -public: - explicit vstack(int count = 10) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(count >= 0); - }), - vect_(count), // OK, executed after precondition so count >= 0. - len_(0) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(length() == 0); - BOOST_CONTRACT_ASSERT(capacity() == count); - }) - ; - } - - virtual ~vstack() { - boost::contract::check c = boost::contract::destructor(this); - } - - // Inherited from abstract_stack. - - virtual int length(boost::contract::virtual_* v = 0) const /* override */ { - int result; - boost::contract::check c = boost::contract::public_function< - override_length>(v, result, &vstack::length, this); - return result = len_; - } - - virtual int capacity(boost::contract::virtual_* v = 0) - const /* override */ { - int result; - boost::contract::check c = boost::contract::public_function< - override_capacity>(v, result, &vstack::capacity, this); - return result = vect_.size(); - } - - virtual T const& item(boost::contract::virtual_* v = 0) - const /* override */ { - boost::optional result; - boost::contract::check c = boost::contract::public_function< - override_item>(v, result, &vstack::item, this); - return *(result = vect_[len_ - 1]); - } - - virtual void push(T const& value, boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::check c = boost::contract::public_function< - override_push>(v, &vstack::push, this, value); - vect_[len_++] = value; - } - - virtual T const& pop(boost::contract::virtual_* v = 0) /* override */ { - boost::optional result; - boost::contract::check c = boost::contract::public_function< - override_pop>(v, result, &vstack::pop, this); - return *(result = vect_[--len_]); - } - - virtual void clear(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_clear>(v, &vstack::clear, this); - len_ = 0; - } - -private: - vector vect_; - int len_; -}; - -int main() { - vstack s(3); - assert(s.capacity() == 3); - - s.push(123); - assert(s.length() == 1); - assert(s.pop() == 123); - - return 0; -} -//] - diff --git a/example/features/access.cpp b/example/features/access.cpp deleted file mode 100644 index 3f0f6040..00000000 --- a/example/features/access.cpp +++ /dev/null @@ -1,97 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -template -class pushable { -private: - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - -public: - virtual void push_back(T const& value, boost::contract::virtual_* v = 0) - = 0; - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template -void pushable::push_back(T const& value, boost::contract::virtual_* v) { - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - ; - assert(false); -} - -//[access -template -class vector - #define BASES public pushable - : BASES -{ -private: - friend class boost::contract::access; // Friend `access` class so... - - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // ...private bases. - #undef BASES - - BOOST_CONTRACT_OVERRIDE(push_back) // ...private overrides. - - void invariant() const { // ...private invariants. - BOOST_CONTRACT_ASSERT(size() <= capacity()); - } - -public: - void push_back(T const& value, boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function< - override_push_back>(v, &vector::push_back, this, value) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - ; - - vect_.push_back(value); - } - - /* ... */ -//] - - unsigned size() const { return vect_.size(); } - unsigned max_size() const { return vect_.max_size(); } - unsigned capacity() const { return vect_.capacity(); } - -private: - std::vector vect_; -}; - -int main() { - vector vect; - vect.push_back(123); - assert(vect.size() == 1); - return 0; -} - diff --git a/example/features/assertion_level.cpp b/example/features/assertion_level.cpp deleted file mode 100644 index 4c6a3b58..00000000 --- a/example/features/assertion_level.cpp +++ /dev/null @@ -1,135 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include - -//[assertion_level_no_impl -// If valid iterator range (cannot implement in C++ but OK to use in AXIOM). -template -bool valid(Iter first, Iter last); // Only declared, not actually defined. -//] - -//[assertion_level_class_begin -template -class vector { -//] - -public: - typedef typename std::vector::iterator iterator; - - // Could program class invariants and contracts for the following. - iterator begin() { return vect_.begin(); } - iterator end() { return vect_.end(); } - unsigned capacity() const { return vect_.capacity(); } - bool operator==(vector const& other) { return vect_ == other.vect_; } - -//[assertion_level_axiom -public: - iterator insert(iterator where, T const& value) { - iterator result; - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(capacity()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - if(capacity() > *old_capacity) { - BOOST_CONTRACT_ASSERT_AXIOM(!valid(begin(), end())); - } else { - BOOST_CONTRACT_ASSERT_AXIOM(!valid(where, end())); - } - }) - ; - - return result = vect_.insert(where, value); - } -//] - -//[assertion_level_audit_old -public: - void swap(vector& other) { - boost::contract::old_ptr old_me, old_other; - #ifdef BOOST_CONTRACT_AUDITS - old_me = BOOST_CONTRACT_OLDOF(*this); - old_other = BOOST_CONTRACT_OLDOF(other); - #endif // Else, skip old value copies... - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // ...and also skip related assertions. - BOOST_CONTRACT_ASSERT_AUDIT(*this == *old_other); - BOOST_CONTRACT_ASSERT_AUDIT(other == *old_me); - }) - ; - - vect_.swap(other.vect_); - } -//] - -//[assertion_level_class_end - /* ... */ - -private: - std::vector vect_; -}; -//] - -//[assertion_level_audit -template -RandomIter random_binary_search(RandomIter first, RandomIter last, - T const& value) { - RandomIter result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(first <= last); // Default, not expensive. - // Expensive O(n) assertion (use AXIOM if prohibitive instead). - BOOST_CONTRACT_ASSERT_AUDIT(std::is_sorted(first, last)); - }) - .postcondition([&] { - if(result != last) BOOST_CONTRACT_ASSERT(*result == value); - }) - ; - - /* ... */ -//] - - RandomIter begin = first, end = last; - while(begin < end) { - RandomIter middle = begin + ((end - begin) >> 1); - BOOST_CONTRACT_CHECK(*begin <= *middle || value < *middle || - *middle < value); - - if(value < *middle) end = middle; - else if(value > *middle) begin = middle + 1; - else return result = middle; - } - return result = last; -} - -int main() { - vector v; - v.insert(v.begin() + 0, 'a'); - v.insert(v.begin() + 1, 'b'); - v.insert(v.begin() + 2, 'c'); - - vector::iterator i = random_binary_search(v.begin(), v.end(), 'b'); - assert(i != v.end()); - assert(*i == 'b'); - - vector w; - w.insert(w.begin() + 0, 'x'); - w.insert(w.begin() + 1, 'y'); - - w.swap(v); - assert(*(w.begin() + 0) == 'a'); - assert(*(w.begin() + 1) == 'b'); - assert(*(w.begin() + 2) == 'c'); - - return 0; -} - diff --git a/example/features/base_types.cpp b/example/features/base_types.cpp deleted file mode 100644 index c3c9c0d5..00000000 --- a/example/features/base_types.cpp +++ /dev/null @@ -1,188 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -template -class pushable { -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - - virtual void push_back(T x, boost::contract::virtual_* v = 0) = 0; - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template -void pushable::push_back(T x, boost::contract::virtual_* v) { - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - ; - assert(false); // Shall never execute this body. -} - -struct has_size { virtual unsigned size() const = 0; }; -struct has_empty { virtual bool empty() const = 0; }; - -class unique_chars - : private boost::contract::constructor_precondition -{ -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(size() >= 0); - } - - unique_chars(char from, char to) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(from <= to); - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); - }) - ; - - for(char x = from; x <= to; ++x) vect_.push_back(x); - } - - virtual ~unique_chars() { - boost::contract::check c = boost::contract::destructor(this); - } - - unsigned size() const { - boost::contract::check c = boost::contract::public_function(this); - return vect_.size(); - } - - bool find(char x) const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(size() == 0) BOOST_CONTRACT_ASSERT(!result); - }) - ; - - return result = std::find(vect_.begin(), vect_.end(), x) != vect_.end(); - } - - virtual void push_back(char x, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!find(x)); - }) - .postcondition([&] { - if(!*old_find) { - BOOST_CONTRACT_ASSERT(find(x)); - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - } - }) - ; - - vect_.push_back(x); - } - -protected: - unique_chars() {} - - std::vector const& vect() const { return vect_; } - -private: - std::vector vect_; -}; - -//[base_types -class chars - #define BASES /* local macro (for convenience) */ \ - private boost::contract::constructor_precondition, \ - public unique_chars, \ - public virtual pushable, \ - virtual protected has_size, \ - private has_empty - : BASES // Bases of this class. -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Bases typedef. - #undef BASES // Undefine local macro. - - /* ... */ -//] - - void invariant() const { - BOOST_CONTRACT_ASSERT(empty() == (size() == 0)); - } - - chars(char from, char to) : unique_chars(from, to) { - boost::contract::check c = boost::contract::constructor(this); - } - - chars(char const* const c_str) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(c_str[0] != '\0'); - }) - { - boost::contract::check c = boost::contract::constructor(this); - - for(unsigned i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]); - } - - void push_back(char x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function< - override_push_back>(v, &chars::push_back, this, x) - .precondition([&] { - BOOST_CONTRACT_ASSERT(find(x)); - }) - .postcondition([&] { - if(*old_find) BOOST_CONTRACT_ASSERT(size() == *old_size); - }) - ; - - if(!find(x)) unique_chars::push_back(x); - } - BOOST_CONTRACT_OVERRIDE(push_back); - - bool empty() const { - boost::contract::check c = boost::contract::public_function(this); - return size() == 0; - } - - unsigned size() const { return unique_chars::size(); } - -protected: - unsigned max_size() const { return vect().max_size(); } - unsigned capacity() const { return vect().capacity(); } -}; - -int main() { - chars s("abc"); - assert(s.find('a')); - assert(s.find('b')); - assert(!s.find('x')); - return 0; -} - diff --git a/example/features/base_types_no_macro.cpp b/example/features/base_types_no_macro.cpp deleted file mode 100644 index 3dda7488..00000000 --- a/example/features/base_types_no_macro.cpp +++ /dev/null @@ -1,188 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -template -class pushable { -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - - virtual void push_back(T x, boost::contract::virtual_* v = 0) = 0; - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template -void pushable::push_back(T x, boost::contract::virtual_* v) { - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - ; - assert(false); // Shall never execute this body. -} - -struct has_size { virtual unsigned size() const = 0; }; -struct has_empty { virtual bool empty() const = 0; }; - -class unique_chars - : private boost::contract::constructor_precondition -{ -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(size() >= 0); - } - - unique_chars(char from, char to) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(from <= to); - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); - }) - ; - - for(char x = from; x <= to; ++x) vect_.push_back(x); - } - - virtual ~unique_chars() { - boost::contract::check c = boost::contract::destructor(this); - } - - unsigned size() const { - boost::contract::check c = boost::contract::public_function(this); - return vect_.size(); - } - - bool find(char x) const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(size() == 0) BOOST_CONTRACT_ASSERT(!result); - }) - ; - - return result = std::find(vect_.begin(), vect_.end(), x) != vect_.end(); - } - - virtual void push_back(char x, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!find(x)); - }) - .postcondition([&] { - if(!*old_find) { - BOOST_CONTRACT_ASSERT(find(x)); - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - } - }) - ; - - vect_.push_back(x); - } - -protected: - unique_chars() {} - - std::vector const& vect() const { return vect_; } - -private: - std::vector vect_; -}; - -//[base_types_no_macro -#include - -class chars : - private boost::contract::constructor_precondition, - public unique_chars, - public virtual pushable, - virtual protected has_size, - private has_empty -{ -public: - // Program `base_types` without macros (list only public bases). - typedef boost::mpl::vector > base_types; - - /* ... */ -//] - - void invariant() const { - BOOST_CONTRACT_ASSERT(empty() == (size() == 0)); - } - - chars(char from, char to) : unique_chars(from, to) { - boost::contract::check c = boost::contract::constructor(this); - } - - chars(char const* const c_str) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(c_str[0] != '\0'); - }) - { - boost::contract::check c = boost::contract::constructor(this); - - for(unsigned i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]); - } - - void push_back(char x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function< - override_push_back>(v, &chars::push_back, this, x) - .precondition([&] { - BOOST_CONTRACT_ASSERT(find(x)); - }) - .postcondition([&] { - if(*old_find) BOOST_CONTRACT_ASSERT(size() == *old_size); - }) - ; - - if(!find(x)) unique_chars::push_back(x); - } - BOOST_CONTRACT_OVERRIDE(push_back); - - bool empty() const { - boost::contract::check c = boost::contract::public_function(this); - return size() == 0; - } - - unsigned size() const { return unique_chars::size(); } - -protected: - unsigned max_size() const { return vect().max_size(); } - unsigned capacity() const { return vect().capacity(); } -}; - -int main() { - chars s("abc"); - assert(s.find('a')); - assert(s.find('b')); - assert(!s.find('x')); - return 0; -} - diff --git a/example/features/call_if_cxx14.cpp b/example/features/call_if_cxx14.cpp deleted file mode 100644 index 2e6c8c78..00000000 --- a/example/features/call_if_cxx14.cpp +++ /dev/null @@ -1,101 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#ifdef BOOST_NO_CXX14_GENERIC_LAMBDAS - -int main() { return 0; } // Trivial program. - -#else // This program requires C++14 generic lambdas. - -#include -#include -#include -#include // std::bind for generic lambdas. -#include -#include -#include - -template -struct is_random_access_iterator : std::is_same< - typename std::iterator_traits::iterator_category, - std::random_access_iterator_tag -> {}; - -template -struct is_bidirectional_iterator : std::is_same< - typename std::iterator_traits::iterator_category, - std::bidirectional_iterator_tag -> {}; - -template -struct is_input_iterator : std::is_same< - typename std::iterator_traits::iterator_category, - std::input_iterator_tag -> {}; - -//[call_if_cxx14 -template -void myadvance(Iter& i, Dist n) { - Iter* p = &i; // So captures change actual pointed iterator value. - boost::contract::call_if >( - std::bind([] (auto p, auto n) { // C++14 generic lambda. - *p += n; - }, p, n) - ).template else_if >( - std::bind([] (auto p, auto n) { - if(n >= 0) while(n--) ++*p; - else while(n++) --*p; - }, p, n) - ).template else_if >( - std::bind([] (auto p, auto n) { - while(n--) ++*p; - }, p, n) - ).else_( - std::bind([] (auto false_) { - static_assert(false_, "requires at least input iterator"); - }, std::false_type()) // Use constexpr value. - ); -} -//] - -struct x {}; // Test not an iterator (static_assert failure in else_ above). - -namespace std { - template<> - struct iterator_traits { - typedef void iterator_category; - }; -} - -int main() { - std::vector v; - v.push_back('a'); - v.push_back('b'); - v.push_back('c'); - v.push_back('d'); - std::vector::iterator r = v.begin(); // Random iterator. - myadvance(r, 1); - assert(*r == 'b'); - - std::list l(v.begin(), v.end()); - std::list::iterator b = l.begin(); // Bidirectional iterator. - myadvance(b, 2); - assert(*b == 'c'); - - std::istringstream s("a b c d"); - std::istream_iterator i(s); - myadvance(i, 3); - assert(*i == 'd'); - - // x j; - // myadvance(j, 0); // Error (correctly because x not even input iter). - - return 0; -} - -#endif // BOOST_NO_CXX14_GENERIC_LAMBDAS - diff --git a/example/features/check.cpp b/example/features/check.cpp deleted file mode 100644 index 24f891d5..00000000 --- a/example/features/check.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -int gcd(int const a, int const b) { - int result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(a > 0); - BOOST_CONTRACT_ASSERT(b > 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result <= a); - BOOST_CONTRACT_ASSERT(result <= b); - }) - ; - - int x = a, y = b; - while(x != y) { - if(x > y) x = x - y; - else y = y - x; - } - return result = x; -} - -int main() { - //[check_class - boost::contract::check c = [&] { // Implementation checks via functor. - BOOST_CONTRACT_ASSERT(gcd(12, 28) == 4); - BOOST_CONTRACT_ASSERT(gcd(4, 14) == 2); - }; - //] - - //[check_macro - // Implementation checks via macro (disable run- and compile-time overhead). - BOOST_CONTRACT_CHECK(gcd(12, 28) == 4); - BOOST_CONTRACT_CHECK(gcd(4, 14) == 2); - //] - - return 0; -} - diff --git a/example/features/code_block.cpp b/example/features/code_block.cpp deleted file mode 100644 index 7b6ffd5e..00000000 --- a/example/features/code_block.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -int main() { - std::vector v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - int total = 10; - - //[code_block - /* ... */ - // Contract for a code block. - { // Code block entry (check preconditions). - boost::contract::old_ptr old_total = BOOST_CONTRACT_OLDOF(total); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(v.size() == 3); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(total == *old_total + v[0] + v[1] + v[2]); - }) - ; - - total += v[0] + v[1] + v[2]; // Code block body. - } // Code block exit (check postconditions and exceptions guarantees). - /* ... */ - //] - - assert(total == 16); - return 0; -} - diff --git a/example/features/condition_if.cpp b/example/features/condition_if.cpp deleted file mode 100644 index 8fa92c76..00000000 --- a/example/features/condition_if.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include -#include - -//[condition_if -template -class vector { -public: - void push_back(T const& value) { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Instead of `ASSERT(back() == value)` for T without `==`. - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to(), - boost::cref(back()), - boost::cref(value) - ) - ) - ); - }) - ; - - vect_.push_back(value); - } - - /* ... */ -//] - - T const& back() const { return vect_.back(); } - -private: - std::vector vect_; -}; - -int main() { - vector v; - v.push_back(1); // Type `int` has `==` so check postcondition. - assert(v.back() == 1); - - struct i { int value; } j; - j.value = 10; - vector w; - w.push_back(j); // Type `i` has no `==` so skip postcondition. - assert(j.value == 10); - - return 0; -} - diff --git a/example/features/friend.cpp b/example/features/friend.cpp deleted file mode 100644 index b661c8ce..00000000 --- a/example/features/friend.cpp +++ /dev/null @@ -1,67 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[friend_byte -class bytes; - -class byte { - friend bool operator==(bytes const& left, byte const& right); - -private: - char value_; - - /* ... */ -//] - -public: - // Could program invariants and contracts for following too. - explicit byte(char value) : value_(value) {} - bool empty() const { return value_ == '\0'; } -}; - -//[friend_bytes -class bytes { - // Friend functions are not member functions... - friend bool operator==(bytes const& left, byte const& right) { - // ...so check contracts via `function` (which won't check invariants). - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(!left.empty()); - BOOST_CONTRACT_ASSERT(!right.empty()); - }) - ; - - for(char const* x = left.values_.c_str(); *x != '\0'; ++x) { - if(*x != right.value_) return false; - } - return true; - } - -private: - std::string values_; - - /* ... */ -//] - -public: - // Could program invariants and contracts for following too. - explicit bytes(std::string const& values) : values_(values) {} - bool empty() const { return values_ == ""; } -}; - -int main() { - bytes p("aaa"); - byte a('a'); - assert(p == a); - bytes q("aba"); - assert(!(q == a)); // No operator!=. - return 0; -} - diff --git a/example/features/friend_invariant.cpp b/example/features/friend_invariant.cpp deleted file mode 100644 index af142064..00000000 --- a/example/features/friend_invariant.cpp +++ /dev/null @@ -1,59 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -//[friend_invariant -template -class positive { -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(value() > 0); - } - - // Can be considered an extension of enclosing class' public interface... - friend void swap(positive& object, T& value) { - boost::contract::old_ptr old_object_value = - BOOST_CONTRACT_OLDOF(object.value()); - boost::contract::old_ptr old_value = BOOST_CONTRACT_OLDOF(value); - // ...so it can be made to check invariants via `public_function`. - boost::contract::check c = boost::contract::public_function(&object) - .precondition([&] { - BOOST_CONTRACT_ASSERT(value > 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(object.value() == *old_value); - BOOST_CONTRACT_ASSERT(value == *old_object_value); - }) - ; - - T saved = object.value_; - object.value_ = value; - value = saved; - } - -private: - T value_; - - /* ... */ -//] - -public: - // Could program contracts for following too. - explicit positive(T const& value) : value_(value) {} - T value() const { return value_; } -}; - -int main() { - positive i(123); - int x = 456; - swap(i, x); - assert(i.value() == 456); - assert(x == 123); - return 0; -} - diff --git a/example/features/ifdef.cpp b/example/features/ifdef.cpp deleted file mode 100644 index cc23ac7e..00000000 --- a/example/features/ifdef.cpp +++ /dev/null @@ -1,213 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[ifdef_function -// Use #ifdef to selectively disable contract compilation. -#include -#ifndef BOOST_CONTRACT_NO_ALL - #include -#endif - -int inc(int& x) { - int result; - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_FUNCTIONS - boost::contract::check c = boost::contract::function() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([&] { - BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); - }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .postcondition([&] { - BOOST_CONTRACT_ASSERT(x == *old_x + 1); - BOOST_CONTRACT_ASSERT(result == *old_x); - }) - #endif - ; - #endif - - return result = x++; -} -//] - -template -class pushable { - #ifndef BOOST_CONTRACT_NO_ALL - friend class boost::contract::access; - #endif - - #ifndef BOOST_CONTRACT_NO_INVARIANTS - void invariant() const { - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - #endif - -public: - virtual void push_back( - T const& x - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - , boost::contract::virtual_* v = 0 - #endif - ) = 0; - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template -void pushable::push_back( - T const& x - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - , boost::contract::virtual_* v - #endif -) { - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - #endif - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(v, this) - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - #endif - ; - #endif - assert(false); // Shall never execute this body. -} - -//[ifdef_class -class integers - #define BASES public pushable - : - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - private boost::contract::constructor_precondition, BASES - #else - BASES - #endif -{ - #ifndef BOOST_CONTRACT_NO_ALL - friend class boost::contract::access; - #endif - - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #endif - #undef BASES - - #ifndef BOOST_CONTRACT_NO_INVARIANTS - void invariant() const { - BOOST_CONTRACT_ASSERT(size() <= capacity()); - } - #endif - -public: - integers(int from, int to) : - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(from <= to); - }), - #endif - vect_(to - from + 1) - { - #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::check c = boost::contract::constructor(this) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .postcondition([&] { - BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); - }) - #endif - ; - #endif - - for(int x = from; x <= to; ++x) vect_.at(x - from) = x; - } - - virtual ~integers() { - #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - #endif - } - - virtual void push_back( - int const& x - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - , boost::contract::virtual_* v = 0 - #endif - ) /* override */ { - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr old_size; - #endif - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function< - override_push_back>(v, &integers::push_back, this, x) - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - .old([&] { - old_size = BOOST_CONTRACT_OLDOF(v, size()); - }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - .except([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size); - }) - #endif - ; - #endif - - vect_.push_back(x); - } - -private: - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - BOOST_CONTRACT_OVERRIDE(push_back) - #endif - - /* ... */ -//] - -public: // Could program contracts for these too... - unsigned size() const { return vect_.size(); } - unsigned max_size() const { return vect_.max_size(); } - unsigned capacity() const { return vect_.capacity(); } - -private: - std::vector vect_; -}; - -int main() { - integers i(1, 10); - int x = 123; - i.push_back(inc(x)); - assert(x == 124); - assert(i.size() == 11); - return 0; -} - diff --git a/example/features/ifdef_macro.cpp b/example/features/ifdef_macro.cpp deleted file mode 100644 index bc0bbf15..00000000 --- a/example/features/ifdef_macro.cpp +++ /dev/null @@ -1,149 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[ifdef_macro_function -// Use macro interface to completely disable contract overhead. -#include - -int inc(int& x) { - int result; - BOOST_CONTRACT_OLD_PTR(int)(old_x, x); - BOOST_CONTRACT_FUNCTION() - BOOST_CONTRACT_PRECONDITION([&] { - BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); - }) - BOOST_CONTRACT_POSTCONDITION([&] { - BOOST_CONTRACT_ASSERT(x == *old_x + 1); - BOOST_CONTRACT_ASSERT(result == *old_x); - }) - ; - - return result = x++; -} -//] - -template -class pushable { - friend class boost::contract::access; // Left in code (almost no overhead). - - BOOST_CONTRACT_INVARIANT({ - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - }) - -public: - virtual void push_back( - T const& x, - boost::contract::virtual_* v = 0 // Left in code (almost no overhead). - ) = 0; - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template -void pushable::push_back(T const& x, boost::contract::virtual_* v) { - BOOST_CONTRACT_OLD_PTR(unsigned)(v, old_capacity, capacity()); - BOOST_CONTRACT_PUBLIC_FUNCTION(v, this) - BOOST_CONTRACT_PRECONDITION([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - BOOST_CONTRACT_POSTCONDITION([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - ; - assert(false); // Shall never execute this body. -} - -//[ifdef_macro_class -class integers - #define BASES public pushable - : - // Left in code (almost no overhead). - private boost::contract::constructor_precondition, - BASES -{ - // Followings left in code (almost no overhead). - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - BOOST_CONTRACT_INVARIANT({ - BOOST_CONTRACT_ASSERT(size() <= capacity()); - }) - -public: - integers(int from, int to) : - BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(integers)([&] { - BOOST_CONTRACT_ASSERT(from <= to); - }), - vect_(to - from + 1) - { - BOOST_CONTRACT_CONSTRUCTOR(this) - BOOST_CONTRACT_POSTCONDITION([&] { - BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); - }) - ; - - for(int x = from; x <= to; ++x) vect_.at(x - from) = x; - } - - virtual ~integers() { - BOOST_CONTRACT_DESTRUCTOR(this); // Check invariants. - } - - virtual void push_back( - int const& x, - boost::contract::virtual_* v = 0 // Left in code (almost no overhead). - ) /* override */ { - BOOST_CONTRACT_OLD_PTR(unsigned)(old_size); - BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_push_back)( - v, &integers::push_back, this, x) - BOOST_CONTRACT_PRECONDITION([&] { - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - BOOST_CONTRACT_OLD([&] { - old_size = BOOST_CONTRACT_OLDOF(v, size()); - }) - BOOST_CONTRACT_POSTCONDITION([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - BOOST_CONTRACT_EXCEPT([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size); - }) - ; - - vect_.push_back(x); - } - -private: - BOOST_CONTRACT_OVERRIDE(push_back) // Left in code (almost no overhead). - - /* ... */ -//] - -public: // Could program contracts for these too... - unsigned size() const { return vect_.size(); } - unsigned max_size() const { return vect_.max_size(); } - unsigned capacity() const { return vect_.capacity(); } - -private: - std::vector vect_; -}; - -int main() { - integers i(1, 10); - int x = 123; - i.push_back(inc(x)); - assert(x == 124); - assert(i.size() == 11); - return 0; -} - diff --git a/example/features/introduction.cpp b/example/features/introduction.cpp deleted file mode 100644 index 6acb18c9..00000000 --- a/example/features/introduction.cpp +++ /dev/null @@ -1,34 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -//[introduction -#include - -void inc(int& x) { - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); // Old value. - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); // Line 17. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(x == *old_x + 1); // Line 20. - }) - ; - - ++x; // Function body. -} -//] - -int main() { - int x = 10; - inc(x); - assert(x == 11); - return 0; -} - diff --git a/example/features/introduction_comments.cpp b/example/features/introduction_comments.cpp deleted file mode 100644 index c27285b8..00000000 --- a/example/features/introduction_comments.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -//[introduction_comments -void inc(int& x) - // Precondition: x < std::numeric_limit::max() - // Postcondition: x == oldof(x) + 1 -{ - ++x; // Function body. -} -//] - -int main() { - int x = 10; - inc(x); - assert(x == 11); - return 0; -} - diff --git a/example/features/introduction_public.cpp b/example/features/introduction_public.cpp deleted file mode 100644 index e896c62e..00000000 --- a/example/features/introduction_public.cpp +++ /dev/null @@ -1,89 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -template -class pushable { // Somewhat arbitrary base (used just to show subcontracting). -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - - virtual void push_back(T const& value, - boost::contract::virtual_* v = 0) = 0; // Pure virtual function. - -protected: - virtual unsigned capacity() const = 0; - virtual unsigned max_size() const = 0; -}; - -template // Contract for pure virtual function. -void pushable::push_back(T const& value, boost::contract::virtual_* v) { - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(capacity() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - }) - ; - assert(false); // Shall never execute this body. -} - -//[introduction_public -template -class vector - #define BASES public pushable - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // For subcontracting. - #undef BASES - - void invariant() const { // Checked in AND with base class invariants. - BOOST_CONTRACT_ASSERT(size() <= capacity()); - } - - virtual void push_back(T const& value, - boost::contract::virtual_* v = 0) /* override */ { // Tag virtuals. - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); // Old values for virtuals. - boost::contract::check c = boost::contract::public_function< // For overrides. - override_push_back>(v, &vector::push_back, this, value) - .precondition([&] { // Checked in OR with base preconditions. - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - .postcondition([&] { // Checked in AND with base postconditions. - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - ; - - vect_.push_back(value); - } - BOOST_CONTRACT_OVERRIDE(push_back) // Define `override_push_back` above. - - // Could program contracts for those as well. - unsigned size() const { return vect_.size(); } - unsigned max_size() const { return vect_.max_size(); } - unsigned capacity() const { return vect_.capacity(); } - -private: - std::vector vect_; -}; -//] - -int main() { - vector vect; - vect.push_back(123); - assert(vect.size() == 1); - return 0; -} - diff --git a/example/features/lambda.cpp b/example/features/lambda.cpp deleted file mode 100644 index 189fe1f9..00000000 --- a/example/features/lambda.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -int main() { - std::vector v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - - //[lambda - int total = 0; - std::for_each(v.cbegin(), v.cend(), - [&total] (int const x) { - // Contract for a lambda function. - boost::contract::old_ptr old_total = - BOOST_CONTRACT_OLDOF(total); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT( - total + x <= std::numeric_limits::max()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(total == *old_total + x); - }) - ; - - total += x; // Lambda function body. - } - ); - //] - - assert(total == 6); - return 0; -} - diff --git a/example/features/loop.cpp b/example/features/loop.cpp deleted file mode 100644 index 631c597a..00000000 --- a/example/features/loop.cpp +++ /dev/null @@ -1,40 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -int main() { - std::vector v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - - //[loop - int total = 0; - for(std::vector::const_iterator i = v.begin(); i != v.end(); ++i) { - // Contract for a for-loop (same for while- and all other loops). - boost::contract::old_ptr old_total = BOOST_CONTRACT_OLDOF(total); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT( - total + *i <= std::numeric_limits::max()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(total == *old_total + *i); - }) - ; - - total += *i; // For-loop body. - } - //] - - assert(total == 6); - return 0; -} - diff --git a/example/features/move.cpp b/example/features/move.cpp deleted file mode 100644 index f0ad36e3..00000000 --- a/example/features/move.cpp +++ /dev/null @@ -1,201 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -//[move -class circular_buffer : - private boost::contract::constructor_precondition { -public: - void invariant() const { - if(!moved()) { // Do not check (some) invariants for moved-from objects. - BOOST_CONTRACT_ASSERT(index() < size()); - } - // More invariants here that hold also for moved-from objects (e.g., - // all assertions necessary to successfully destroy moved-from objects). - } - - // Move constructor. - /* implicit */ circular_buffer(circular_buffer&& other) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(!other.moved()); - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - BOOST_CONTRACT_ASSERT(other.moved()); - }) - ; - - move(std::forward(other)); - } - - // Move assignment. - circular_buffer& operator=(circular_buffer&& other) { - // Moved-from can be (move) assigned (so no pre `!moved()` here). - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!other.moved()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - BOOST_CONTRACT_ASSERT(other.moved()); - }) - ; - - return move(std::forward(other)); - } - - ~circular_buffer() { - // Moved-from can always be destroyed (in fact no preconditions). - boost::contract::check c = boost::contract::destructor(this); - } - - bool moved() const { - boost::contract::check c = boost::contract::public_function(this); - return moved_; - } - -private: - bool moved_; - - /* ... */ -//] - -public: - explicit circular_buffer(std::vector const& data, - unsigned start = 0) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(start < data.size()); - }), - moved_(false), - data_(data), - index_(start) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - }) - ; - } - - // Copy constructor. - /* implicit */ circular_buffer(circular_buffer const& other) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(!other.moved()); - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - }) - ; - - copy(other); - } - - // Copy assignment. - circular_buffer& operator=(circular_buffer const& other) { - // Moved-from can be (copy) assigned (so no pre `!moved()` here). - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!other.moved()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - }) - ; - - return copy(other); - } - - char read() { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!moved()); - }) - ; - - unsigned i = index_++; - if(index_ == data_.size()) index_ = 0; // Circular. - return data_.at(i); - } - -private: - circular_buffer& copy(circular_buffer const& other) { - data_ = other.data_; - index_ = other.index_; - moved_ = false; - return *this; - } - - circular_buffer& move(circular_buffer&& other) { - data_ = std::move(other.data_); - index_ = std::move(other.index_); - moved_ = false; - other.moved_ = true; // Mark moved-from object. - return *this; - } - - std::vector data_; - unsigned index_; - -public: - unsigned index() const { - boost::contract::check c = boost::contract::public_function(this); - return index_; - } - - unsigned size() const { - boost::contract::check c = boost::contract::public_function(this); - return data_.size(); - } -}; - -int main() { - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - { - circular_buffer x({'a', 'b', 'c', 'd'}, 2); - assert(x.read() == 'c'); - - circular_buffer y1 = x; // Copy constructor. - assert(y1.read() == 'd'); - assert(x.read() == 'd'); - - circular_buffer y2({'h'}); - y2 = x; // Copy assignment. - assert(y2.read() == 'a'); - assert(x.read() == 'a'); - - circular_buffer z1 = std::move(x); // Move constructor. - assert(z1.read() == 'b'); - // Calling `x.read()` would fail `!moved()` precondition. - - x = y1; // Moved-from `x` can be copy assigned. - assert(x.read() == 'a'); - assert(y1.read() == 'a'); - - circular_buffer z2({'k'}); - z2 = std::move(x); // Move assignment. - assert(z2.read() == 'b'); - // Calling `x.read()` would fail `!moved()` precondition. - - x = std::move(y2); // Moved-from `x` can be move assigned. - assert(x.read() == 'b'); - // Calling `y2.read()` would fail `!moved()` precondition. - - } // Moved-from `y2` can be destroyed. - - return 0; -} - diff --git a/example/features/named_override.cpp b/example/features/named_override.cpp deleted file mode 100644 index a847f363..00000000 --- a/example/features/named_override.cpp +++ /dev/null @@ -1,104 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[named_override_pure_virtual_assert_false -template -class generic_unary_pack { -public: - virtual void _1(T const& value, boost::contract::virtual_* v = 0) = 0; - virtual T _1(boost::contract::virtual_* v = 0) const = 0; -}; - -template -void generic_unary_pack::_1(T const& value, boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(false); // Defer preconditions to overrides. - }) - ; - assert(false); -} - -/* ... */ -//] - -template -T generic_unary_pack::_1(boost::contract::virtual_* v) const { - boost::optional result; // Do not assume T has default constructor. - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (boost::optional const& result) { - BOOST_CONTRACT_ASSERT(*result == _1()); - }) - ; - - assert(false); - return *result; -} - -//[named_override -template -class positive_unary_pack - #define BASES public generic_unary_pack - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // BOOST_CONTRACT_OVERRIDE(_1) would generate reserved name `override__1`. - BOOST_CONTRACT_NAMED_OVERRIDE(override1, _1) // Generate `override1`. - - virtual void _1(T const& value, boost::contract::virtual_* v = 0) - /* override */ { - // Use `override1` generated by BOOST_CONTRACT_NAMED_OVERRIDE above. - boost::contract::check c = boost::contract::public_function( - v, - static_cast(&positive_unary_pack::_1), - this, - value - ) - .precondition([&] { - BOOST_CONTRACT_ASSERT(value > 0); - }) - ; - value1_ = value; - } - - /* ... */ -//] - - virtual T _1(boost::contract::virtual_* v = 0) const /* override */ { - T result; // Class default constructor already used T's default ctor. - boost::contract::check c = boost::contract::public_function( - v, - result, - static_cast(&positive_unary_pack::_1), - this - ) - .postcondition([&] (T const& result) { - BOOST_CONTRACT_ASSERT(result > 0); - }) - ; - return result = value1_; - } - -private: - T value1_; -}; - -int main() { - positive_unary_pack u; - u._1(123); - assert(u._1() == 123); - return 0; -} - diff --git a/example/features/no_lambdas.cpp b/example/features/no_lambdas.cpp deleted file mode 100644 index 87eec3da..00000000 --- a/example/features/no_lambdas.cpp +++ /dev/null @@ -1,84 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "no_lambdas.hpp" -#include -#include - -//[no_lambdas_cpp -template -array::array(unsigned count) : - boost::contract::constructor_precondition(boost::bind( - &array::constructor_precondition, count)), - values_(new T[MaxSize]) // Member initializations can be here. -{ - boost::contract::old_ptr old_instances; - boost::contract::check c = boost::contract::constructor(this) - .old(boost::bind(&array::constructor_old, boost::ref(old_instances))) - .postcondition(boost::bind(&array::constructor_postcondition, this, - boost::cref(count), boost::cref(old_instances))) - ; - - for(unsigned i = 0; i < count; ++i) values_[i] = T(); - size_ = count; - ++instances_; -} - -template -array::~array() { - boost::contract::old_ptr old_instances; - boost::contract::check c = boost::contract::destructor(this) - .old(boost::bind(&array::destructor_old, this, - boost::ref(old_instances))) - .postcondition(boost::bind(&array::destructor_postcondition, - boost::cref(old_instances))) - ; - - delete[] values_; - --instances_; -} - -template -void array::push_back(T const& value, - boost::contract::virtual_* v) { - boost::contract::old_ptr old_size; - boost::contract::check c = boost::contract::public_function(v, this) - .precondition(boost::bind(&array::push_back_precondition, this)) - .old(boost::bind(&array::push_back_old, this, boost::cref(v), - boost::ref(old_size))) - .postcondition(boost::bind(&array::push_back_postcondition, this, - boost::cref(old_size))) - ; - - values_[size_++] = value; -} - -template -unsigned array::size() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return size_; -} - -template -int array::instances() { - // Check static invariants. - boost::contract::check c = boost::contract::public_function(); - return instances_; -} - -template -int array::instances_ = 0; -//] - -int main() { - array a(2); - assert(a.size() == 2); - a.push_back('x'); - assert(a.size() == 3); - return 0; -} - diff --git a/example/features/no_lambdas.hpp b/example/features/no_lambdas.hpp deleted file mode 100644 index 3c771824..00000000 --- a/example/features/no_lambdas.hpp +++ /dev/null @@ -1,74 +0,0 @@ - -#ifndef NO_LAMBDAS_HPP_ -#define NO_LAMBDAS_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -//[no_lambdas_hpp -template -class array : - private boost::contract::constructor_precondition > { -public: - static void static_invariant() { - BOOST_CONTRACT_ASSERT(instances() >= 0); - } - - void invariant() const { - BOOST_CONTRACT_ASSERT(size() <= MaxSize); - } - - explicit array(unsigned count); - static void constructor_precondition(unsigned const count) { - BOOST_CONTRACT_ASSERT(count <= MaxSize); - } - static void constructor_old(boost::contract::old_ptr& - old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(instances()); - } - void constructor_postcondition(unsigned const count, - boost::contract::old_ptr const old_instances) const { - BOOST_CONTRACT_ASSERT(size() == count); - BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); - } - - virtual ~array(); - void destructor_old(boost::contract::old_ptr& old_instances) - const { - old_instances = BOOST_CONTRACT_OLDOF(instances()); - } - static void destructor_postcondition(boost::contract::old_ptr const - old_instances) { - BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1); - } - - virtual void push_back(T const& value, boost::contract::virtual_* v = 0); - void push_back_precondition() const { - BOOST_CONTRACT_ASSERT(size() < MaxSize); - } - void push_back_old(boost::contract::virtual_* v, - boost::contract::old_ptr& old_size) const { - old_size = BOOST_CONTRACT_OLDOF(v, size()); - } - void push_back_postcondition( - boost::contract::old_ptr const old_size) const { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - } - - unsigned size() const; - - static int instances(); - -private: - T* values_; - unsigned size_; - static int instances_; -}; -//] - -#endif // #include guard - diff --git a/example/features/no_lambdas_local_func.cpp b/example/features/no_lambdas_local_func.cpp deleted file mode 100644 index 96a9bf81..00000000 --- a/example/features/no_lambdas_local_func.cpp +++ /dev/null @@ -1,113 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[no_lambdas_local_func -#include - -template -class array : - private boost::contract::constructor_precondition > { -public: - static void static_invariant() { - BOOST_CONTRACT_ASSERT(instances() >= 0); - } - - void invariant() const { - BOOST_CONTRACT_ASSERT(size() <= MaxSize); - } - - static void constructor_pre(unsigned const count) { - BOOST_CONTRACT_ASSERT(count <= MaxSize); - } - explicit array(unsigned count) : - boost::contract::constructor_precondition(boost::bind( - &array::constructor_pre, count)), - values_(new T[MaxSize]) - { - boost::contract::old_ptr old_instances; - void BOOST_LOCAL_FUNCTION_TPL(bind& old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(array::instances()); - } BOOST_LOCAL_FUNCTION_NAME_TPL(old) - void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& count, - const bind& old_instances) { - BOOST_CONTRACT_ASSERT(this_->size() == count); - BOOST_CONTRACT_ASSERT(this_->instances() == *old_instances + 1); - } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::check c = boost::contract::constructor(this) - .old(old).postcondition(post); - - for(unsigned i = 0; i < count; ++i) values_[i] = T(); - size_ = count; - ++instances_; - } - - virtual ~array() { - boost::contract::old_ptr old_instances; - void BOOST_LOCAL_FUNCTION_TPL(const bind this_, bind& old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(this_->instances()); - } BOOST_LOCAL_FUNCTION_NAME_TPL(old) - void BOOST_LOCAL_FUNCTION_TPL(const bind& old_instances) { - BOOST_CONTRACT_ASSERT(array::instances() == *old_instances - 1); - } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::check c = boost::contract::destructor(this) - .old(old).postcondition(post); - - delete[] values_; - --instances_; - } - - virtual void push_back(T const& value, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_size; - void BOOST_LOCAL_FUNCTION_TPL(const bind this_) { - BOOST_CONTRACT_ASSERT(this_->size() < MaxSize); - } BOOST_LOCAL_FUNCTION_NAME_TPL(pre) - void BOOST_LOCAL_FUNCTION_TPL(const bind v, const bind this_, - bind& old_size) { - old_size = BOOST_CONTRACT_OLDOF(v, this_->size()); - } BOOST_LOCAL_FUNCTION_NAME_TPL(old) - void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& old_size) { - BOOST_CONTRACT_ASSERT(this_->size() == *old_size + 1); - } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::check c = boost::contract::public_function(v, this) - .precondition(pre).old(old).postcondition(post); - - values_[size_++] = value; - } - - unsigned size() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return size_; - } - - static int instances() { - // Check static invariants. - boost::contract::check c = boost::contract::public_function(); - return instances_; - } - -private: - T* values_; - unsigned size_; - static int instances_; -}; - -template -int array::instances_ = 0; -//] - -int main() { - array a(2); - assert(a.size() == 2); - a.push_back('x'); - assert(a.size() == 3); - return 0; -} - diff --git a/example/features/non_member.cpp b/example/features/non_member.cpp deleted file mode 100644 index ff846dcf..00000000 --- a/example/features/non_member.cpp +++ /dev/null @@ -1,40 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -//[non_member -#include - -// Contract for a non-member function. -int inc(int& x) { - int result; - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(x == *old_x + 1); - BOOST_CONTRACT_ASSERT(result == *old_x); - }) - .except([&] { - BOOST_CONTRACT_ASSERT(x == *old_x); - }) - ; - - return result = x++; // Function body. -} -//] - -int main() { - int x = std::numeric_limits::max() - 1; - assert(inc(x) == std::numeric_limits::max() - 1); - assert(x == std::numeric_limits::max()); - return 0; -} - diff --git a/example/features/old.cpp b/example/features/old.cpp deleted file mode 100644 index 360ada73..00000000 --- a/example/features/old.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[old -char replace(std::string& s, unsigned index, char x) { - char result; - boost::contract::old_ptr old_y; // Null, old value copied later... - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(index < s.size()); - }) - .old([&] { // ...after preconditions (and invariants) checked. - old_y = BOOST_CONTRACT_OLDOF(s[index]); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(s[index] == x); - BOOST_CONTRACT_ASSERT(result == *old_y); - }) - ; - - result = s[index]; - s[index] = x; - return result; -} -//] - -int main() { - std::string s = "abc"; - char r = replace(s, 1, '_'); - assert(s == "a_c"); - assert(r == 'b'); - return 0; -} - diff --git a/example/features/old_if_copyable.cpp b/example/features/old_if_copyable.cpp deleted file mode 100644 index e6eb3fb7..00000000 --- a/example/features/old_if_copyable.cpp +++ /dev/null @@ -1,133 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -//[old_if_copyable_offset -template // T might or might not be copyable. -void offset(T& x, int count) { - // No compiler error if T has no copy constructor... - boost::contract::old_ptr_if_copyable old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::check c = boost::contract::function() - .postcondition([&] { - // ...but old value null if T has no copy constructor. - if(old_x) BOOST_CONTRACT_ASSERT(x == *old_x + count); - }) - ; - - x += count; -} -//] - -//[old_if_copyable_w_decl -// Copyable type but... -class w { -public: - w(w const&) { /* Some very expensive copy here operation here... */ } - - /* ... */ -//] - w() : num_(0) {} - int operator+(int i) const { return num_ + i; } - w& operator+=(int i) { num_ += i; return *this; } - bool operator==(int i) const { return long(num_) == i; } -private: - unsigned long num_; -}; - -//[old_if_copyable_w_spec -// ...never copy old values for type `w` (because its copy is too expensive). -namespace boost { namespace contract { - template<> - struct is_old_value_copyable : boost::false_type {}; -} } // namespace -//] - -//[old_if_copyable_p_decl -// Non-copyable type but... -class p : private boost::noncopyable { - int* num_; - - friend struct boost::contract::old_value_copy

; - - /* ... */ -//] -public: - p() : num_(new int(0)) {} - ~p() { delete num_; } - int operator+(int i) const { return *num_ + i; } - p& operator+=(int i) { *num_ += i; return *this; } - bool operator==(int i) const { return *num_ == i; } -}; - -//[old_if_copyable_p_spec -// ...still copy old values for type `p` (using a deep copy). -namespace boost { namespace contract { - template<> - struct old_value_copy

{ - explicit old_value_copy(p const& old) { - *old_.num_ = *old.num_; // Deep copy pointed value. - } - - p const& old() const { return old_; } - - private: - p old_; - }; - - template<> - struct is_old_value_copyable


-

© Copyright Lorenzo Caminiti, 2008-2016

-

Distributed under the Boost Software License, Version 1.0 (see - accompanying file LICENSE_1_0.txt or a copy at - www.boost.org/LICENSE_1_0.txt - )

- - diff --git a/src/contract.cpp b/src/contract.cpp deleted file mode 100644 index a1a1dc7b..00000000 --- a/src/contract.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#ifndef BOOST_CONTRACT_HEADER_ONLY // This is not an #include guard. - // For shared (default) and static lib only. - #define BOOST_CONTRACT_DETAIL_SOURCE - #include -#endif // Else (header-only), make sure nothing is compiled here. - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 deleted file mode 100644 index bf97e5d9..00000000 --- a/test/Jamfile.v2 +++ /dev/null @@ -1,347 +0,0 @@ - -# Copyright (C) 2008-2017 Lorenzo Caminiti -# Distributed under the Boost Software License, Version 1.0 (see accompanying -# file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -# See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -make help : : help_exit ; -explicit help ; - -test-suite constructor : - [ subdir-run constructor : smoke ] - - [ subdir-run constructor : decl_pre_all ] - [ subdir-run constructor : decl_pre_ends ] - [ subdir-run constructor : decl_pre_mid ] - [ subdir-run constructor : decl_pre_none ] - - [ subdir-run constructor : decl_post_all ] - [ subdir-run constructor : decl_post_ends ] - [ subdir-run constructor : decl_post_mid ] - [ subdir-run constructor : decl_post_none ] - - [ subdir-run constructor : decl_entry_static_inv_all ] - [ subdir-run constructor : decl_entry_static_inv_ends ] - [ subdir-run constructor : decl_entry_static_inv_mid ] - [ subdir-run constructor : decl_entry_static_inv_none ] - - [ subdir-run constructor : decl_exit_static_inv_all ] - [ subdir-run constructor : decl_exit_static_inv_ends ] - [ subdir-run constructor : decl_exit_static_inv_mid ] - [ subdir-run constructor : decl_exit_static_inv_none ] - - # No decl_entry_static_inv_... for constructors. - - [ subdir-run constructor : decl_exit_inv_all ] - [ subdir-run constructor : decl_exit_inv_ends ] - [ subdir-run constructor : decl_exit_inv_mid ] - [ subdir-run constructor : decl_exit_inv_none ] - - [ subdir-run constructor : access ] - - [ subdir-run constructor : ifdef ] - [ subdir-run constructor : ifdef_macro ] - - [ subdir-run constructor : throwing_pre ] - [ subdir-run constructor : throwing_old ] - [ subdir-run constructor : throwing_body ] - [ subdir-run constructor : throwing_post ] - # No throwing_except test (because throwing twice calls terminate). - - [ subdir-compile-fail constructor : pre_error ] -; - -test-suite destructor : - [ subdir-run destructor : smoke ] - - # No decl_pre_... for destructors. - - [ subdir-run destructor : decl_post_all ] - [ subdir-run destructor : decl_post_ends ] - [ subdir-run destructor : decl_post_mid ] - [ subdir-run destructor : decl_post_none ] - - [ subdir-run destructor : decl_entry_static_inv_all ] - [ subdir-run destructor : decl_entry_static_inv_ends ] - [ subdir-run destructor : decl_entry_static_inv_mid ] - [ subdir-run destructor : decl_entry_static_inv_none ] - - [ subdir-run destructor : decl_exit_static_inv_all ] - [ subdir-run destructor : decl_exit_static_inv_ends ] - [ subdir-run destructor : decl_exit_static_inv_mid ] - [ subdir-run destructor : decl_exit_static_inv_none ] - - [ subdir-run destructor : decl_entry_inv_all ] - [ subdir-run destructor : decl_entry_inv_ends ] - [ subdir-run destructor : decl_entry_inv_mid ] - [ subdir-run destructor : decl_entry_inv_none ] - - # No decl_exit_inv_... for destructors. - - [ subdir-run destructor : access ] - - [ subdir-run destructor : ifdef ] - [ subdir-run destructor : ifdef_macro ] - - # No throwing_pre test (because dtors have no preconditions). - [ subdir-run destructor : throwing_old ] - [ subdir-run destructor : throwing_body ] - [ subdir-run destructor : throwing_post ] - # No throwing_except test (because throwing twice calls terminate). - - [ subdir-compile-fail destructor : pre_error ] -; - -test-suite public_function : - [ subdir-run public_function : smoke ] - - [ subdir-run public_function : decl_pre_all ] - [ subdir-run public_function : decl_pre_ends ] - [ subdir-run public_function : decl_pre_mid ] - [ subdir-run public_function : decl_pre_none ] - - [ subdir-run public_function : decl_post_all ] - [ subdir-run public_function : decl_post_ends ] - [ subdir-run public_function : decl_post_mid ] - [ subdir-run public_function : decl_post_none ] - - [ subdir-run public_function : decl_entry_static_inv_all ] - [ subdir-run public_function : decl_entry_static_inv_ends ] - [ subdir-run public_function : decl_entry_static_inv_mid ] - [ subdir-run public_function : decl_entry_static_inv_none ] - - [ subdir-run public_function : decl_exit_static_inv_all ] - [ subdir-run public_function : decl_exit_static_inv_ends ] - [ subdir-run public_function : decl_exit_static_inv_mid ] - [ subdir-run public_function : decl_exit_static_inv_none ] - - [ subdir-run public_function : decl_entry_inv_all ] - [ subdir-run public_function : decl_entry_inv_ends ] - [ subdir-run public_function : decl_entry_inv_mid ] - [ subdir-run public_function : decl_entry_inv_none ] - - [ subdir-run public_function : decl_exit_inv_all ] - [ subdir-run public_function : decl_exit_inv_ends ] - [ subdir-run public_function : decl_exit_inv_mid ] - [ subdir-run public_function : decl_exit_inv_none ] - - [ subdir-run public_function : access ] - - [ subdir-run public_function : ifdef ] - [ subdir-run public_function : ifdef_macro ] - - [ subdir-run public_function : virtual ] - [ subdir-run public_function : virtual_branch ] - [ subdir-run public_function : virtual_sparse ] - [ subdir-run public_function : virtual_access ] - [ subdir-run public_function : virtual_access_multi ] - [ subdir-run public_function : old_virtual ] - - [ subdir-run public_function : protected ] - [ subdir-compile-fail public_function : protected_error ] - [ subdir-run public_function : friend ] - - [ subdir-run public_function : throwing_pre ] - [ subdir-run public_function : throwing_old ] - [ subdir-run public_function : throwing_body ] - [ subdir-run public_function : throwing_body_virtual ] - [ subdir-run public_function : throwing_body_virtual_branch ] - [ subdir-run public_function : throwing_post ] - # No throwing_except test (because throwing twice calls terminate). - - [ subdir-run public_function : max_args0 ] - [ subdir-run public_function : max_args0_no_tva ] - [ subdir-run public_function : max_args1 ] - [ subdir-run public_function : max_args1_no_tva ] - [ subdir-run public_function : max_args2 ] - [ subdir-run public_function : max_args2_no_tva ] - [ subdir-run public_function : max_args ] - [ subdir-run public_function : max_args_no_tva ] - - [ subdir-run public_function : max_bases ] - - [ subdir-run public_function : overload ] - [ subdir-run public_function : overload_no_tva ] - - [ subdir-compile-fail public_function : override_error ] - [ subdir-run public_function : override_permissive ] - - [ subdir-run public_function : static ] - - [ subdir-run public_function : static_ifdef ] - [ subdir-run public_function : static_ifdef_macro ] - - [ subdir-run public_function : static_throwing_pre ] - [ subdir-run public_function : static_throwing_old ] - [ subdir-run public_function : static_throwing_body ] - [ subdir-run public_function : static_throwing_post ] - # No throwing_except test (because throwing twice calls terminate). -; - -test-suite invariant : - [ subdir-run invariant : decl_static_cv_const ] - [ subdir-run invariant : decl_static_cv ] - [ subdir-run invariant : decl_cv_const ] - [ subdir-run invariant : decl_static_const ] - [ subdir-run invariant : decl_static ] - [ subdir-run invariant : decl_cv ] - [ subdir-run invariant : decl_const ] - [ subdir-run invariant : decl_nothing ] - - [ subdir-run invariant : ifdef ] - [ subdir-run invariant : ifdef_macro ] - - [ subdir-compile-fail invariant : static_mutable_error ] - [ subdir-run invariant : static_mutable_permissive ] - [ subdir-compile-fail invariant : static_const_error ] - [ subdir-run invariant : static_const_permissive ] - [ subdir-compile-fail invariant : static_volatile_error ] - [ subdir-run invariant : static_volatile_permissive ] - [ subdir-compile-fail invariant : static_cv_error ] - [ subdir-run invariant : static_cv_permissive ] - - [ subdir-compile-fail invariant : static_error ] - [ subdir-run invariant : static_permissive ] - [ subdir-compile-fail invariant : mutable_error ] - [ subdir-run invariant : mutable_permissive ] - [ subdir-compile-fail invariant : volatile_error ] - [ subdir-run invariant : volatile_permissive ] -; - -test-suite function : - [ subdir-run function : smoke ] - - [ subdir-run function : decl_pre_all ] - [ subdir-run function : decl_pre_none ] - - [ subdir-run function : decl_post_all ] - [ subdir-run function : decl_post_none ] - - [ subdir-run function : ifdef ] - [ subdir-run function : ifdef_macro ] - - [ subdir-run function : throwing_pre ] - [ subdir-run function : throwing_old ] - [ subdir-run function : throwing_body ] - [ subdir-run function : throwing_post ] - # No throwing_except test (because throwing twice calls terminate). -; - -test-suite check : - [ subdir-run check : decl_class ] - [ subdir-run check : decl_macro ] - - [ subdir-run check : ifdef ] - [ subdir-run check : ifdef_macro ] - - [ subdir-run check : audit ] - [ subdir-compile-fail check : audit_error ] - [ subdir-run check : audit_disabled ] - [ subdir-compile-fail check : audit_disabled_error ] - [ subdir-run check : axiom ] - [ subdir-compile-fail check : axiom_error ] -; - -test-suite result : - [ subdir-run result : mixed_optional ] - [ subdir-run result : mixed_optional_ref ] - - [ subdir-compile-fail result : type_mismatch_error ] -; - -test-suite old : - [ subdir-run old : auto ] - - [ subdir-run old : no_macro ] - [ subdir-run old : no_macro_if_copyable ] - - [ subdir-compile-fail old : no_make_old_error ] - [ subdir-compile-fail old : no_make_old_if_copyable_error ] - - [ subdir-run old : if_copyable ] - [ subdir-compile-fail old : if_copyable_error ] - [ subdir-run old : if_copyable_macro ] - - [ subdir-run old : copyable_traits ] -; - -test-suite disable : - [ subdir-run disable : pre_disable_no_assertion_prog ] - [ subdir-run disable : assertions_disable_assertions_prog ] - - [ subdir-lib disable : lib_a : - shared:BOOST_CONTRACT_TEST_LIB_A_DYN_LINK ] - [ subdir-lib disable : lib_b : disable-lib_a - shared:BOOST_CONTRACT_TEST_LIB_B_DYN_LINK ] - [ subdir-run disable : assertions_disable_assertions_lib : - disable-lib_a disable-lib_b ] - - [ subdir-lib disable : lib_x : - shared:BOOST_CONTRACT_TEST_LIB_X_DYN_LINK ] - [ subdir-lib disable : lib_y : disable-lib_x - shared:BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK ] - [ subdir-run disable : always_disable_post_except_lib : - disable-lib_x disable-lib_y ] - - [ subdir-run disable : audit ] - [ subdir-compile-fail disable : audit_error ] - [ subdir-run disable : audit_disabled ] - [ subdir-compile-fail disable : audit_disabled_error ] - [ subdir-run disable : axiom ] - [ subdir-compile-fail disable : axiom_error ] -; - -test-suite specify : - [ subdir-run specify : pre_old_post_except ] - - [ subdir-run specify : pre_old_post ] - [ subdir-run specify : pre_old_except ] - [ subdir-run specify : pre_post_except ] - [ subdir-run specify : old_post_except ] - - [ subdir-run specify : pre_old ] - [ subdir-run specify : pre_post ] - [ subdir-run specify : pre_except ] - [ subdir-run specify : old_post ] - [ subdir-run specify : old_except ] - [ subdir-run specify : post_except ] - - [ subdir-run specify : pre ] - [ subdir-run specify : old ] - [ subdir-run specify : post ] - [ subdir-run specify : except ] - - [ subdir-run specify : nothing ] - - [ subdir-compile-fail specify : except_post_error ] - [ subdir-compile-fail specify : except_old_error ] - [ subdir-compile-fail specify : except_pre_error ] - [ subdir-compile-fail specify : post_old_error ] - [ subdir-compile-fail specify : post_pre_error ] - [ subdir-compile-fail specify : old_pre_error ] - - [ subdir-run specify : missing_check ] - - [ subdir-compile-fail specify : auto_error ] - [ subdir-compile-fail specify : auto_pre_error ] - [ subdir-compile-fail specify : auto_pre_old_error ] - [ subdir-compile-fail specify : auto_pre_old_post_error ] - [ subdir-compile-fail specify : auto_pre_old_post_except_error ] -; - -test-suite call_if : - [ subdir-run call_if : true_ ] - [ subdir-run call_if : false_ ] - - [ subdir-run call_if : true_void ] - [ subdir-run call_if : false_void ] - - [ subdir-run call_if : equal_to ] - [ subdir-run call_if : equal_to_cxx14 : # Requires C++14. - clang:-std=c++1y ] - - [ subdir-run call_if : no_equal_condition_if ] - [ subdir-run call_if : no_equal_call_if ] - [ subdir-compile-fail call_if : no_equal_error ] -; - diff --git a/test/call_if/equal_to.cpp b/test/call_if/equal_to.cpp deleted file mode 100644 index 9c4d3edc..00000000 --- a/test/call_if/equal_to.cpp +++ /dev/null @@ -1,80 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test STL equal_to with call_if. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -template -struct void_equal_to { - typedef void result_type; // Test void result type. - - void operator()(T const& left, T const& right) const { - out << (left == right) << std::endl; - } -}; - -struct x {}; // Doest not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2;; - - out.str(""); - out << // Test on true condition with non-void result type. - boost::contract::call_if >( - boost::bind(std::equal_to(), 123, 123) // True. - ).else_( - // Compiler-error... but not called. - boost::bind(std::equal_to(), x1, x2) - ) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << // Test on false condition with non-void result type. - boost::contract::call_if >( - // Compiler-error... but not called. - boost::bind(std::equal_to(), x1, x2) - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - // Test on true condition void result type. - boost::contract::call_if >( - boost::bind(void_equal_to(), 123, 456) // False. - ).else_( - // Compiler-error... but not called. - boost::bind(void_equal_to(), x1, x1) - ); - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - // Test on false condition with void result type. - boost::contract::call_if >( - // Compiler-error... but not called. - boost::bind(void_equal_to(), x1, x1) - ).else_( - boost::bind(void_equal_to(), 123, 456) // False. - ); - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/call_if/equal_to_cxx14.cpp b/test/call_if/equal_to_cxx14.cpp deleted file mode 100644 index de9318c6..00000000 --- a/test/call_if/equal_to_cxx14.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test call_if equality check with C++14 generic lambdas. - -#include -#ifdef BOOST_NO_CXX14_GENERIC_LAMBDAS - -int main() { return 0; } // Test trivially always pass. - -#else // This test requires C++14 generic lambdas. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include // std::bind for generic lambdas. -#include - -boost::contract::test::detail::oteststream out; - -struct x {}; // Does not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2; - - out.str(""); - out << - boost::contract::call_if >( - std::bind([] (auto a, auto b) { return a == b; }, 123, 456) - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << - boost::contract::call_if >( - std::bind([] (auto a, auto b) { return a == b; }, x1, x2) - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << // Test explicit result, cannot deduce from lambda missing `-> bool`. - boost::contract::call_if >( - std::bind([] (auto a, auto b) { return a == b; }, x1, x2) - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - -#endif // BOOST_NO_CXX14_GENERIC_LAMBDAS - diff --git a/test/call_if/false_.cpp b/test/call_if/false_.cpp deleted file mode 100644 index 47b57448..00000000 --- a/test/call_if/false_.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test call_if with false condition and non-void result type. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct eq { - typedef bool result_type; // Test non-void result type. - - template - result_type operator()(L left, R right) const { - return left == right; // Requires operator==. - } -}; - -struct x {}; // Doest not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2;; - - out.str(""); - out << - boost::contract::call_if >( - boost::bind(eq(), x1, x1) // Compiler-error... but not called. - ).else_([] { return false; }) // Test else. - << std::endl; - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << - boost::contract::call_if >( - boost::bind(eq(), x1, x2) // Compiler-error... but not called. - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << // Test "..._c". - boost::contract::call_if_c::value>( - boost::bind(eq(), x1, x2) // Compiler-error...but not called. - ).else_([] { return true; }) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/call_if/false_void.cpp b/test/call_if/false_void.cpp deleted file mode 100644 index 286cb493..00000000 --- a/test/call_if/false_void.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test call_if with false condition and void result type. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct eq { - typedef void result_type; // Test void result type. - - template - result_type operator()(L left, R right) const { - out << (left == right) << std::endl; // Requires operator==. - } -}; - -struct x {}; // Doest not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2;; - - out.str(""); - boost::contract::call_if >( - boost::bind(eq(), x1, x2) // Compiler-error... but not called. - ); // Test no else. - ok.str(""); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - // Test "..._c". - boost::contract::call_if_c::value>( - boost::bind(eq(), x1, x2) // Compiler-error...but not called. - ).else_( - [] { out << true << std::endl; } // Test else. - ); - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/call_if/no_equal_call_if.cpp b/test/call_if/no_equal_call_if.cpp deleted file mode 100644 index 34b7eb99..00000000 --- a/test/call_if/no_equal_call_if.cpp +++ /dev/null @@ -1,64 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test assertions skipped when operations to check them missing (e.g., `==`). - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -unsigned equal_skips; - -template -void push_back(std::vector& vect, T const& value) { - boost::contract::check c = boost::contract::function() - .postcondition([&] { - BOOST_CONTRACT_ASSERT( - boost::contract::call_if >( - boost::bind(std::equal_to(), boost::cref(vect.back()), - boost::cref(value)) - ).else_([] { ++equal_skips; return true; }) - ); - }) - ; - vect.push_back(value); -} - -struct j { // Type without operator==. - explicit j(int i) : j_(i) {} -private: - int j_; -}; - -int main() { - std::vector vi; - equal_skips = 0; - push_back(vi, 123); - BOOST_TEST_EQ(equal_skips, 0); - - unsigned const cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 1 - #else - 0 - #endif - ; - - j jj(456); - std::vector vj; - equal_skips = 0; - push_back(vj, jj); - BOOST_TEST_EQ(equal_skips, cnt); - - return boost::report_errors(); -} - diff --git a/test/call_if/no_equal_condition_if.cpp b/test/call_if/no_equal_condition_if.cpp deleted file mode 100644 index 0bf58ee1..00000000 --- a/test/call_if/no_equal_condition_if.cpp +++ /dev/null @@ -1,65 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test assertions skipped when operations to check them missing (e.g., `==`). - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -unsigned equal_skips; - -template -void push_back(std::vector& vect, T const& value) { - boost::contract::check c = boost::contract::function() - .postcondition([&] { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to(), boost::cref(vect.back()), - boost::cref(value)) - ) - ); - if(!boost::has_equal_to::value) ++equal_skips; - }) - ; - vect.push_back(value); -} - -struct j { // Type without operator==. - explicit j(int i) : j_(i) {} -private: - int j_; -}; - -int main() { - std::vector vi; - equal_skips = 0; - push_back(vi, 123); - BOOST_TEST_EQ(equal_skips, 0u); - - unsigned const cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 1 - #else - 0 - #endif - ; - - j jj(456); - std::vector vj; - equal_skips = 0; - push_back(vj, jj); - BOOST_TEST_EQ(equal_skips, cnt); - - return boost::report_errors(); -} - diff --git a/test/call_if/no_equal_error.cpp b/test/call_if/no_equal_error.cpp deleted file mode 100644 index 33c2c44d..00000000 --- a/test/call_if/no_equal_error.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test assertion error when operations to check them missing (e.g., `==`). - -#include -#include -#include -#include - -template -void push_back(std::vector& vect, T const& value) { - boost::contract::check c = boost::contract::function() - .postcondition([&] { - BOOST_CONTRACT_ASSERT(vect.back() == value); // Error (j has no ==). - #ifdef BOOST_CONTRACT_NO_ALL - #error "force error if no contracts (ASSERT expands to nothing)" - #endif - }) - ; - vect.push_back(value); -} - -struct j { // Type without operator==. - explicit j(int i) : j_(i) {} -private: - int j_; -}; - -int main() { - std::vector vi; - push_back(vi, 123); - - j jj(456); - std::vector vj; - push_back(vj, jj); - - return 0; -} - diff --git a/test/call_if/true_.cpp b/test/call_if/true_.cpp deleted file mode 100644 index 60bf7aa3..00000000 --- a/test/call_if/true_.cpp +++ /dev/null @@ -1,64 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test call_if with true condition and non-void result type. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct eq { - typedef bool result_type; // Test non-void result type. - - template - result_type operator()(L left, R right) const { - return left == right; // Requires operator==. - } -}; - -struct x {}; // Doest not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2;; - - out.str(""); - out << - boost::contract::call_if >( - boost::bind(eq(), 123, 456) // False. - ) // Test no else (not called). - << std::endl; - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << - boost::contract::call_if >( - boost::bind(eq(), 123, 123) // True. - ).else_([] { return false; }) // Test else not called. - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - out << // Test "..._c". - boost::contract::call_if_c::value>( - boost::bind(eq(), 123, 123) // True. - ).else_( // Test else not called. - boost::bind(eq(), x1, x2) // Compiler-error... but not called. - ) - << std::endl; - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/call_if/true_void.cpp b/test/call_if/true_void.cpp deleted file mode 100644 index a8450e28..00000000 --- a/test/call_if/true_void.cpp +++ /dev/null @@ -1,61 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test call_if with true condition and void result type. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct eq { - typedef void result_type; // Test void result type. - - template - result_type operator()(L left, R right) const { - out << (left == right) << std::endl; // Requires operator==. - } -}; - -struct x {}; // Doest not have operator==. - -int main() { - std::ostringstream ok; - x x1, x2;; - - out.str(""); - boost::contract::call_if >( - boost::bind(eq(), 123, 456) // False. - ); // Test no else (not called). - ok.str(""); ok << false << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - boost::contract::call_if >( - boost::bind(eq(), 123, 123) // True. - ).else_( - [] { return false; } - ); // Test else (not called). - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - // Test "..._c". - boost::contract::call_if_c::value>( - boost::bind(eq(), 123, 123) // True. - ).else_( // Test else (not called). - boost::bind(eq(), x1, x2) // Compiler-error... but not called. - ); - ok.str(""); ok << true << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/check/audit.cpp b/test/check/audit.cpp deleted file mode 100644 index 4f8beb73..00000000 --- a/test/check/audit.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_AUDITS -#include "audit.hpp" - diff --git a/test/check/audit.hpp b/test/check/audit.hpp deleted file mode 100644 index 867b41b1..00000000 --- a/test/check/audit.hpp +++ /dev/null @@ -1,35 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -int main() { - struct err {}; - boost::contract::set_check_failure([] { throw err(); }); - - bool threw = false; - try { - #ifdef BOOST_CONTRACT_TEST_ERROR - BOOST_CONTRACT_CHECK_AUDIT( - BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); - #else - BOOST_CONTRACT_CHECK_AUDIT(false); - #endif - } catch(err const&) { threw = true; } - - #if defined(BOOST_CONTRACT_AUDITS) && !defined(BOOST_CONTRACT_NO_CHECKS) - BOOST_TEST(threw); - #else - BOOST_TEST(!threw); - #endif - - return boost::report_errors(); -} - diff --git a/test/check/audit_disabled.cpp b/test/check/audit_disabled.cpp deleted file mode 100644 index 75bc5d07..00000000 --- a/test/check/audit_disabled.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "audit.hpp" - diff --git a/test/check/audit_disabled_error.cpp b/test/check/audit_disabled_error.cpp deleted file mode 100644 index e90e2e97..00000000 --- a/test/check/audit_disabled_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "audit.hpp" - diff --git a/test/check/audit_error.cpp b/test/check/audit_error.cpp deleted file mode 100644 index e90e2e97..00000000 --- a/test/check/audit_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "audit.hpp" - diff --git a/test/check/axiom.cpp b/test/check/axiom.cpp deleted file mode 100644 index b26d6468..00000000 --- a/test/check/axiom.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "axiom.hpp" - diff --git a/test/check/axiom.hpp b/test/check/axiom.hpp deleted file mode 100644 index f561a28d..00000000 --- a/test/check/axiom.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -bool no_impl(); // Test func that cannot be impl in C++ sill OK in axioms. - -int main() { - #ifdef BOOST_CONTRACT_TEST_ERROR - BOOST_CONTRACT_CHECK_AXIOM( - BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); - #else - BOOST_CONTRACT_CHECK_AXIOM(false); // Test always false, OK. - BOOST_CONTRACT_CHECK_AXIOM(no_impl()); // Test no implementation, OK. - #endif - return 0; -} - diff --git a/test/check/axiom_error.cpp b/test/check/axiom_error.cpp deleted file mode 100644 index f3cf0b6a..00000000 --- a/test/check/axiom_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "axiom.hpp" - diff --git a/test/check/decl.hpp b/test/check/decl.hpp deleted file mode 100644 index 140abf2a..00000000 --- a/test/check/decl.hpp +++ /dev/null @@ -1,65 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test check (class and macro). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f(bool check) { - #ifdef BOOST_CONTRACT_TEST_CHECK_MACRO - BOOST_CONTRACT_CHECK([&] () -> bool { - out << "f::check" << std::endl; - return check; - }()); - #else - boost::contract::check c = [&] { - out << "f::check" << std::endl; - BOOST_CONTRACT_ASSERT(check); - }; - #endif - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(true); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_CHECKS - << "f::check" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_check_failure([] { throw err(); }); - - out.str(""); - try { - f(false); - #ifndef BOOST_CONTRACT_NO_CHECKS - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); - ok << "f::check" << std::endl; - #else - ok.str(""); - ok << "f::body" << std::endl; - #endif - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/check/decl_class.cpp b/test/check/decl_class.cpp deleted file mode 100644 index a20d13b1..00000000 --- a/test/check/decl_class.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test check class. - -#undef BOOST_CONTRACT_TEST_CHECK_MACRO -#include "decl.hpp" - diff --git a/test/check/decl_macro.cpp b/test/check/decl_macro.cpp deleted file mode 100644 index 654e9871..00000000 --- a/test/check/decl_macro.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test check macro. - -#define BOOST_CONTRACT_TEST_CHECK_MACRO -#include "decl.hpp" - diff --git a/test/check/ifdef.cpp b/test/check/ifdef.cpp deleted file mode 100644 index 408361b4..00000000 --- a/test/check/ifdef.cpp +++ /dev/null @@ -1,89 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#ifndef BOOST_CONTRACT_NO_CHECKS - #include - #include -#else - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -void f(bool check1, bool check2) { - BOOST_CONTRACT_CHECK([&] () -> bool { // Macro already so #ifdef needed. - out << "f::check1" << std::endl; - return check1; - }()); - #ifndef BOOST_CONTRACT_NO_CHECKS - boost::contract::check c = [&] { - out << "f::check2" << std::endl; - BOOST_CONTRACT_ASSERT(check2); - }; - #endif - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(true, true); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_CHECKS - << "f::check1" << std::endl - << "f::check2" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_check_failure([] { throw err(); }); - - out.str(""); - try { - f(false, true); - #ifndef BOOST_CONTRACT_NO_CHECKS - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); - ok << "f::check1" << std::endl; - #else - ok.str(""); - ok << "f::body" << std::endl; - #endif - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - out.str(""); - try { - f(true, false); - #ifndef BOOST_CONTRACT_NO_CHECKS - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); - ok << "f::check1" << std::endl; - ok << "f::check2" << std::endl; - #else - ok.str(""); - ok << "f::body" << std::endl; - #endif - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - // No need to test `f(false, false)` because same as `f(false, true)`. - - return boost::report_errors(); -} - diff --git a/test/check/ifdef_macro.cpp b/test/check/ifdef_macro.cpp deleted file mode 100644 index a842534e..00000000 --- a/test/check/ifdef_macro.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off (using macro interface only). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f(bool check) { - BOOST_CONTRACT_CHECK(( - [&] () -> bool { - typedef boost::contract::test::detail::unprotected_commas t; - out << "f::check" << std::endl; - return check; - }() - )); - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(true); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_CHECKS - << "f::check" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_check_failure([] { throw err(); }); - - out.str(""); - try { - f(false); - #ifndef BOOST_CONTRACT_NO_CHECKS - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); - ok << "f::check" << std::endl; - #else - ok.str(""); - ok << "f::body" << std::endl; - #endif - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/access.cpp b/test/constructor/access.cpp deleted file mode 100644 index 407f9c34..00000000 --- a/test/constructor/access.cpp +++ /dev/null @@ -1,136 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test making all contract extra declarations (base types, inv, etc.) private. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class b - #define BASES private boost::contract::constructor_precondition - : BASES -{ - friend class boost::contract::access; - - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - -public: - b() : boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } -}; - -class a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - friend class boost::contract::access; - - // Private base types (always OK because never used by ctors). - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // Private invariants. - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - -public: - a() : boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - b bb; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/constructor/decl.hpp b/test/constructor/decl.hpp deleted file mode 100644 index f6d24c66..00000000 --- a/test/constructor/decl.hpp +++ /dev/null @@ -1,170 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_ -#define BOOST_CONTRACT_TEST_CONSTRUCTOR_DECL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with and without pre, post, and inv declarations. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -bool c_pre = true, c_post = true; -bool c_entering_static_inv = true, c_entry_static_inv = true, - c_exit_static_inv = true; -bool c_exit_inv = true; // Only exit non-static inv for ctors. -struct c - #ifndef BOOST_CONTRACT_TEST_NO_C_PRE - : private boost::contract::constructor_precondition - #endif -{ - #ifndef BOOST_CONTRACT_TEST_NO_C_STATIC_INV - static void static_invariant() { - out << "c::static_inv" << std::endl; - if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); - else BOOST_CONTRACT_ASSERT(c_exit_static_inv); - c_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_C_INV - void invariant() const { - out << "c::inv" << std::endl; - BOOST_CONTRACT_ASSERT(c_exit_inv); - } - #endif - - c() - #ifndef BOOST_CONTRACT_TEST_NO_C_PRE - : boost::contract::constructor_precondition([] { - out << "c::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(c_pre); - }) - #endif - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "c::ctor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_C_POST - .postcondition([] { - out << "c::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(c_post); - }) - #endif - ; - out << "c::ctor::body" << std::endl; - } -}; - -bool b_pre = true, b_post = true; -bool b_entering_static_inv = true, b_entry_static_inv = true, - b_exit_static_inv = true; -bool b_exit_inv = true; // Only exit non-static inv for ctors. -struct b - #ifndef BOOST_CONTRACT_TEST_NO_B_PRE - #define BASES \ - private boost::contract::constructor_precondition, public c - #else - #define BASES public c - #endif - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_B_STATIC_INV - static void static_invariant() { - out << "b::static_inv" << std::endl; - if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); - else BOOST_CONTRACT_ASSERT(b_exit_static_inv); - b_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_B_INV - void invariant() const { - out << "b::inv" << std::endl; - BOOST_CONTRACT_ASSERT(b_exit_inv); - } - #endif - - b() - #ifndef BOOST_CONTRACT_TEST_NO_B_PRE - : boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(b_pre); - }) - #endif - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_B_POST - .postcondition([] { - out << "b::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(b_post); - }) - #endif - ; - out << "b::ctor::body" << std::endl; - } -}; - -bool a_pre = true, a_post = true; -bool a_entering_static_inv = true, a_entry_static_inv = true, - a_exit_static_inv = true; -bool a_exit_inv = true; // Only exit non-static inv for ctors. -struct a - #ifndef BOOST_CONTRACT_TEST_NO_A_PRE - #define BASES \ - private boost::contract::constructor_precondition, public b - #else - #define BASES public b - #endif - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_A_STATIC_INV - static void static_invariant() { - out << "a::static_inv" << std::endl; - if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); - else BOOST_CONTRACT_ASSERT(a_exit_static_inv); - a_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_A_INV - void invariant() const { - out << "a::inv" << std::endl; - BOOST_CONTRACT_ASSERT(a_exit_inv); - } - #endif - - a() - #ifndef BOOST_CONTRACT_TEST_NO_A_PRE - : boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(a_pre); - }) - #endif - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_A_POST - .postcondition([] { - out << "a::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(a_post); - }) - #endif - ; - out << "a::ctor::body" << std::endl; - } -}; - -#endif // #include guard - diff --git a/test/constructor/decl_entry_static_inv_all.cpp b/test/constructor/decl_entry_static_inv_all.cpp deleted file mode 100644 index 561ff067..00000000 --- a/test/constructor/decl_entry_static_inv_all.cpp +++ /dev/null @@ -1,218 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with entry static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // Might fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl // Might fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // Might fail. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test a::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/constructor/decl_entry_static_inv_ends.cpp b/test/constructor/decl_entry_static_inv_ends.cpp deleted file mode 100644 index cc2f71d0..00000000 --- a/test/constructor/decl_entry_static_inv_ends.cpp +++ /dev/null @@ -1,208 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with entry static inv. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // This might fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - // No b::static_inv to fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // This might fail. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test a::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/constructor/decl_entry_static_inv_mid.cpp b/test/constructor/decl_entry_static_inv_mid.cpp deleted file mode 100644 index 33bc98e0..00000000 --- a/test/constructor/decl_entry_static_inv_mid.cpp +++ /dev/null @@ -1,203 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - // No c::static_inv here. - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl // This might fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - // No a::static_inv here. - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test no a::static_inv so no failure. - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - std::cout << "---" << std::endl; - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::static_inv failed. - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - std::cout << "===" << std::endl; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() // Test no c::static_inv so no failure. - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/constructor/decl_entry_static_inv_none.cpp b/test/constructor/decl_entry_static_inv_none.cpp deleted file mode 100644 index dbc08086..00000000 --- a/test/constructor/decl_entry_static_inv_none.cpp +++ /dev/null @@ -1,124 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_inv_all.cpp b/test/constructor/decl_exit_inv_all.cpp deleted file mode 100644 index deb28bde..00000000 --- a/test/constructor/decl_exit_inv_all.cpp +++ /dev/null @@ -1,200 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with exit invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing fails. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test a::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test bb::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_inv_ends.cpp b/test/constructor/decl_exit_inv_ends.cpp deleted file mode 100644 index 1ca734dc..00000000 --- a/test/constructor/decl_exit_inv_ends.cpp +++ /dev/null @@ -1,194 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with exit invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - // No failure here. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test no failure. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test a::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() // Test no b::inv so no failure. - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_inv_mid.cpp b/test/constructor/decl_exit_inv_mid.cpp deleted file mode 100644 index b5efe4d4..00000000 --- a/test/constructor/decl_exit_inv_mid.cpp +++ /dev/null @@ -1,188 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle class with exit invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - // No failure here. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - // No failure here. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test no failure here. - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() // Test no failure here. - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_inv_none.cpp b/test/constructor/decl_exit_inv_none.cpp deleted file mode 100644 index 62ddd05f..00000000 --- a/test/constructor/decl_exit_inv_none.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and grandparent classes (ends) with exit invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_static_inv_all.cpp b/test/constructor/decl_exit_static_inv_all.cpp deleted file mode 100644 index d3478073..00000000 --- a/test/constructor/decl_exit_static_inv_all.cpp +++ /dev/null @@ -1,223 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test exit a::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test exit b::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test exit c::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test exit c::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_static_inv_ends.cpp b/test/constructor/decl_exit_static_inv_ends.cpp deleted file mode 100644 index aae0ffeb..00000000 --- a/test/constructor/decl_exit_static_inv_ends.cpp +++ /dev/null @@ -1,212 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and grandparent classes (ends) with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test a::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::static_inv failed (as all did). - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_b() - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_static_inv_mid.cpp b/test/constructor/decl_exit_static_inv_mid.cpp deleted file mode 100644 index 6989228b..00000000 --- a/test/constructor/decl_exit_static_inv_mid.cpp +++ /dev/null @@ -1,201 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - // No failure here. - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - // No failure here. - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing fails. - << ok_c() - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() // Test no a::static_inv so no failure. - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() // Test no c::static_inv so no failure. - << ok_b() - << ok_a() - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::static_inv failed. - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << ok_a() - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_exit_static_inv_none.cpp b/test/constructor/decl_exit_static_inv_none.cpp deleted file mode 100644 index f604a0f6..00000000 --- a/test/constructor/decl_exit_static_inv_none.cpp +++ /dev/null @@ -1,123 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_post_all.cpp b/test/constructor/decl_post_all.cpp deleted file mode 100644 index 4b2f51a4..00000000 --- a/test/constructor/decl_post_all.cpp +++ /dev/null @@ -1,185 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - { - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_b() - << ok_a() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - out.str(""); - try { - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() - << ok_a() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - out.str(""); - try { - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_b() // Test b::ctor::post failed. - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_a() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - out.str(""); - try { - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::ctor::post failed. - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_b() - << ok_a() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - out.str(""); - try { - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::ctor::post failed (as all did) - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_b() - << ok_a() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_post_ends.cpp b/test/constructor/decl_post_ends.cpp deleted file mode 100644 index 076c17ff..00000000 --- a/test/constructor/decl_post_ends.cpp +++ /dev/null @@ -1,167 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_c() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_ba() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - // No b::ctor::post here. - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_c() - << ok_ba() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() - << ok_ba() // Test a::ctor::post failed. - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - { - out.str(""); - a aa; - ok.str(""); ok - << ok_c() - << ok_ba() // Test no b::ctor::post so no failure. - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = true; - b_post = true; - c_post = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::ctor::post failed. - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_ba() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_c() // Test c::ctor::post failed (as all did). - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_ba() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_post_mid.cpp b/test/constructor/decl_post_mid.cpp deleted file mode 100644 index 1f94b16d..00000000 --- a/test/constructor/decl_post_mid.cpp +++ /dev/null @@ -1,159 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_cb() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - << ok_cb() - << ok_a() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - { - out.str(""); - a aa; - ok.str(""); ok - << ok_cb() - << ok_a() // Test no a::ctor::post so no failure. - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = true; - b_post = false; - c_post = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_cb() // Test b::ctor::post failed. - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_a() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - { - out.str(""); - a aa; - ok.str(""); ok - << ok_cb() // Test no c::ctor::post so no failure. - << ok_a() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = false; - b_post = false; - c_post = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_cb() // Test b::ctor::post failed (as all did). - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_a() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_post_none.cpp b/test/constructor/decl_post_none.cpp deleted file mode 100644 index a3f7c13f..00000000 --- a/test/constructor/decl_post_none.cpp +++ /dev/null @@ -1,109 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - - a_post = true; - b_post = true; - c_post = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = false; - b_post = true; - c_post = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = true; - b_post = false; - c_post = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = true; - b_post = true; - c_post = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_post = false; - b_post = false; - c_post = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_pre_all.cpp b/test/constructor/decl_pre_all.cpp deleted file mode 100644 index 09718411..00000000 --- a/test/constructor/decl_pre_all.cpp +++ /dev/null @@ -1,177 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with preconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_PRE -#undef BOOST_CONTRACT_TEST_NO_B_PRE -#undef BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_after() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_pre = true; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = false; - b_pre = true; - c_pre = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = true; - b_pre = false; - c_pre = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = true; - b_pre = true; - c_pre = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = false; - b_pre = false; - c_pre = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl // Test this failed (as all did). - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_pre_ends.cpp b/test/constructor/decl_pre_ends.cpp deleted file mode 100644 index d457059e..00000000 --- a/test/constructor/decl_pre_ends.cpp +++ /dev/null @@ -1,171 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with preconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_PRE -#define BOOST_CONTRACT_TEST_NO_B_PRE -#undef BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_after() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_pre = true; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = false; - b_pre = true; - c_pre = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = true; - b_pre = false; - c_pre = true; - { - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - // Test no failure here. - << "c::ctor::pre" << std::endl - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = true; - b_pre = true; - c_pre = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = false; - b_pre = false; - c_pre = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl // Test this failed (as all did). - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_pre_mid.cpp b/test/constructor/decl_pre_mid.cpp deleted file mode 100644 index dcad895b..00000000 --- a/test/constructor/decl_pre_mid.cpp +++ /dev/null @@ -1,163 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base classes with preconditions. - -#define BOOST_CONTRACT_TEST_NO_A_PRE -#undef BOOST_CONTRACT_TEST_NO_B_PRE -#define BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_after() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_pre = true; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = false; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl // Test no failure here. - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = true; - b_pre = false; - c_pre = true; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl // Test this failed. - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - - a_pre = true; - b_pre = true; - c_pre = false; - { - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl // Test no failure here. - #endif - << ok_after() - ; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = false; - b_pre = false; - c_pre = false; - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl // Test this failed (as all did). - #else - << ok_after() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/decl_pre_none.cpp b/test/constructor/decl_pre_none.cpp deleted file mode 100644 index c45d7dc1..00000000 --- a/test/constructor/decl_pre_none.cpp +++ /dev/null @@ -1,114 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without preconditions. - -#define BOOST_CONTRACT_TEST_NO_A_PRE -#define BOOST_CONTRACT_TEST_NO_B_PRE -#define BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok - // Test no preconditions here. - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - - a_pre = true; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = false; - b_pre = true; - c_pre = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = true; - b_pre = false; - c_pre = true; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = true; - b_pre = true; - c_pre = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - a_pre = false; - b_pre = false; - c_pre = false; - { - out.str(""); - a aa; - BOOST_TEST(out.eq(ok.str())); - } - - return boost::report_errors(); -} - diff --git a/test/constructor/ifdef.cpp b/test/constructor/ifdef.cpp deleted file mode 100644 index 508e1c80..00000000 --- a/test/constructor/ifdef.cpp +++ /dev/null @@ -1,133 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) - #include -#endif -#ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - : private boost::contract::constructor_precondition - #endif -{ - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - #endif - - explicit b(int x) - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - : boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) - #endif - { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::check c = boost::contract::constructor(this) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - #endif - ; - #endif - out << "b::ctor::body" << std::endl; - } -}; - -struct a : - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - private boost::contract::constructor_precondition, - #endif - public b -{ - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - #endif - - explicit a(int x) : - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }), - #endif - b(x) - { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::check c = boost::contract::constructor(this) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - #endif - ; - #endif - out << "a::ctor::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - out.str(""); - a aa(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - return boost::report_errors(); -} - diff --git a/test/constructor/ifdef_macro.cpp b/test/constructor/ifdef_macro.cpp deleted file mode 100644 index ce577516..00000000 --- a/test/constructor/ifdef_macro.cpp +++ /dev/null @@ -1,157 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off (using macro interface). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include // Outside #if below for ctor pre. -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b : - private boost::contract::constructor_precondition // OK, always in code. -{ - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::inv" << std::endl; - }) - - explicit b(int x) : - BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(b)([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "b::ctor::pre" << std::endl; - }) - { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas::type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_CONSTRUCTOR(this) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "b::f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "b::ctor::post" << std::endl; - }) - ; - out << "b::ctor::body" << std::endl; - } -}; - -struct a: - private boost::contract::constructor_precondition, // OK, always in code. - public b -{ - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::inv" << std::endl; - }) - - explicit a(int x) : - BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(a)([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::ctor::pre" << std::endl; } - ), - b(x) - { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas::type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_CONSTRUCTOR(boost::contract::test::detail:: - unprotected_commas::same(this)) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::ctor::post" << std::endl; - }) - ; - out << "a::ctor::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - out.str(""); - a aa(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - return boost::report_errors(); -} - diff --git a/test/constructor/pre_error.cpp b/test/constructor/pre_error.cpp deleted file mode 100644 index 4bbbac10..00000000 --- a/test/constructor/pre_error.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test constructor cannot use `.precondition(...)`. - -#include -#include - -struct a { - a() { - boost::contract::check c = boost::contract::constructor(this) - .precondition([] {}) // Error (must use constructor_precondition). - ; - } -}; - -int main() { - a aa; - return 0; -} - diff --git a/test/constructor/smoke.cpp b/test/constructor/smoke.cpp deleted file mode 100644 index dc5d3a08..00000000 --- a/test/constructor/smoke.cpp +++ /dev/null @@ -1,410 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test constructor subcontracting. - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -template -struct t - #define BASES private boost::contract::constructor_precondition > - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - out << Id << "::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(l.value >= 0); - } - - void invariant() const { - out << Id << "::inv" << std::endl; - BOOST_CONTRACT_ASSERT(k_ < 0); - } - - struct l_tag; - typedef boost::contract::test::detail::counter l_type; - static l_type l; - - struct z_tag; - typedef boost::contract::test::detail::counter z_type; - - explicit t(z_type& z) : - boost::contract::constructor_precondition >([&] { - out << Id << "::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(z.value < 0); - }) - { - boost::contract::old_ptr old_z; - boost::contract::old_ptr old_l = - BOOST_CONTRACT_OLDOF(l_type::eval(l)); - boost::contract::check c = boost::contract::constructor(this) - .old([&] { - out << Id << "::ctor::old" << std::endl; - old_z = BOOST_CONTRACT_OLDOF(z_type::eval(z)); - }) - .postcondition([&] { - out << Id << "::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(k_ == old_z->value); - BOOST_CONTRACT_ASSERT(z.value == l.value); - BOOST_CONTRACT_ASSERT(l.value == old_l->value + 1); - }) - ; - out << Id << "::ctor::body" << std::endl; - k_ = z.value; - z.value = ++l.value; - } - - virtual ~t() { --l.value; } - -private: - int k_; -}; -template typename t::l_type t::l; - -// Test deep inheritance (2 vertical levels), multiple inheritance (4 -// horizontal levels), and that all public/protected/private part of -// subcontracting for constructors (not just public, because all access levels -// are part of C++ object construction mechanism). -struct c - #define BASES private boost::contract::constructor_precondition, \ - public t<'d'>, protected t<'p'>, private t<'q'>, public t<'e'> - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - out << "c::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(m.value >= 0); - } - - void invariant() const { - out << "c::inv" << std::endl; - BOOST_CONTRACT_ASSERT(j_ < 0); - } - - struct m_tag; - typedef boost::contract::test::detail::counter m_type; - static m_type m; - - struct y_tag; - typedef boost::contract::test::detail::counter y_type; - - explicit c(y_type& y, t<'d'>::z_type& dz, t<'p'>::z_type& pz, - t<'q'>::z_type& qz, t<'e'>::z_type& ez) : - boost::contract::constructor_precondition([&] { - out << "c::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(y.value < 0); - }), - t<'d'>(dz), t<'p'>(pz), t<'q'>(qz), t<'e'>(ez) - { - boost::contract::old_ptr old_y = - BOOST_CONTRACT_OLDOF(y_type::eval(y)); - boost::contract::old_ptr old_m; - boost::contract::check c = boost::contract::constructor(this) - .old([&] { - out << "c::ctor::old" << std::endl; - old_m = BOOST_CONTRACT_OLDOF(m_type::eval(m)); - }) - .postcondition([&] { - out << "c::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(j_ == old_y->value); - BOOST_CONTRACT_ASSERT(y.value == m.value); - BOOST_CONTRACT_ASSERT(m.value == old_m->value + 1); - }) - ; - out << "c::ctor::body" << std::endl; - j_ = y.value; - y.value = ++m.value; - } - - virtual ~c() { --m.value; } - -private: - int j_; -}; -c::m_type c::m; - -// Test not (fully) contracted base is not part of constructor subcontracting. -struct b - #define BASES private boost::contract::constructor_precondition - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - explicit b() {} // No contract. - virtual ~b() {} -}; - -// Test constructor with both non-contracted and contracted bases. -struct a - #define BASES private boost::contract::constructor_precondition, \ - public b, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - out << "a::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(n.value >= 0); - } - - void invariant() const { - out << "a::inv" << std::endl; - BOOST_CONTRACT_ASSERT(i_ < 0); - } - - struct n_tag; - typedef boost::contract::test::detail::counter n_type; - static n_type n; - - struct x_tag; - typedef boost::contract::test::detail::counter x_type; - - explicit a(x_type& x, c::y_type& y, t<'d'>::z_type& dz, - t<'p'>::z_type& pz, t<'q'>::z_type& qz, t<'e'>::z_type& ez) : - boost::contract::constructor_precondition([&] { - out << "a::ctor::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x.value < 0); - }), - b(), c(y, dz, pz, qz, ez) - { - boost::contract::old_ptr old_x; - boost::contract::old_ptr old_n = - BOOST_CONTRACT_OLDOF(n_type::eval(n)); - boost::contract::check c = boost::contract::constructor(this) - .old([&] { - out << "a::ctor::old" << std::endl; - old_x = BOOST_CONTRACT_OLDOF(x_type::eval(x)); - }) - .postcondition([&] { - out << "a::ctor::post" << std::endl; - BOOST_CONTRACT_ASSERT(i_ == old_x->value); - BOOST_CONTRACT_ASSERT(x.value == n.value); - BOOST_CONTRACT_ASSERT(n.value == old_n->value + 1); - }) - ; - out << "a::ctor::body" << std::endl; - i_ = x.value; - x.value = ++n.value; - } - - virtual ~a() { --n.value; } - -private: - int i_; -}; -a::n_type a::n; - -int main() { - std::ostringstream ok; - - { - t<'e'>::z_type ez; ez.value = -5; - t<'q'>::z_type qz; qz.value = -5; - t<'p'>::z_type pz; pz.value = -4; - t<'d'>::z_type dz; dz.value = -3; - c::y_type y; y.value = -2; - a::x_type x; x.value = -1; - - out.str(""); - a aa(x, y, dz, pz, qz, ez); - ok.str(""); ok - // Test all constructor pre checked first. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - // Test static inv, but not const inv, checked before ctor body. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::ctor::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::ctor::old" << std::endl - #endif - << "d::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::ctor::post" << std::endl - #endif - - // Test check also protected bases (because part of C++ constr.). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "p::ctor::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "p::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "p::ctor::old" << std::endl - #endif - << "p::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "p::static_inv" << std::endl - << "p::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "p::ctor::post" << std::endl - #endif - - // Test check also private bases (because part of C++ constr.). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "q::ctor::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "q::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "q::ctor::old" << std::endl - #endif - << "q::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "q::static_inv" << std::endl - << "q::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "q::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "e::ctor::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "e::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "e::ctor::old" << std::endl - #endif - << "e::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "e::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - std::clog << a::x_type::copies() << std::endl; - std::clog << BOOST_CONTRACT_TEST_old << std::endl; - BOOST_TEST_EQ(a::x_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::x_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); // No leak. - - BOOST_TEST_EQ(c::y_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::y_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::y_type::ctors(), c::y_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'d'>::z_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'d'>::z_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'d'>::z_type::ctors(), t<'d'>::z_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'p'>::z_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'p'>::z_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'p'>::z_type::ctors(), t<'p'>::z_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'q'>::z_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'q'>::z_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'q'>::z_type::ctors(), t<'q'>::z_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'e'>::z_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::z_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::z_type::ctors(), t<'e'>::z_type::dtors()); // No leak. - - // Following destroy only copies (actual objects are static data members). - - BOOST_TEST_EQ(a::n_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::n_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. - - BOOST_TEST_EQ(c::m_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::m_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'d'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'d'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'p'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'p'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'q'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'q'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'e'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/constructor/throwing_body.cpp b/test/constructor/throwing_body.cpp deleted file mode 100644 index 5e9195ca..00000000 --- a/test/constructor/throwing_body.cpp +++ /dev/null @@ -1,145 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw form constructor body (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c - #define BASES private boost::contract::constructor_precondition - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - c() : - boost::contract::constructor_precondition([] { - out << "c::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "c::ctor::old" << std::endl; }) - .postcondition([] { out << "c::ctor::post" << std::endl; }) - .except([] { out << "c::ctor::except" << std::endl; }) - ; - out << "c::ctor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES private boost::contract::constructor_precondition, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - b() : - boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - .except([] { out << "b::ctor::except" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - throw b::err(); // Test body throws (from inheritance mid branch). - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - a() : - boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - .except([] { out << "a::ctor::except" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - try { - out.str(""); - a aa; - BOOST_TEST(false); - } catch(b::err const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl // Test this threw... - // ... so check only following after (no post, no a ctor, etc.). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "b::ctor::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/throwing_old.cpp b/test/constructor/throwing_old.cpp deleted file mode 100644 index f29405d2..00000000 --- a/test/constructor/throwing_old.cpp +++ /dev/null @@ -1,158 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw form constructor .old() (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c - #define BASES private boost::contract::constructor_precondition - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - c() : - boost::contract::constructor_precondition([] { - out << "c::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "c::ctor::old" << std::endl; }) - .postcondition([] { out << "c::ctor::post" << std::endl; }) - .except([] { out << "c::ctor::except" << std::endl; }) - ; - out << "c::ctor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES private boost::contract::constructor_precondition, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - b() : - boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { - out << "b::ctor::old" << std::endl; - throw b::err(); // Test this throws (from mid branch). - }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - .except([] { out << "b::ctor::except" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - a() : - boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - .except([] { out << "a::ctor::except" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(false); - } catch(b::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl // Test this threw. - #else - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/throwing_post.cpp b/test/constructor/throwing_post.cpp deleted file mode 100644 index 75f018d7..00000000 --- a/test/constructor/throwing_post.cpp +++ /dev/null @@ -1,164 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw form constructor .post() (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c - #define BASES private boost::contract::constructor_precondition - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - c() : - boost::contract::constructor_precondition([] { - out << "c::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "c::ctor::old" << std::endl; }) - .postcondition([] { out << "c::ctor::post" << std::endl; }) - .except([] { out << "c::ctor::except" << std::endl; }) - ; - out << "c::ctor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES private boost::contract::constructor_precondition, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - b() : - boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { - out << "b::ctor::post" << std::endl; - throw b::err(); // Test this throws (from mid branch). - }) - .except([] { out << "b::ctor::except" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - a() : - boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - .except([] { out << "a::ctor::except" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - a aa; - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(b::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - << "c::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl // Test this threw. - #else - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/constructor/throwing_pre.cpp b/test/constructor/throwing_pre.cpp deleted file mode 100644 index e7559f7c..00000000 --- a/test/constructor/throwing_pre.cpp +++ /dev/null @@ -1,164 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw form constructor .pre() (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c - #define BASES private boost::contract::constructor_precondition - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - c() : - boost::contract::constructor_precondition([] { - out << "c::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "c::ctor::old" << std::endl; }) - .postcondition([] { out << "c::ctor::post" << std::endl; }) - .except([] { out << "c::ctor::except" << std::endl; }) - ; - out << "c::ctor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES private boost::contract::constructor_precondition, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - b() : - boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - throw b::err(); // Test this throws (from mid branch). - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - .except([] { out << "b::ctor::except" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - a() : - boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) - { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - .except([] { out << "a::ctor::except" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - a aa; -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(b::err const&) { -#endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl // Test this threw. - #else - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::ctor::old" << std::endl - #endif - << "c::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/destructor/access.cpp b/test/destructor/access.cpp deleted file mode 100644 index 98f23047..00000000 --- a/test/destructor/access.cpp +++ /dev/null @@ -1,122 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test making all contract extra declarations (base types, inv, etc.) private. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class b { - friend class boost::contract::access; - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - -public: - virtual ~b() { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } -}; - -class a - #define BASES public b - : BASES -{ - friend class boost::contract::access; - - // Private base types (always OK because never used by dtors). - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // Private invariants. - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - -public: - virtual ~a() { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - { - a aa; - out.str(""); - } // Call aa's destructor. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - { - b bb; - out.str(""); - } // Call bb's destructor. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/destructor/decl.hpp b/test/destructor/decl.hpp deleted file mode 100644 index bdc12e3b..00000000 --- a/test/destructor/decl.hpp +++ /dev/null @@ -1,145 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_DESTRUCTOR_DECL_HPP_ -#define BOOST_CONTRACT_TEST_DESTRUCTOR_DECL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with and without pre, post, and inv declarations. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -bool c_pre = true, c_post = true; -bool c_entering_static_inv = true, c_entry_static_inv = true, - c_exit_static_inv = true; -bool c_entry_inv = true; // Only entry non-static inv for dtors. -struct c { - #ifndef BOOST_CONTRACT_TEST_NO_C_STATIC_INV - static void static_invariant() { - out << "c::static_inv" << std::endl; - if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); - else BOOST_CONTRACT_ASSERT(c_exit_static_inv); - c_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_C_INV - void invariant() const { - out << "c::inv" << std::endl; - BOOST_CONTRACT_ASSERT(c_entry_inv); - } - #endif - - virtual ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - #ifdef BOOST_CONTRACT_TEST_NO_C_PRE - #error "destructors cannot have preconditions" - #endif - .old([] { out << "c::dtor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_C_POST - .postcondition([] { - out << "c::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(c_post); - }) - #endif - ; - out << "c::dtor::body" << std::endl; - } -}; - -bool b_pre = true, b_post = true; -bool b_entering_static_inv = true, b_entry_static_inv = true, - b_exit_static_inv = true; -bool b_entry_inv = true; // Only entry non-static inv for dtors. -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_B_STATIC_INV - static void static_invariant() { - out << "b::static_inv" << std::endl; - if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); - else BOOST_CONTRACT_ASSERT(b_exit_static_inv); - b_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_B_INV - void invariant() const { - out << "b::inv" << std::endl; - BOOST_CONTRACT_ASSERT(b_entry_inv); - } - #endif - - virtual ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - #ifdef BOOST_CONTRACT_TEST_NO_B_PRE - #error "destructors cannot have preconditions" - #endif - .old([] { out << "b::dtor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_B_POST - .postcondition([] { - out << "b::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(b_post); - }) - #endif - ; - out << "b::dtor::body" << std::endl; - } -}; - -bool a_pre = true, a_post = true; -bool a_entering_static_inv = true, a_entry_static_inv = true, - a_exit_static_inv = true; -bool a_entry_inv = true; // Only entry non-static inv for dtors. -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_A_STATIC_INV - static void static_invariant() { - out << "a::static_inv" << std::endl; - if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); - else BOOST_CONTRACT_ASSERT(a_exit_static_inv); - a_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_A_INV - void invariant() const { - out << "a::inv" << std::endl; - BOOST_CONTRACT_ASSERT(a_entry_inv); - } - #endif - - virtual ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - #ifdef BOOST_CONTRACT_TEST_NO_A_PRE - #error "destructors cannot have preconditions" - #endif - .old([] { out << "a::dtor::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_A_POST - .postcondition([] { - out << "a::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(a_post); - }) - #endif - ; - out << "a::dtor::body" << std::endl; - } -}; - -#endif // #include guard - diff --git a/test/destructor/decl_entry_inv_all.cpp b/test/destructor/decl_entry_inv_all.cpp deleted file mode 100644 index 4fc769fa..00000000 --- a/test/destructor/decl_entry_inv_all.cpp +++ /dev/null @@ -1,221 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with entry static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a(bool failed = false) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl // This can fail. - #endif - ; - if(!failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -enum checked { passed, failed, threw }; - -std::string ok_b(checked check = passed) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl // This can fail. - #endif - ; - if(check != failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << (check == threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(checked check = passed) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // This can fail. - #endif - ; - if(check != failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (check == threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (dtors should never throw otherwise). - }); - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - try { - { - a aa; - ok.str(""); ok - // Test entry a::inv failed... - << ok_a(BOOST_CONTRACT_TEST_entry_inv) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_entry_inv ? threw : passed) - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() - // Test entry b::inv failed... - << ok_b(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - // Test entry c::inv failed... - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple except, - // just ignore failure and continue test program (for testing only). - }); - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - { - a aa; - out.str(""); - } - ok.str(""); ok - // Test entry a::inv failed (as all did). - << ok_a(BOOST_CONTRACT_TEST_entry_inv) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::dtor::body" << std::endl - #endif - - // Test entry b::inv failed (as all did). - << ok_b(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::dtor::body" << std::endl - #endif - - // Test entry c::inv failed (as all did). - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::dtor::body" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_inv_ends.cpp b/test/destructor/decl_entry_inv_ends.cpp deleted file mode 100644 index a00f2273..00000000 --- a/test/destructor/decl_entry_inv_ends.cpp +++ /dev/null @@ -1,205 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with entry invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a(bool failed = false) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl // This can fail. - #endif - ; - if(!failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - // No b::inv here (not even when threw). - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -enum checked { passed, failed, threw }; - -std::string ok_c(checked check = passed) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // This can fail. - #endif - ; - if(check != failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (check == threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). - }); - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - try { - { - a aa; - ok.str(""); ok - // Test entry a::inv failed... - << ok_a(BOOST_CONTRACT_TEST_entry_inv) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_entry_inv) - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() // Test no entry b::inv so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - // Test entry c::inv failed... - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... - }); - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - { - a aa; - out.str(""); - } - ok.str(""); ok - // Test entry a::inv failed (as all did). - << ok_a(BOOST_CONTRACT_TEST_entry_inv) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::dtor::body" << std::endl - #endif - - << ok_b() // Test no entry b::inv so no failure here. - - // Test entry c::inv failed (as all did). - << ok_c(BOOST_CONTRACT_TEST_entry_inv ? failed : passed) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::dtor::body" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_inv_mid.cpp b/test/destructor/decl_entry_inv_mid.cpp deleted file mode 100644 index 37c55b89..00000000 --- a/test/destructor/decl_entry_inv_mid.cpp +++ /dev/null @@ -1,193 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b(bool failed = false) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl // This can fail. - #endif - ; - if(!failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - // No b::inv here (not even when threw). - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). - }); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - try { - { - a aa; - ok.str(""); - out.str(""); - } - ok.str(""); ok - << ok_a() // Test no entry a::inv so no failure here. - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 2 - #endif - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() - // Test entry b::inv failed... - << ok_b(bool(BOOST_CONTRACT_TEST_entry_inv)) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(bool(BOOST_CONTRACT_TEST_entry_inv)) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - try { - { - a aa; - ok.str(""); - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() - << ok_c() // Test no entry c::inv so no failure here. - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... - }); - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() // Test no entry a::inv so no failure here. - - // Test entry b::inv failed (as all did). - << ok_b(bool(BOOST_CONTRACT_TEST_entry_inv)) - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::dtor::body" << std::endl - #endif - - << ok_c() // Test no entry c::inv so no failure here. - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_inv_none.cpp b/test/destructor/decl_entry_inv_none.cpp deleted file mode 100644 index 81a7301f..00000000 --- a/test/destructor/decl_entry_inv_none.cpp +++ /dev/null @@ -1,109 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without entry invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::dtor::post" << std::endl - #endif - ; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_static_inv_all.cpp b/test/destructor/decl_entry_static_inv_all.cpp deleted file mode 100644 index 56f39a2a..00000000 --- a/test/destructor/decl_entry_static_inv_all.cpp +++ /dev/null @@ -1,230 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with entry static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << (threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (dtors should never throw otherwise). - }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // Test this failed... - #else - << ok_a() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_entry_inv) - << ok_c(BOOST_CONTRACT_TEST_entry_inv) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl // Test this failed... - #else - << ok_b() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_entry_inv) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // Test this failed... - #else - << ok_c() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... - }); - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // Test this failed (as all did)... - << "a::dtor::body" << std::endl - - << "b::static_inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl - - << "c::static_inv" << std::endl // Test this failed (as all did)... - << "c::dtor::body" << std::endl - #else - << ok_a() - << ok_b() - << ok_c() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_static_inv_ends.cpp b/test/destructor/decl_entry_static_inv_ends.cpp deleted file mode 100644 index 60956a47..00000000 --- a/test/destructor/decl_entry_static_inv_ends.cpp +++ /dev/null @@ -1,215 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with entry static inv. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << (threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (dtors should never throw otherwise). - }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // Test this failed... - #else - << ok_a() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_entry_inv) - << ok_c(BOOST_CONTRACT_TEST_entry_inv) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() // Test no b::static_inv so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // Test this failed... - #else - << ok_c() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program. - }); - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl // Test this failed (as all did). - << "a::dtor::body" << std::endl - - << ok_b() // Test no b::static_inv so no failure here. - - << "c::static_inv" << std::endl // Test this failed (as all did). - << "c::dtor::body" << std::endl - #else - << ok_a() - << ok_b() - << ok_c() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_static_inv_mid.cpp b/test/destructor/decl_entry_static_inv_mid.cpp deleted file mode 100644 index d2c34273..00000000 --- a/test/destructor/decl_entry_static_inv_mid.cpp +++ /dev/null @@ -1,202 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (dtors should never throw otherwise). - }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() // Test no a::static_inv so no failure here. - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl // Test this failed... - #else - << ok_b() - #endif - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_entry_inv) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() - << ok_c() // Test no c::static_inv so no failure here. - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_entry_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... - }); - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << ok_a() // Test no a::static_inv so no failure here. - - << "b::static_inv" << std::endl // Test this failed (as all did)... - << "b::dtor::body" << std::endl - - << ok_c() // Test no c::static_inv so no failure here. - #else - << ok_a() - << ok_b() - << ok_c() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_entry_static_inv_none.cpp b/test/destructor/decl_entry_static_inv_none.cpp deleted file mode 100644 index 4630cd28..00000000 --- a/test/destructor/decl_entry_static_inv_none.cpp +++ /dev/null @@ -1,118 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::dtor::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_exit_static_inv_all.cpp b/test/destructor/decl_exit_static_inv_all.cpp deleted file mode 100644 index e6c42786..00000000 --- a/test/destructor/decl_exit_static_inv_all.cpp +++ /dev/null @@ -1,221 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a(bool failed = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl // This can fail. - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!failed ? "a::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -enum checked { passed, failed, threw }; - -std::string ok_b(checked check = passed) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl // This can fail. - << (check == threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(checked check = passed) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // This can fail. - << (check == threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #define BOOST_CONTRACT_TEST_exit_inv 0 - #else - #define BOOST_CONTRACT_TEST_exit_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (as dtors should not throw otherwise). - }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - // Test a::static_inv failed... - << ok_a(BOOST_CONTRACT_TEST_exit_inv) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_exit_inv ? threw : passed) - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - // Test b::static_inv failed... - << ok_b(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - // Test exit c::static_inv failed. - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ... then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_exit_invariant_failure([] (boost::contract::from) { - // Testing multiple failures but dtors must not throw multiple except, - // just ignore failure and continue test program (for testing only). - }); - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - // Test exit a::static_inv failed (as all did). - << ok_a(BOOST_CONTRACT_TEST_exit_inv) - // Test exit b::static_inv failed (as all did). - << ok_b(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - // Test exit c::static_inv failed (as all did). - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - #undef BOOST_CONTRACT_TEST_exit_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_exit_static_inv_ends.cpp b/test/destructor/decl_exit_static_inv_ends.cpp deleted file mode 100644 index 4ed34979..00000000 --- a/test/destructor/decl_exit_static_inv_ends.cpp +++ /dev/null @@ -1,210 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a(bool failed = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl // This can fail. - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!failed ? "a::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << (threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -enum checked { passed, failed, threw }; - -std::string ok_c(checked check = passed) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // This can fail. - << (check == threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (check == passed ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #define BOOST_CONTRACT_TEST_exit_inv 0 - #else - #define BOOST_CONTRACT_TEST_exit_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (as dtors should not throw otherwise). - }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - // Test a::static_inv failed... - << ok_a(BOOST_CONTRACT_TEST_exit_inv) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_exit_inv) - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? threw : passed) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() // Test no exit b::static_inv so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - // Test c::static_inv failed... - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_exit_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple - // exceptions, just ignore failure and continue test program... - }); - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - // Test a::static_inv failed (as all did). - << ok_a(BOOST_CONTRACT_TEST_exit_inv) - // Test no exit b::static_inv so no failure here. - << ok_b() - // Test c::static_inv failed (as all did). - << ok_c(BOOST_CONTRACT_TEST_exit_inv ? failed : passed) - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - #undef BOOST_CONTRACT_TEST_exit_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_exit_static_inv_mid.cpp b/test/destructor/decl_exit_static_inv_mid.cpp deleted file mode 100644 index 3b125c3d..00000000 --- a/test/destructor/decl_exit_static_inv_mid.cpp +++ /dev/null @@ -1,202 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b(bool failed = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl // This can fail. - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!failed ? "b::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - #ifdef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #define BOOST_CONTRACT_TEST_exit_inv 0 - #else - #define BOOST_CONTRACT_TEST_exit_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws. - throw err(); // For testing only (as dtors should not throw otherwise). - }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); - out.str(""); - } - ok.str(""); ok - << ok_a() // Test no exit a::static_inv so no failure here. - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); ok - << ok_a() - // Test exit b::static_inv failed... - << ok_b(BOOST_CONTRACT_TEST_exit_inv) - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_exit_inv) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - try { - { - a aa; - ok.str(""); - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() - // Test no exit c::static_inv so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - boost::contract::set_exit_invariant_failure([] (boost::contract::from) { - // Testing multiple failures so dtors must not throw multiple except, - // just ignore failure and continue test program (for testing only). - }); - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - ok.str(""); ok - // Test no exit a::static_inv so no faliure here. - << ok_a() - // Test exit b::static_inv failed (as all did). - << ok_b(BOOST_CONTRACT_TEST_exit_inv) - // Test no exit c::static_inv so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - #undef BOOST_CONTRACT_TEST_exit_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_exit_static_inv_none.cpp b/test/destructor/decl_exit_static_inv_none.cpp deleted file mode 100644 index 9afe4c3e..00000000 --- a/test/destructor/decl_exit_static_inv_none.cpp +++ /dev/null @@ -1,118 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::dtor::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/destructor/decl_post_all.cpp b/test/destructor/decl_post_all.cpp deleted file mode 100644 index 2e20a5c2..00000000 --- a/test/destructor/decl_post_all.cpp +++ /dev/null @@ -1,199 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << (threw ? "b::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "b::dtor::post\n" : "") // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") // This can fail. - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // for testing (as dtors should never throw anyways). - }); - - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_TEST_post 0 - #else - #define BOOST_CONTRACT_TEST_post 1 - #endif - - a_post = false; - b_post = true; - c_post = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() // Test a::dtor::post failed... - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_post) - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() // Test b::dtor::post failed... - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - << ok_c() // Test c::dtor::post failed... - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ...then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() // Test a::dtor::post failed... - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_post) - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_post - return boost::report_errors(); -} - diff --git a/test/destructor/decl_post_ends.cpp b/test/destructor/decl_post_ends.cpp deleted file mode 100644 index ffa27a5b..00000000 --- a/test/destructor/decl_post_ends.cpp +++ /dev/null @@ -1,190 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_b(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << (threw ? "b::inv\n" : "") - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (threw ? "c::inv\n" : "") - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << (!threw ? "c::dtor::post\n" : "") // This can fail. - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // ... for testing (as dtors should never throw anyways). - }); - - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_TEST_post 0 - #else - #define BOOST_CONTRACT_TEST_post 1 - #endif - - a_post = false; - b_post = true; - c_post = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() // Test a::dtor::post failed. - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_post) - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - try { - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() // Test no b::dtor::post so no failure here. - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() - << ok_c() // Test c::dtor::post failed. - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - // ... then exec other dtors and check inv on throw (as dtor threw). - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() // Test a::dtor::post failed. - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << ok_b(BOOST_CONTRACT_TEST_post) - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_post - return boost::report_errors(); -} - diff --git a/test/destructor/decl_post_mid.cpp b/test/destructor/decl_post_mid.cpp deleted file mode 100644 index 5d37884f..00000000 --- a/test/destructor/decl_post_mid.cpp +++ /dev/null @@ -1,181 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_a() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_b() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -std::string ok_c(bool threw = false) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << (threw ? "c::inv\n" : "") - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a_post = true; - b_post = true; - c_post = true; - { - a aa; - out.str(""); - } - ok.str(""); ok // Test nothing failed. - << ok_a() - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure([&ok] (boost::contract::from) { - BOOST_TEST(out.eq(ok.str())); // Must check before dtor throws... - throw err(); // ... for testing (as dtors should never throw anyways). - }); - - a_post = false; - b_post = true; - c_post = true; - try { - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() // Test no a::dtor::post so no failure here. - << ok_b() - << ok_c() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #ifdef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_TEST_post 0 - #else - #define BOOST_CONTRACT_TEST_post 1 - #endif - - a_post = true; - b_post = false; - c_post = true; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() // Test b::dtor::post failed. - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - try { - { - a aa; - out.str(""); - } - ok.str(""); ok - << ok_a() - << ok_b() - << ok_c() // Test no c::dtor::post so no failure here. - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - try { - { - a aa; - ok.str(""); ok - << ok_a() - << ok_b() // Test b::dtor::post failed. - ; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok // ... then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_post) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_post - return boost::report_errors(); -} - diff --git a/test/destructor/decl_post_none.cpp b/test/destructor/decl_post_none.cpp deleted file mode 100644 index 96bd1a97..00000000 --- a/test/destructor/decl_post_none.cpp +++ /dev/null @@ -1,103 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - ; - - a_post = true; - b_post = true; - c_post = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_post = false; - b_post = true; - c_post = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_post = true; - b_post = false; - c_post = true; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_post = true; - b_post = true; - c_post = false; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - a_post = false; - b_post = false; - c_post = false; - { - a aa; - out.str(""); - } - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/destructor/ifdef.cpp b/test/destructor/ifdef.cpp deleted file mode 100644 index 10647471..00000000 --- a/test/destructor/ifdef.cpp +++ /dev/null @@ -1,111 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#ifndef BOOST_CONTRACT_NO_DESTRUCTORS - #include - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - #endif - - virtual ~b() { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_y = BOOST_CONTRACT_OLDOF(y); - #endif - #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - boost::contract::check c = boost::contract::destructor(this) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - #endif - ; - #endif - out << "b::dtor::body" << std::endl; - } - - static int y; -}; -int b::y = 0; - -struct a : public b { - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - #endif - - virtual ~a() { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - boost::contract::check c = boost::contract::destructor(this) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - #endif - ; - #endif - out << "a::dtor::body" << std::endl; - } - - static int x; -}; -int a::x = 0; - -int main() { - std::ostringstream ok; - { - a aa; - out.str(""); - } - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - return boost::report_errors(); -} - diff --git a/test/destructor/ifdef_macro.cpp b/test/destructor/ifdef_macro.cpp deleted file mode 100644 index 756d8e16..00000000 --- a/test/destructor/ifdef_macro.cpp +++ /dev/null @@ -1,142 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off (using macro interface). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::inv" << std::endl; - }) - - virtual ~b() { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas::type1 - )( - old_y, - (boost::contract::test::detail::unprotected_commas::same(y)) - ); - BOOST_CONTRACT_DESTRUCTOR(boost::contract::test::detail:: - unprotected_commas::same(this)) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::dtor::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::dtor::post" << std::endl; - }) - ; - out << "b::dtor::body" << std::endl; - } - - static int y; -}; -int b::y = 0; - -struct a : public b { - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::inv" << std::endl; - }) - - virtual ~a() { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas:: - type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_DESTRUCTOR(boost::contract::test::detail:: - unprotected_commas::same(this)) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::dtor::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::dtor::post" << std::endl; - }) - ; - out << "a::dtor::body" << std::endl; - } - - static int x; -}; -int a::x = 0; - -int main() { - std::ostringstream ok; - { - a aa; - out.str(""); - } - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - return boost::report_errors(); -} - diff --git a/test/destructor/pre_error.cpp b/test/destructor/pre_error.cpp deleted file mode 100644 index ac6f84c9..00000000 --- a/test/destructor/pre_error.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test destructor cannot use `.precondition(...)`. - -#include -#include - -struct a { - ~a() { - boost::contract::check c = boost::contract::destructor(this) - .precondition([] {}) // Error (no dtor func arg so never pre). - ; - } -}; - -int main() { - a aa; - return 0; -} - diff --git a/test/destructor/smoke.cpp b/test/destructor/smoke.cpp deleted file mode 100644 index 01196809..00000000 --- a/test/destructor/smoke.cpp +++ /dev/null @@ -1,302 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test destructor subcontracting. - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -template -struct t { - static void static_invariant() { - out << Id << "::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(l.value >= 0); - } - - void invariant() const { - out << Id << "::inv" << std::endl; - BOOST_CONTRACT_ASSERT(k_ < 0); - } - - struct l_tag; - typedef boost::contract::test::detail::counter l_type; - static l_type l; - - explicit t() : k_(-1) { ++l.value; } - - virtual ~t() { - boost::contract::old_ptr old_l; - boost::contract::check c = boost::contract::destructor(this) - .old([&] { - out << Id << "::dtor::old" << std::endl; - old_l = BOOST_CONTRACT_OLDOF(l_type::eval(l)); - }) - .postcondition([&old_l] { - out << Id << "::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(t::l.value == old_l->value - 1); - }) - ; - out << Id << "::dtor::body" << std::endl; - --l.value; - } - -private: - int k_; -}; -template typename t::l_type t::l; - -// Test deep inheritance (2 vertical levels), multiple inheritance (4 -// horizontal levels), and that all public/protected/private part of -// subcontracting for destructors (not just public, because all access levels -// are part of C++ object destruction mechanism). -struct c - #define BASES public t<'d'>, protected t<'p'>, private t<'q'>, public t<'e'> - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - out << "c::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(m.value >= 0); - } - - void invariant() const { - out << "c::inv" << std::endl; - BOOST_CONTRACT_ASSERT(j_ < 0); - } - - struct m_tag; - typedef boost::contract::test::detail::counter m_type; - static m_type m; - - explicit c() : j_(-1) { ++m.value; } - - virtual ~c() { - boost::contract::old_ptr old_m = - BOOST_CONTRACT_OLDOF(m_type::eval(m)); - boost::contract::check c = boost::contract::destructor(this) - .old([] { - out << "c::dtor::old" << std::endl; - // Test old-of assignment above instead. - }) - .postcondition([&old_m] { - out << "c::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(c::m.value == old_m->value - 1); - }) - ; - out << "c::dtor::body" << std::endl; - --m.value; - } - -private: - int j_; -}; -c::m_type c::m; - -// Test not (fully) contracted base is not part of destructor subcontracting. -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - explicit b() {} - virtual ~b() {} // No contract. -}; - -// Test destructor with both non-contracted and contracted bases. -struct a - #define BASES public b, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - out << "a::static_inv" << std::endl; - BOOST_CONTRACT_ASSERT(n.value >= 0); - } - - void invariant() const { - out << "a::inv" << std::endl; - BOOST_CONTRACT_ASSERT(i_ < 0); - } - - struct n_tag; - typedef boost::contract::test::detail::counter n_type; - static n_type n; - - explicit a() : i_(-1) { ++n.value; } - - virtual ~a() { - boost::contract::old_ptr old_n; - boost::contract::check c = boost::contract::destructor(this) - .old([&] { - out << "a::dtor::old" << std::endl; - old_n = BOOST_CONTRACT_OLDOF(n_type::eval(n)); - }) - .postcondition([&old_n] { - out << "a::dtor::post" << std::endl; - BOOST_CONTRACT_ASSERT(a::n.value == old_n->value - 1); - }) - ; - out << "a::dtor::body" << std::endl; - --n.value; - } - -private: - int i_; -}; -a::n_type a::n; - -int main() { - std::ostringstream ok; - - { - a aa; - out.str(""); - } // Call aa's destructor. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - // Test static inv, but not const inv, checked after destructor body. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "e::dtor::old" << std::endl - #endif - << "e::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "e::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "e::dtor::post" << std::endl - #endif - - // Test check also private bases (because part of C++ destruction). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "q::static_inv" << std::endl - << "q::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "q::dtor::old" << std::endl - #endif - << "q::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "q::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "q::dtor::post" << std::endl - #endif - - // Test check also protected bases (because part of C++ destruction). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "p::static_inv" << std::endl - << "p::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "p::dtor::old" << std::endl - #endif - << "p::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "p::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "p::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::dtor::old" << std::endl - #endif - << "d::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - // Followings destroy only copies (actual objects are static data members). - - BOOST_TEST_EQ(a::n_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::n_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. - - BOOST_TEST_EQ(c::m_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::m_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. - - BOOST_TEST_EQ(t<'d'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'d'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'d'>::l_type::copies(), t<'d'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'p'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'p'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'p'>::l_type::copies(), t<'p'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'q'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'q'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'q'>::l_type::copies(), t<'q'>::l_type::dtors()); // No leak - - BOOST_TEST_EQ(t<'e'>::l_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/destructor/throwing_body.cpp b/test/destructor/throwing_body.cpp deleted file mode 100644 index fcba3794..00000000 --- a/test/destructor/throwing_body.cpp +++ /dev/null @@ -1,144 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from destructor body (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "c::dtor::old" << std::endl; }) - .postcondition([] { out << "c::dtor::post" << std::endl; }) - .except([] { out << "c::dtor::except" << std::endl; }) - ; - out << "c::dtor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - .except([] { out << "b::dtor::except" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - throw b::err(); // Test body throw (from inheritance mid branch). - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - .except([] { out << "a::dtor::except" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - try { - { - a aa; - out.str(""); - } - BOOST_TEST(false); - } catch(b::err const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - // Test a destructed (so only static_inv and post, but no inv). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl // Test this threw. - // Test b not destructed (so static_inv, inv, and except, no post). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "b::dtor::except" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - // Test c not destructed (so static_inv, inv, and except, no post). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "c::dtor::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/destructor/throwing_old.cpp b/test/destructor/throwing_old.cpp deleted file mode 100644 index 06ce9524..00000000 --- a/test/destructor/throwing_old.cpp +++ /dev/null @@ -1,150 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from destructor .old() (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "c::dtor::old" << std::endl; }) - .postcondition([] { out << "c::dtor::post" << std::endl; }) - .except([] { out << "c::dtor::except" << std::endl; }) - ; - out << "c::dtor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { - out << "b::dtor::old" << std::endl; - throw b::err(); // Test this throws (from mid branch). - }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - .except([] { out << "b::dtor::except" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - .except([] { out << "a::dtor::except" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - try { - { - a aa; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(false); - } catch(b::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - // Test a destructed (so only static_inv and post, but no inv). - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl // Test this threw. - #else - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - // Test c not destructed (so both inv and except). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "c::dtor::except" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/destructor/throwing_post.cpp b/test/destructor/throwing_post.cpp deleted file mode 100644 index d576105f..00000000 --- a/test/destructor/throwing_post.cpp +++ /dev/null @@ -1,153 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from destructor .post() (in middle branch of inheritance tree). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "c::dtor::old" << std::endl; }) - .postcondition([] { out << "c::dtor::post" << std::endl; }) - .except([] { out << "c::dtor::except" << std::endl; }) - ; - out << "c::dtor::body" << std::endl; - // Do not throw (from inheritance root). - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { - out << "b::dtor::post" << std::endl; - throw b::err(); // Test this throws (from mid branch). - }) - .except([] { out << "b::dtor::except" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - .except([] { out << "a::dtor::except" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - // Do not throw (from inheritance leaf). - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw; }); - - try { - { - a aa; - out.str(""); - } - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(b::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - // Test a destructed (so only static_inv and post, but no inv). - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl // Test this threw. - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::dtor::old" << std::endl - #endif - << "c::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // Test c not destructed (so both inv and except). - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "c::dtor::except" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/detail/counter.hpp b/test/detail/counter.hpp deleted file mode 100644 index 0e4304f7..00000000 --- a/test/detail/counter.hpp +++ /dev/null @@ -1,56 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_ -#define BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -namespace boost { namespace contract { namespace test { namespace detail { - -// Helper to count copies and evaluations of type (e.g., for old values). -template -struct counter { - T value; - - counter() : value() { ++ctors_; } - static unsigned ctors() { return ctors_; } - - ~counter() { ++dtors_; } - static unsigned dtors() { return dtors_; } - - /* implicit */ counter(counter const& other) : value(other.value) { - ++ctor_copies_; - ++ctors_; - } - - counter& operator=(counter const& other) { - value = other.value; - ++op_copies_; - return *this; - } - - static unsigned copies() { return ctor_copies_ + op_copies_; } - - static counter const& eval(counter const& me) { ++me.evals_; return me; } - static unsigned evals() { return evals_; } - -private: - static unsigned ctors_; // Total constructions (including copies). - static unsigned dtors_; - static unsigned ctor_copies_; - static unsigned op_copies_; - static unsigned evals_; -}; - -template unsigned counter::ctors_ = 0; -template unsigned counter::dtors_ = 0; -template unsigned counter::ctor_copies_ = 0; -template unsigned counter::op_copies_ = 0; -template unsigned counter::evals_ = 0; - -} } } } // namespace - -#endif // #include guard - diff --git a/test/detail/oteststream.hpp b/test/detail/oteststream.hpp deleted file mode 100644 index dad068e0..00000000 --- a/test/detail/oteststream.hpp +++ /dev/null @@ -1,79 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_HPP_ -#define BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include - -namespace boost { namespace contract { namespace test { namespace detail { - -namespace oteststream_ { - struct oss_base { // Wrap oss data member for proper initialization order. - protected: - std::ostringstream oss_; - }; -} - -// Print to clog plus build internal string (using ostringstream) for checking. -struct oteststream : - private oteststream_::oss_base, - public boost::iostreams::stream > -{ - oteststream() : - oteststream_::oss_base(), - boost::iostreams::stream >( - boost::iostreams::tee_device( - std::clog, oss_) - ) - {} - - std::string str() const { return oss_.str(); } - void str(std::string const& s) { oss_.str(s); } - - bool eq(std::string const& s) { return eq(str(), s); } - - // Also display mismatching characters. - static bool eq(std::string const& r, std::string const& s) { - std::string::size_type i = 0; - for(; i < r.size() && i < s.size(); ++i) if(r[i] != s[i]) break; - if(i < r.size() || i < s.size()) { - std::cout << std::endl; - std::cout << - "Error: Following strings differ at position " << i << - ", because '" << r[i] << "' != '" << s[i] << "':" << std::endl - ; - std::cout << std::endl; - std::cout - << r.substr(0, i) - << "(((" << r[i] << ")))" - << r.substr(std::min(i + 1, r.size()), r.size()) - << std::endl - ; - std::cout << std::endl; - std::cout - << s.substr(0, i) - << "(((" << s[i] << ")))" - << s.substr(std::min(i + 1, s.size()), s.size()) - << std::endl - ; - std::cout << std::endl; - return false; - } - return true; - } -}; - -} } } } // namespace - -#endif // #include guard - diff --git a/test/detail/out.hpp b/test/detail/out.hpp deleted file mode 100644 index 558322e0..00000000 --- a/test/detail/out.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ -#define BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// To declare test string functions across shared libraries. - -#include - -namespace boost { namespace contract { namespace test { namespace detail { - -std::string BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(); - -void BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(std::string const& text); - -} } } } - -#endif // #include guard - diff --git a/test/detail/out_inlined.hpp b/test/detail/out_inlined.hpp deleted file mode 100644 index e4563e48..00000000 --- a/test/detail/out_inlined.hpp +++ /dev/null @@ -1,33 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ -#define BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "out.hpp" -#include - -namespace boost { namespace contract { namespace test { namespace detail { - -namespace out_ { - std::string out; -} - -std::string out() { return out_::out; } - -void out(std::string const& text) { - if(text == "") out_::out = ""; - else { - out_::out = out_::out + text; - std::clog << text; - std::clog.flush(); - } -} - -} } } } - -#endif // #include guard - diff --git a/test/detail/unprotected_commas.hpp b/test/detail/unprotected_commas.hpp deleted file mode 100644 index d2c7264d..00000000 --- a/test/detail/unprotected_commas.hpp +++ /dev/null @@ -1,25 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_DETAIL_UNPROTECTED_COMMAS_HPP_ -#define BOOST_CONTRACT_TEST_DETAIL_UNPROTECTED_COMMAS_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -namespace boost { namespace contract { namespace test { namespace detail { - -// Used to test passing unprotected commas into macro parameters. -template -struct unprotected_commas { - typedef T1 type1; // For type and code block macro parameters. - - // For value macro parameters. - template static U& same(U& x) { return x; } - template static U* same(U* x) { return x; } -}; - -} } } } // namespace - -#endif // #include guard - diff --git a/test/disable/always_disable_post_except_lib.cpp b/test/disable/always_disable_post_except_lib.cpp deleted file mode 100644 index c2b1246e..00000000 --- a/test/disable/always_disable_post_except_lib.cpp +++ /dev/null @@ -1,75 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contracts in .cpp compiled to never check post/except (but not in .hpp). - -#include "lib_x.hpp" -#include "lib_y.hpp" -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -void f() { - using boost::contract::test::detail::out; - boost::contract::check c = boost::contract::function() - .precondition([] { out("f::pre\n"); }) - .old([] { out("f::old\n"); }) - .postcondition([] { out("f::post\n"); }) - ; - out("f::body\n"); -} - -int main() { - using boost::contract::test::detail::out; - std::ostringstream ok; - - out(""); - f(); - ok.str(""); ok // Test normal (no lib) case. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); - - out(""); - x(); - ok.str(""); ok // Test contracts in .cpp so no post (NO_POST in build file). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "x::pre" << std::endl - #endif - << "x::body" << std::endl - ; - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); - - out(""); - y(); - ok.str(""); ok // Test contracts in .hpp so post (NO_POST in build file). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "y::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "y::old" << std::endl - #endif - << "y::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "y::post" << std::endl - #endif - ; - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); - - return boost::report_errors(); -} - diff --git a/test/disable/assertions_disable_assertions_lib.cpp b/test/disable/assertions_disable_assertions_lib.cpp deleted file mode 100644 index 72d846f3..00000000 --- a/test/disable/assertions_disable_assertions_lib.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test assertion checking disables other assertion checking (in libraries). - -#include "lib_ab.hpp" - diff --git a/test/disable/assertions_disable_assertions_prog.cpp b/test/disable/assertions_disable_assertions_prog.cpp deleted file mode 100644 index e2c094e0..00000000 --- a/test/disable/assertions_disable_assertions_prog.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test assertion checking disables other assertion checking (in programs). - -#include "prog.hpp" - diff --git a/test/disable/audit.cpp b/test/disable/audit.cpp deleted file mode 100644 index 4f8beb73..00000000 --- a/test/disable/audit.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_AUDITS -#include "audit.hpp" - diff --git a/test/disable/audit.hpp b/test/disable/audit.hpp deleted file mode 100644 index 539cdf3a..00000000 --- a/test/disable/audit.hpp +++ /dev/null @@ -1,32 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -int main() { - bool threw = false; - try { - #ifdef BOOST_CONTRACT_TEST_ERROR - BOOST_CONTRACT_ASSERT_AUDIT( - BOOST_CONTRACT_TEST_ERROR_expected_undeclared_identifier); - #else - BOOST_CONTRACT_ASSERT_AUDIT(false); - #endif - } catch(boost::contract::assertion_failure const&) { threw = true; } - - #if defined(BOOST_CONTRACT_AUDITS) && !defined(BOOST_CONTRACT_NO_ALL) - BOOST_TEST(threw); - #else - BOOST_TEST(!threw); - #endif - - return boost::report_errors(); -} - diff --git a/test/disable/audit_disabled.cpp b/test/disable/audit_disabled.cpp deleted file mode 100644 index 75bc5d07..00000000 --- a/test/disable/audit_disabled.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "audit.hpp" - diff --git a/test/disable/audit_disabled_error.cpp b/test/disable/audit_disabled_error.cpp deleted file mode 100644 index e90e2e97..00000000 --- a/test/disable/audit_disabled_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "audit.hpp" - diff --git a/test/disable/audit_error.cpp b/test/disable/audit_error.cpp deleted file mode 100644 index e90e2e97..00000000 --- a/test/disable/audit_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "audit.hpp" - diff --git a/test/disable/axiom.cpp b/test/disable/axiom.cpp deleted file mode 100644 index b26d6468..00000000 --- a/test/disable/axiom.cpp +++ /dev/null @@ -1,8 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "axiom.hpp" - diff --git a/test/disable/axiom.hpp b/test/disable/axiom.hpp deleted file mode 100644 index f609bb80..00000000 --- a/test/disable/axiom.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -bool no_impl(); // Test func that cannot be impl in C++ sill OK in axioms. - -int main() { - #ifdef BOOST_CONTRACT_TEST_ERROR - BOOST_CONTRACT_ASSERT_AXIOM( - BOOST_CONRACT_TEST_ERROR_expected_undeclared_identifier); - #else - BOOST_CONTRACT_ASSERT_AXIOM(false); // Test always false, OK. - BOOST_CONTRACT_ASSERT_AXIOM(no_impl()); // Test no implementation, OK. - #endif - return 0; -} - diff --git a/test/disable/axiom_error.cpp b/test/disable/axiom_error.cpp deleted file mode 100644 index f3cf0b6a..00000000 --- a/test/disable/axiom_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_ERROR -#include "axiom.hpp" - diff --git a/test/disable/lib_a.cpp b/test/disable/lib_a.cpp deleted file mode 100644 index 465c8e84..00000000 --- a/test/disable/lib_a.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_LIB_A_SOURCE -#include "lib_a.hpp" -#ifndef BOOST_CONTRACT_HEADER_ONLY - #include "lib_a_inlined.hpp" -#endif -#include "../detail/out_inlined.hpp" - diff --git a/test/disable/lib_a.hpp b/test/disable/lib_a.hpp deleted file mode 100644 index 05b24ffe..00000000 --- a/test/disable/lib_a.hpp +++ /dev/null @@ -1,50 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_A_HPP_ -#define BOOST_CONTRACT_TEST_LIB_A_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "../detail/counter.hpp" -#include -#include - -#ifdef BOOST_CONTRACT_TEST_LIB_A_DYN_LINK - #ifdef BOOST_CONTRACT_TEST_LIB_A_SOURCE - #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC BOOST_SYMBOL_EXPORT - #else - #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC BOOST_SYMBOL_IMPORT - #endif -#else - #define BOOST_CONTRACT_TEST_LIB_A_DECLSPEC /* nothing */ -#endif - -#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ - BOOST_CONTRACT_TEST_LIB_A_DECLSPEC -#include "../detail/out.hpp" - -struct BOOST_CONTRACT_TEST_LIB_A_DECLSPEC a { - static void static_invariant(); - void invariant() const; - - struct x_tag; - typedef boost::contract::test::detail::counter x_type; - - int f(x_type& x); - - static void disable_pre_failure(); - static void disable_post_failure(); - static void disable_entry_inv_failure(); - static void disable_exit_inv_failure(); - static void disable_inv_failure(); - static void disable_failure(); -}; - -#ifdef BOOST_CONTRACT_HEADER_ONLY - #include "lib_a_inlined.hpp" -#endif - -#endif // #include guard - diff --git a/test/disable/lib_a_inlined.hpp b/test/disable/lib_a_inlined.hpp deleted file mode 100644 index 2320e370..00000000 --- a/test/disable/lib_a_inlined.hpp +++ /dev/null @@ -1,88 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ -#define BOOST_CONTRACT_TEST_LIB_A_INLINED_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "lib_a.hpp" -#include -#include -#include -#include - -void a::static_invariant() { - using boost::contract::test::detail::out; - out("a::static_inv\n"); -} - -void a::invariant() const { - using boost::contract::test::detail::out; - out("a::inv\n"); -} - -int a::f(x_type& x) { - using boost::contract::test::detail::out; - int result; - boost::contract::old_ptr old_x = - BOOST_CONTRACT_OLDOF(x_type::eval(x)); - boost::contract::check c = boost::contract::public_function(this) - .precondition([] { out("a::f::pre\n"); }) - .old([] { out("a::f::old\n"); }) - .postcondition([&] { - out("a::f::post\n"); - BOOST_CONTRACT_ASSERT(x.value == -old_x->value); - BOOST_CONTRACT_ASSERT(result == old_x->value); - }) - ; - out("a::f::body\n"); - result = x.value; - x.value = -x.value; - return result; -} - -void a::disable_pre_failure() { - using boost::contract::test::detail::out; - boost::contract::set_precondition_failure([] (boost::contract::from) - { out("a::pre_failure\n"); }); -} - -void a::disable_post_failure() { - using boost::contract::test::detail::out; - boost::contract::set_postcondition_failure([] (boost::contract::from) - { out("a::post_failure\n"); }); -} - -void a::disable_entry_inv_failure() { - using boost::contract::test::detail::out; - boost::contract::set_entry_invariant_failure([] (boost::contract::from) - { out("a::entry_inv_failure\n"); }); -} - -void a::disable_exit_inv_failure() { - using boost::contract::test::detail::out; - boost::contract::set_exit_invariant_failure([] (boost::contract::from) - { out("a::exit_inv_failure\n"); }); -} - -void a::disable_inv_failure() { - using boost::contract::test::detail::out; - boost::contract::set_invariant_failure([] (boost::contract::from) - { out("a::inv_failure\n"); }); -} - -void a::disable_failure() { - using boost::contract::test::detail::out; - boost::contract::set_precondition_failure( - boost::contract::set_postcondition_failure( - boost::contract::set_except_failure( - boost::contract::set_old_failure( - boost::contract::set_invariant_failure( - [] (boost::contract::from) { out("a::failure\n"); } - ))))); -} - -#endif // #include guard - diff --git a/test/disable/lib_ab.hpp b/test/disable/lib_ab.hpp deleted file mode 100644 index c247f89c..00000000 --- a/test/disable/lib_ab.hpp +++ /dev/null @@ -1,164 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "lib_a.hpp" -#include "lib_b.hpp" -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -std::string ok_f() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - using boost::contract::test::detail::out; - std::ostringstream ok; - b bb; - - out(""); - bb.g(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::g::pre" << std::endl - #ifdef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION - // Test preconditions have disabled no contract. - << ok_f() - #else - // Test call while checking executes body (but no contracts). - << "a::f::body" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::g::old" << std::endl - #endif - << "b::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::g::post" << std::endl - // Test call while checking executes body (but no contracts). - << "a::f::body" << std::endl - #endif - ; - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok.str())); - - // Test old values not copied for disabled contracts. - - #if defined(BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) && \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ - !defined(BOOST_CONTRACT_NO_OLDS) - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(a::x_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::x_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); - - // Double check a call to f outside another contract checks f's contracts. - - out(""); - call_f(); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), ok_f())); - - // Test setting failure handlers (from this program using a lib). - - a::disable_pre_failure(); - out(""); - boost::contract::precondition_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::pre_failure\n")); - - a::disable_post_failure(); - out(""); - boost::contract::postcondition_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::post_failure\n")); - - a::disable_entry_inv_failure(); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::entry_inv_failure\n")); - - a::disable_exit_inv_failure(); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::exit_inv_failure\n")); - - a::disable_inv_failure(); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::inv_failure\n")); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::inv_failure\n")); - - a::disable_failure(); - out(""); - boost::contract::precondition_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n")); - out(""); - boost::contract::postcondition_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n")); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n")); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - BOOST_TEST(boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n")); - - // Test setting failure handlers (from a lib using another lib). - - BOOST_TEST(b::test_disable_pre_failure()); - BOOST_TEST(b::test_disable_post_failure()); - BOOST_TEST(b::test_disable_entry_inv_failure()); - BOOST_TEST(b::test_disable_exit_inv_failure()); - BOOST_TEST(b::test_disable_inv_failure()); - BOOST_TEST(b::test_disable_failure()); - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/disable/lib_b.cpp b/test/disable/lib_b.cpp deleted file mode 100644 index 9f12816d..00000000 --- a/test/disable/lib_b.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_LIB_B_SOURCE -#include "lib_b_inlined.hpp" - diff --git a/test/disable/lib_b.hpp b/test/disable/lib_b.hpp deleted file mode 100644 index 73c62660..00000000 --- a/test/disable/lib_b.hpp +++ /dev/null @@ -1,41 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_B_HPP_ -#define BOOST_CONTRACT_TEST_LIB_B_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -#ifdef BOOST_CONTRACT_TEST_LIB_B_DYN_LINK - #ifdef BOOST_CONTRACT_TEST_LIB_B_SOURCE - #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC BOOST_SYMBOL_EXPORT - #else - #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC BOOST_SYMBOL_IMPORT - #endif -#else - #define BOOST_CONTRACT_TEST_LIB_B_DECLSPEC /* nothing */ -#endif - -bool BOOST_CONTRACT_TEST_LIB_B_DECLSPEC call_f(); - -struct BOOST_CONTRACT_TEST_LIB_B_DECLSPEC b { - static void static_invariant(); - void invariant() const; - - void g(); - - static bool test_disable_pre_failure(); - static bool test_disable_post_failure(); - static bool test_disable_entry_inv_failure(); - static bool test_disable_exit_inv_failure(); - static bool test_disable_inv_failure(); - static bool test_disable_failure(); - -}; - -#endif // #include guard - - diff --git a/test/disable/lib_b_inlined.hpp b/test/disable/lib_b_inlined.hpp deleted file mode 100644 index bc8fbe8f..00000000 --- a/test/disable/lib_b_inlined.hpp +++ /dev/null @@ -1,126 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ -#define BOOST_CONTRACT_TEST_LIB_B_INLINED_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "lib_b.hpp" -#include "lib_a.hpp" -#include "../detail/oteststream.hpp" -#include -#include -#include - -bool call_f() { - a aa; - a::x_type x; x.value = -123; - return aa.f(x) == -123; -} - -void b::static_invariant() { - using boost::contract::test::detail::out; - out("b::static_inv\n"); -} - -void b::invariant() const { - using boost::contract::test::detail::out; - out("b::inv\n"); -} - -void b::g() { - using boost::contract::test::detail::out; - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - out("b::g::pre\n"); - BOOST_CONTRACT_ASSERT(call_f()); - }) - .old([&] { out("b::g::old\n"); }) - .postcondition([&] { - out("b::g::post\n"); - BOOST_CONTRACT_ASSERT(call_f()); - }) - ; - out("b::g::body\n"); -} - -bool b::test_disable_pre_failure() { - using boost::contract::test::detail::out; - a::disable_pre_failure(); - out(""); - boost::contract::precondition_failure(boost::contract::from()); - return boost::contract::test::detail::oteststream::eq(out(), - "a::pre_failure\n"); -} - -bool b::test_disable_post_failure() { - using boost::contract::test::detail::out; - a::disable_post_failure(); - out(""); - boost::contract::postcondition_failure(boost::contract::from()); - return boost::contract::test::detail::oteststream::eq(out(), - "a::post_failure\n"); -} - -bool b::test_disable_entry_inv_failure() { - using boost::contract::test::detail::out; - a::disable_entry_inv_failure(); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - return boost::contract::test::detail::oteststream::eq(out(), - "a::entry_inv_failure\n"); -} - -bool b::test_disable_exit_inv_failure() { - using boost::contract::test::detail::out; - a::disable_exit_inv_failure(); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - return boost::contract::test::detail::oteststream::eq(out(), - "a::exit_inv_failure\n"); -} - -bool b::test_disable_inv_failure() { - using boost::contract::test::detail::out; - - a::disable_inv_failure(); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - bool entry_inv = boost::contract::test::detail::oteststream::eq(out(), - "a::inv_failure\n"); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), - "a::inv_failure\n"); - - return entry_inv && exit_inv; -} - -bool b::test_disable_failure() { - using boost::contract::test::detail::out; - - a::disable_failure(); - out(""); - boost::contract::precondition_failure(boost::contract::from()); - bool pre = boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n"); - out(""); - boost::contract::postcondition_failure(boost::contract::from()); - bool post = boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n"); - out(""); - boost::contract::entry_invariant_failure(boost::contract::from()); - bool entry_inv = boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n"); - out(""); - boost::contract::exit_invariant_failure(boost::contract::from()); - bool exit_inv = boost::contract::test::detail::oteststream::eq(out(), - "a::failure\n"); - - return pre && post && entry_inv && exit_inv; -} - -#endif // #include guard - diff --git a/test/disable/lib_x.cpp b/test/disable/lib_x.cpp deleted file mode 100644 index 54c0515b..00000000 --- a/test/disable/lib_x.cpp +++ /dev/null @@ -1,30 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Force .cpp never check post/except. -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_NO_POSTCONDITIONS -#endif -#ifndef BOOST_CONTRACT_NO_EXCEPTS - #define BOOST_CONTRACT_NO_EXCEPTS -#endif - -#define BOOST_CONTRACT_TEST_LIB_X_SOURCE -#include "lib_x.hpp" -#include -#include -#include "../detail/out_inlined.hpp" - -void x() { - using boost::contract::test::detail::out; - boost::contract::check c = boost::contract::function() - .precondition([] { out("x::pre\n"); }) - .old([] { out("x::old\n"); }) - .postcondition([] { out("x::post\n"); }) - ; - out("x::body\n"); -} - diff --git a/test/disable/lib_x.hpp b/test/disable/lib_x.hpp deleted file mode 100644 index 9c07a71e..00000000 --- a/test/disable/lib_x.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_X_HPP_ -#define BOOST_CONTRACT_TEST_LIB_X_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -#ifdef BOOST_CONTRACT_TEST_LIB_X_DYN_LINK - #ifdef BOOST_CONTRACT_TEST_LIB_X_SOURCE - #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC BOOST_SYMBOL_EXPORT - #else - #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC BOOST_SYMBOL_IMPORT - #endif -#else - #define BOOST_CONTRACT_TEST_LIB_X_DECLSPEC /* nothing */ -#endif - -#define BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC \ - BOOST_CONTRACT_TEST_LIB_X_DECLSPEC -#include "../detail/out.hpp" - -void BOOST_CONTRACT_TEST_LIB_X_DECLSPEC x(); - -#endif - diff --git a/test/disable/lib_y.cpp b/test/disable/lib_y.cpp deleted file mode 100644 index ba7f4fe5..00000000 --- a/test/disable/lib_y.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Force .cpp never check post/except. -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_NO_POSTCONDITIONS -#endif -#ifndef BOOST_CONTRACT_NO_EXCEPTS - #define BOOST_CONTRACT_NO_EXCEPTS -#endif - -#define BOOST_CONTRACT_TEST_LIB_Y_SOURCE -#include "lib_y.hpp" - -namespace lib_y_ { - void y_body() { - using boost::contract::test::detail::out; - out("y::body\n"); - } -} - diff --git a/test/disable/lib_y.hpp b/test/disable/lib_y.hpp deleted file mode 100644 index c4ab1e82..00000000 --- a/test/disable/lib_y.hpp +++ /dev/null @@ -1,40 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_LIB_Y_HPP_ -#define BOOST_CONTRACT_TEST_LIB_Y_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "lib_x.hpp" -#include -#include -#include - -#ifdef BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK - #ifdef BOOST_CONTRACT_TEST_LIB_Y_SOURCE - #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC BOOST_SYMBOL_EXPORT - #else - #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC BOOST_SYMBOL_IMPORT - #endif -#else - #define BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC /* nothing */ -#endif - -namespace lib_y_ { // Internal namepsace. - void BOOST_CONTRACT_TEST_LIB_Y_DECLSPEC y_body(); -} - -inline void y() { - using boost::contract::test::detail::out; - boost::contract::check c = boost::contract::function() - .precondition([] { out("y::pre\n"); }) - .old([] { out("y::old\n"); }) - .postcondition([] { out("y::post\n"); }) - ; - lib_y_::y_body(); -} - -#endif - diff --git a/test/disable/pre_disable_no_assertion_prog.cpp b/test/disable/pre_disable_no_assertion_prog.cpp deleted file mode 100644 index 6edf3108..00000000 --- a/test/disable/pre_disable_no_assertion_prog.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test pre disable no assertion (in programs, but same for libraries). - -#define BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION -#include "prog.hpp" - diff --git a/test/disable/prog.hpp b/test/disable/prog.hpp deleted file mode 100644 index 2e884368..00000000 --- a/test/disable/prog.hpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "lib_a.hpp" -#include "lib_a_inlined.hpp" -#include "lib_b.hpp" -#include "lib_b_inlined.hpp" -#include "lib_ab.hpp" -#include "../detail/out_inlined.hpp" - diff --git a/test/function/decl.hpp b/test/function/decl.hpp deleted file mode 100644 index 3c3a9760..00000000 --- a/test/function/decl.hpp +++ /dev/null @@ -1,40 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_FUNCTION_DECL_HPP_ -#define BOOST_CONTRACT_TEST_FUNCTION_DECL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with and without pre and post declarations. - -#include "../detail/oteststream.hpp" -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -bool f_pre = true, f_post = true; -void f() { - boost::contract::check c = boost::contract::function() - #ifndef BOOST_CONTRACT_TEST_NO_F_PRE - .precondition([] { - out << "f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(f_pre); - }) - #endif - .old([] { out << "f::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_F_POST - .postcondition([] { - out << "f::post" << std::endl; - BOOST_CONTRACT_ASSERT(f_post); - }) - #endif - ; - out << "f::body" << std::endl; -} - -#endif // #include guard - diff --git a/test/function/decl_post_all.cpp b/test/function/decl_post_all.cpp deleted file mode 100644 index cadbc634..00000000 --- a/test/function/decl_post_all.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_F_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_f() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl // This can fail. - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - f_post = true; - out.str(""); - f(); - ok.str(""); ok // Test nothing failed. - << ok_f() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - f_post = false; - out.str(""); - try { - f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_f() // Test f::post failed. - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/function/decl_post_none.cpp b/test/function/decl_post_none.cpp deleted file mode 100644 index f84f910f..00000000 --- a/test/function/decl_post_none.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test without postconditions. - -#define BOOST_CONTRACT_TEST_NO_F_POST -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - ; - - f_post = true; - out.str(""); - f(); - BOOST_TEST(out.eq(ok.str())); - - f_post = false; - out.str(""); - f(); - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/function/decl_pre_all.cpp b/test/function/decl_pre_all.cpp deleted file mode 100644 index d92e7e2d..00000000 --- a/test/function/decl_pre_all.cpp +++ /dev/null @@ -1,72 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with preconditions. - -#undef BOOST_CONTRACT_TEST_NO_F_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_f(bool failed = false) { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl // Test no failure here. - #endif - ; - if(!failed) ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - f_pre = true; - out.str(""); - f(); - ok.str(""); ok - << ok_f() - ; - BOOST_TEST(out.eq(ok.str())); - - #ifdef BOOST_CONTRACT_NO_PRECONDITIONS - #define BOOST_CONTRACT_TEST_pre 0 - #else - #define BOOST_CONTRACT_TEST_pre 1 - #endif - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - f_pre = false; - out.str(""); - try { - f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_f(BOOST_CONTRACT_TEST_pre) - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_pre - return boost::report_errors(); -} - diff --git a/test/function/decl_pre_none.cpp b/test/function/decl_pre_none.cpp deleted file mode 100644 index 0fc43217..00000000 --- a/test/function/decl_pre_none.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test without preconditions. - -#define BOOST_CONTRACT_TEST_NO_F_PRE -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - - f_pre = true; - out.str(""); - f(); - BOOST_TEST(out.eq(ok.str())); - - f_pre = false; - out.str(""); - f(); - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/function/except_throw.cpp b/test/function/except_throw.cpp deleted file mode 100644 index 66cf4198..00000000 --- a/test/function/except_throw.cpp +++ /dev/null @@ -1,56 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from free function .old(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct err {}; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { - out << "f::old" << std::endl; - throw err(); // Test .old() throws. - }) - .postcondition([] { out << "f::post" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - try { - out.str(""); - f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - #endif - } catch(err const&) { - ok.str(""); ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl // Test this threw. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/function/ifdef.cpp b/test/function/ifdef.cpp deleted file mode 100644 index 057c8aa2..00000000 --- a/test/function/ifdef.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#ifndef BOOST_CONTRACT_NO_FUNCTIONS - #include - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -void f(int x) { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_FUNCTIONS - boost::contract::check c = boost::contract::function() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([] { out << "f::pre" << std::endl; }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - #endif - ; - #endif - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - out.str(""); - f(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - return boost::report_errors(); -} - diff --git a/test/function/ifdef_macro.cpp b/test/function/ifdef_macro.cpp deleted file mode 100644 index 2095dd9e..00000000 --- a/test/function/ifdef_macro.cpp +++ /dev/null @@ -1,95 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off (including EXCEPT, using macro interface). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct except_error {}; - -void f(int x) { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas:: - type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas:: - same(x)) - ); - BOOST_CONTRACT_FUNCTION() - BOOST_CONTRACT_PRECONDITION([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "f::pre" << std::endl; - }) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "f::post" << std::endl; - }) - BOOST_CONTRACT_EXCEPT([] { // Test EXCEPT macro (at least 1 time here). - typedef boost::contract::test::detail::unprotected_commas< - void, void, void> t; - out << "f::except" << std::endl; - }) - ; - out << "f::body" << std::endl; - if(x == -1) throw except_error(); -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - boost::contract::set_except_failure([] (boost::contract::from) {}); - out.str(""); - try { - f(-1); // Test throw and EXCEPT macro (test only here... that's fine). - BOOST_TEST(false); - } catch(except_error const&) {} // OK. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "f::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/function/smoke.cpp b/test/function/smoke.cpp deleted file mode 100644 index f897c1b7..00000000 --- a/test/function/smoke.cpp +++ /dev/null @@ -1,99 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test free function contracts. - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct x_tag; typedef boost::contract::test::detail::counter x_type; -struct y_tag; typedef boost::contract::test::detail::counter y_type; - -bool swap(x_type& x, y_type& y) { - bool result; - boost::contract::old_ptr old_x = - BOOST_CONTRACT_OLDOF(x_type::eval(x)); - boost::contract::old_ptr old_y; - boost::contract::check c = boost::contract::function() - .precondition([&] { - out << "swap::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x.value != y.value); - }) - .old([&] { - out << "swap::old" << std::endl; - old_y = BOOST_CONTRACT_OLDOF(y_type::eval(y)); - }) - .postcondition([&] { - out << "swap::post" << std::endl; - BOOST_CONTRACT_ASSERT(x.value == old_y->value); - BOOST_CONTRACT_ASSERT(y.value == old_x->value); - BOOST_CONTRACT_ASSERT(result == (old_x->value != old_y->value)); - }) - ; - - out << "swap::body" << std::endl; - if(x.value == y.value) return result = false; - int save_x = x.value; - x.value = y.value; - y.value = save_x; - return result = true; -} - -int main() { - std::ostringstream ok; - - { - x_type x; x.value = 123; - y_type y; y.value = 456; - - out.str(""); - bool r = swap(x, y); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "swap::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "swap::old" << std::endl - #endif - << "swap::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "swap::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - BOOST_TEST(r); - BOOST_TEST_EQ(x.value, 456); - BOOST_TEST_EQ(y.value, 123); - } - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(x_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(x_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(x_type::ctors(), x_type::dtors()); // No leak. - - BOOST_TEST_EQ(y_type::copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(y_type::evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(y_type::ctors(), y_type::dtors()); // No leak. - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/function/throwing_body.cpp b/test/function/throwing_body.cpp deleted file mode 100644 index 0b539b55..00000000 --- a/test/function/throwing_body.cpp +++ /dev/null @@ -1,55 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from free function body. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct err {}; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; - throw err(); // Test body throws. -} - -int main() { - std::ostringstream ok; - - try { - out.str(""); - f(); - BOOST_TEST(false); - } catch(err const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl // Test this threw. - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "f::except" << std::endl; - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/function/throwing_old.cpp b/test/function/throwing_old.cpp deleted file mode 100644 index f24641f0..00000000 --- a/test/function/throwing_old.cpp +++ /dev/null @@ -1,59 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from free function .old(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct err {}; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { - out << "f::old" << std::endl; - throw err(); // Test this throws. - }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - try { - out.str(""); - f(); - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl // Test this threw. - #else - << "f::body" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/function/throwing_post.cpp b/test/function/throwing_post.cpp deleted file mode 100644 index 40635fd7..00000000 --- a/test/function/throwing_post.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from free function .post(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct err {}; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { - out << "f::post" << std::endl; - throw err(); // Test this throws. - }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl // Test this threw. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/function/throwing_pre.cpp b/test/function/throwing_pre.cpp deleted file mode 100644 index 7f23472d..00000000 --- a/test/function/throwing_pre.cpp +++ /dev/null @@ -1,63 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from free function .pre(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct err {}; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { - out << "f::pre" << std::endl; - throw err(); // Test this throws. - }) - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl // Test this threw. - #else - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/invariant/decl.hpp b/test/invariant/decl.hpp deleted file mode 100644 index 9e2e05e1..00000000 --- a/test/invariant/decl.hpp +++ /dev/null @@ -1,840 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with and without all invariants (static/cv/const-only) declarations. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b : private boost::contract::constructor_precondition { - // Test also with no base_types. - - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - static void static_invariant() { out << "b::static_inv" << std::endl; } - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - void invariant() const volatile { out << "b::cv_inv" << std::endl; } - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - void invariant() const { out << "b::const_inv" << std::endl; } - #endif - - b() : boost::contract::constructor_precondition([] { - out << "b::ctor::pre" << std::endl; - }) { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "b::ctor::old" << std::endl; }) - .postcondition([] { out << "b::ctor::post" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } - - virtual ~b() { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "b::dtor::old" << std::endl; }) - .postcondition([] { out << "b::dtor::post" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) volatile { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::f::volatile_pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'b'); - }) - .old([] { out << "b::f::volatile_old" << std::endl; }) - .postcondition([] { out << "b::f::volatile_post" << std::endl; }) - ; - out << "b::f::volatile_body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'b'); - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - static void static_invariant() { out << "a::static_inv" << std::endl; } - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - void invariant() const volatile { out << "a::cv_inv" << std::endl; } - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - void invariant() const { out << "a::const_inv" << std::endl; } - #endif - - a() : boost::contract::constructor_precondition([] { - out << "a::ctor::pre" << std::endl; - }) { - boost::contract::check c = boost::contract::constructor(this) - .old([] { out << "a::ctor::old" << std::endl; }) - .postcondition([] { out << "a::ctor::post" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - } - - virtual ~a() { - boost::contract::check c = boost::contract::destructor(this) - .old([] { out << "a::dtor::old" << std::endl; }) - .postcondition([] { out << "a::dtor::post" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) - volatile /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>( - v, - static_cast(&a::f), - this, x - ) - .precondition([&] { - out << "a::f::volatile_pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'a'); - }) - .old([] { out << "a::f::volatile_old" << std::endl; }) - .postcondition([] { out << "a::f::volatile_post" << std::endl; }) - ; - out << "a::f::volatile_body" << std::endl; - } - - virtual void f(char x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>( - v, - static_cast(&a::f), - this, x - ) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x == 'a'); - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - - static void s() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "a::s::pre" << std::endl; }) - .old([] { out << "a::s::old" << std::endl; }) - .postcondition([] { out << "a::s::post" << std::endl; }) - ; - out << "a::s::body" << std::endl; - } - -protected: - void p() volatile { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "a::p::volatile_pre" << std::endl; }) - .old([] { out << "a::p::volatile_old" << std::endl; }) - .postcondition([] { out << "a::p::volatile_post" << std::endl; }) - ; - out << "a::p::volatile_body" << std::endl; - } - - void p() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "a::p::pre" << std::endl; }) - .old([] { out << "a::p::old" << std::endl; }) - .postcondition([] { out << "a::p::post" << std::endl; }) - ; - out << "a::p::body" << std::endl; - } -public: - void call_p() volatile { p(); } - void call_p() { p(); } - -private: - void q() volatile { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "a::q::volatile_pre" << std::endl; }) - .old([] { out << "a::q::volatile_old" << std::endl; }) - .postcondition([] { out << "a::q::volatile_post" << std::endl; }) - ; - out << "a::q::volatile_body" << std::endl; - } - - void q() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "a::q::pre" << std::endl; }) - .old([] { out << "a::q::old" << std::endl; }) - .postcondition([] { out << "a::q::post" << std::endl; }) - ; - out << "a::q::body" << std::endl; - } -public: - void call_q() volatile { q(); } - void call_q() { q(); } - - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - { // Test volatile call with bases. - out.str(""); - a volatile av; - ok.str(""); ok // Ctors always check const_inv (even if volatile). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.f('a'); - ok.str(""); ok // Volatile checks static and cv (but not const) inv. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::volatile_pre" << std::endl - << "a::f::volatile_pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::volatile_old" << std::endl - << "a::f::volatile_old" << std::endl - #endif - << "a::f::volatile_body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::volatile_old" << std::endl - << "b::f::volatile_post" << std::endl - << "a::f::volatile_post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.s(); // Test static call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::s::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::s::old" << std::endl - #endif - << "a::s::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::s::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.call_p(); // Test (indirect) protected call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::p::volatile_pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::p::volatile_old" << std::endl - #endif - << "a::p::volatile_body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::p::volatile_post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - av.call_q(); // Test (indirect) private call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::q::volatile_pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::q::volatile_old" << std::endl - #endif - << "a::q::volatile_body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::q::volatile_post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call a's destructor. - ok.str(""); ok // Dtors always check const_inv (even if volatile). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - { // Test non-volatile call with bases. - out.str(""); - a aa; - ok.str(""); ok // Ctors always check cv_inv (even if not volatile). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f('a'); - ok.str(""); ok // Non-cv checks static and const (but not cv) inv. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.s(); // Test static call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::s::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::s::old" << std::endl - #endif - << "a::s::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::s::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.call_p(); // Test (indirect) protected call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::p::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::p::old" << std::endl - #endif - << "a::p::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::p::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.call_q(); // Test (indirect) private call. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::q::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::q::old" << std::endl - #endif - << "a::q::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::q::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call a's destructor. - ok.str(""); ok // Dtors always check cv_inv (even if not volatile). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "a::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "a::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "a::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - - { // Test volatile call with no bases. - out.str(""); - b volatile bv; - ok.str(""); ok // Ctors always check const_inv (even if volatile). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - bv.f('b'); - ok.str(""); ok // Volatile checks static and cv (but not const) inv. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::volatile_pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::volatile_old" << std::endl - #endif - << "b::f::volatile_body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::volatile_post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call b's destructor. - ok.str(""); ok // Dtors always check const_inv (even if volatile). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - { // Test non-volatile call with no bases. - out.str(""); - b bb; - ok.str(""); ok // Ctors always check cv_inv (even if not volatile). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - bb.f('b'); - ok.str(""); ok // Non-cv checks static and const (but not cv) inv. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call b's destructor. - ok.str(""); ok // Dtors always check cv_inv (even if not volatile). - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CV_INV - << "b::cv_inv" << std::endl - #endif - #ifdef BOOST_CONTRACT_TEST_CONST_INV - << "b::const_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #ifdef BOOST_CONTRACT_TEST_STATIC_INV - << "b::static_inv" << std::endl - #endif - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/invariant/decl_const.cpp b/test/invariant/decl_const.cpp deleted file mode 100644 index 952ddcd8..00000000 --- a/test/invariant/decl_const.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#undef BOOST_CONTRACT_TEST_STATIC_INV -#undef BOOST_CONTRACT_TEST_CV_INV -#define BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_cv.cpp b/test/invariant/decl_cv.cpp deleted file mode 100644 index 1ca7a9fd..00000000 --- a/test/invariant/decl_cv.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#undef BOOST_CONTRACT_TEST_STATIC_INV -#define BOOST_CONTRACT_TEST_CV_INV -#undef BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_cv_const.cpp b/test/invariant/decl_cv_const.cpp deleted file mode 100644 index 30108e2d..00000000 --- a/test/invariant/decl_cv_const.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#undef BOOST_CONTRACT_TEST_STATIC_INV -#define BOOST_CONTRACT_TEST_CV_INV -#define BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_nothing.cpp b/test/invariant/decl_nothing.cpp deleted file mode 100644 index a5af5b44..00000000 --- a/test/invariant/decl_nothing.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#undef BOOST_CONTRACT_TEST_STATIC_INV -#undef BOOST_CONTRACT_TEST_CV_INV -#undef BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_static.cpp b/test/invariant/decl_static.cpp deleted file mode 100644 index bd30b155..00000000 --- a/test/invariant/decl_static.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#define BOOST_CONTRACT_TEST_STATIC_INV -#undef BOOST_CONTRACT_TEST_CV_INV -#undef BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_static_const.cpp b/test/invariant/decl_static_const.cpp deleted file mode 100644 index 7d931126..00000000 --- a/test/invariant/decl_static_const.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#define BOOST_CONTRACT_TEST_STATIC_INV -#undef BOOST_CONTRACT_TEST_CV_INV -#define BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_static_cv.cpp b/test/invariant/decl_static_cv.cpp deleted file mode 100644 index 6730a43a..00000000 --- a/test/invariant/decl_static_cv.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#define BOOST_CONTRACT_TEST_STATIC_INV -#define BOOST_CONTRACT_TEST_CV_INV -#undef BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/decl_static_cv_const.cpp b/test/invariant/decl_static_cv_const.cpp deleted file mode 100644 index c5de6570..00000000 --- a/test/invariant/decl_static_cv_const.cpp +++ /dev/null @@ -1,13 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all invariants (static, cv, and const-only). - -#define BOOST_CONTRACT_TEST_STATIC_INV -#define BOOST_CONTRACT_TEST_CV_INV -#define BOOST_CONTRACT_TEST_CONST_INV -#include "decl.hpp" - diff --git a/test/invariant/ifdef.cpp b/test/invariant/ifdef.cpp deleted file mode 100644 index 2123efdf..00000000 --- a/test/invariant/ifdef.cpp +++ /dev/null @@ -1,174 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test invariant compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class a { -public: - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { - out << "a::static_inv" << std::endl; - } - - void invariant() const volatile { - out << "a::cv_inv" << std::endl; - } - - void invariant() const { - out << "a::const_inv" << std::endl; - } - #endif - - a() { // Test check both cv and const invariant (at exit if no throw). - #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::check c= boost::contract::constructor(this); - #endif - out << "a::ctor::body" << std::endl; - } - - ~a() { // Test check both cv and const invariant (at entry). - #ifndef BOOSTT_CONTRACT_NO_DESTRUCTORS - boost::contract::check c = boost::contract::destructor(this); - #endif - out << "a::dtor::body" << std::endl; - } - - void m() { // Test check const invariant (at entry and exit). - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(this); - #endif - out << "a::m::body" << std::endl; - } - - void c() const { // Test check const invariant (at entry and exit). - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(this); - #endif - out << "a::c::body" << std::endl; - } - - void v() volatile { // Test check cv invariant (at entry and exit). - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(this); - #endif - out << "a::v::body" << std::endl; - } - - void cv() const volatile { // Test check cv invariant (at entry and exit). - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(this); - #endif - out << "a::cv::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - { - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.m(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::m::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.c(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::c::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.v(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - << "a::v::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.cv(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - << "a::cv::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call dtor. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/invariant/ifdef_macro.cpp b/test/invariant/ifdef_macro.cpp deleted file mode 100644 index 24c79552..00000000 --- a/test/invariant/ifdef_macro.cpp +++ /dev/null @@ -1,170 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test invariant compilation on/off (using macro interface). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class a { -public: - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas::type1 t; - out << "a::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT_VOLATILE({ - typedef boost::contract::test::detail::unprotected_commas::type1 t; - out << "a::cv_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas::type1 t; - out << "a::const_inv" << std::endl; - }) - - a() { // Test check both cv and const invariant (at exit if no throw). - BOOST_CONTRACT_CONSTRUCTOR(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::ctor::body" << std::endl; - } - - ~a() { // Test check both cv and const invariant (at entry). - BOOST_CONTRACT_DESTRUCTOR(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::dtor::body" << std::endl; - } - - void m() { // Test check const invariant (at entry and exit). - BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::m::body" << std::endl; - } - - void c() const { // Test check const invariant (at entry and exit). - BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::c::body" << std::endl; - } - - void v() volatile { // Test check cv invariant (at entry and exit). - BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::v::body" << std::endl; - } - - void cv() const volatile { // Test check cv invariant (at entry and exit). - BOOST_CONTRACT_PUBLIC_FUNCTION(boost::contract::test::detail:: - unprotected_commas::same(this)); - out << "a::cv::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - { - out.str(""); - a aa; - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.m(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::m::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.c(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::c::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::const_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.v(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - << "a::v::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.cv(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - << "a::cv::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - } // Call dtor. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::cv_inv" << std::endl - << "a::const_inv" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/invariant/mutable.hpp b/test/invariant/mutable.hpp deleted file mode 100644 index 38682b9c..00000000 --- a/test/invariant/mutable.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if non-static inv declared mutable (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void invariant() {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/mutable_error.cpp b/test/invariant/mutable_error.cpp deleted file mode 100644 index 909b79a9..00000000 --- a/test/invariant/mutable_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test compiler error when invariant() not declared const. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "mutable.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/mutable_permissive.cpp b/test/invariant/mutable_permissive.cpp deleted file mode 100644 index 9c8707a6..00000000 --- a/test/invariant/mutable_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no error if permissive even if invariant() not declared const. - -#define BOOST_CONTRACT_PERMISSIVE -#include "mutable.hpp" - diff --git a/test/invariant/static.hpp b/test/invariant/static.hpp deleted file mode 100644 index 870ec390..00000000 --- a/test/invariant/static.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if non-static inv declared static (unless PERMISSIVE #defined). - -#include -#include - -struct a { - static void invariant() {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/static_const.hpp b/test/invariant/static_const.hpp deleted file mode 100644 index 8bc2d48c..00000000 --- a/test/invariant/static_const.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared const (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void static_invariant() const {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/static_const_error.cpp b/test/invariant/static_const_error.cpp deleted file mode 100644 index 75a7464a..00000000 --- a/test/invariant/static_const_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared const. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "static_const.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/static_const_permissive.cpp b/test/invariant/static_const_permissive.cpp deleted file mode 100644 index 2411d1b8..00000000 --- a/test/invariant/static_const_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no error if permissive even when static inv declared const. - -#define BOOST_CONTRACT_PERMISSIVE -#include "static_const.hpp" - diff --git a/test/invariant/static_cv.hpp b/test/invariant/static_cv.hpp deleted file mode 100644 index 54e83223..00000000 --- a/test/invariant/static_cv.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared cv (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void static_invariant() const volatile {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/static_cv_error.cpp b/test/invariant/static_cv_error.cpp deleted file mode 100644 index aec2e598..00000000 --- a/test/invariant/static_cv_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared cv. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "static_cv.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/static_cv_permissive.cpp b/test/invariant/static_cv_permissive.cpp deleted file mode 100644 index b45627f6..00000000 --- a/test/invariant/static_cv_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no error if permissive even when static inv declared cv. - -#define BOOST_CONTRACT_PERMISSIVE -#include "static_cv.hpp" - diff --git a/test/invariant/static_error.cpp b/test/invariant/static_error.cpp deleted file mode 100644 index 3fd42f68..00000000 --- a/test/invariant/static_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test compiler error if invariant() declared static. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "static.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/static_mutable.hpp b/test/invariant/static_mutable.hpp deleted file mode 100644 index 0a67f40f..00000000 --- a/test/invariant/static_mutable.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared mutable (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void static_invariant() {} // Error (unless PERMISSIVE). - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/static_mutable_error.cpp b/test/invariant/static_mutable_error.cpp deleted file mode 100644 index 3ec20282..00000000 --- a/test/invariant/static_mutable_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared mutable. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "static_mutable.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/static_mutable_permissive.cpp b/test/invariant/static_mutable_permissive.cpp deleted file mode 100644 index 7c96dcf5..00000000 --- a/test/invariant/static_mutable_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if permissive even when static inv declared mutable. - -#define BOOST_CONTRACT_PERMISSIVE -#include "static_mutable.hpp" - diff --git a/test/invariant/static_permissive.cpp b/test/invariant/static_permissive.cpp deleted file mode 100644 index 09fe997a..00000000 --- a/test/invariant/static_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no compiler error if permissive even when invariant() declared static. - -#define BOOST_CONTRACT_PERMISSIVE -#include "static.hpp" - diff --git a/test/invariant/static_volatile.hpp b/test/invariant/static_volatile.hpp deleted file mode 100644 index 4f02f799..00000000 --- a/test/invariant/static_volatile.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared volatile (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void static_invariant() volatile {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/static_volatile_error.cpp b/test/invariant/static_volatile_error.cpp deleted file mode 100644 index 96a7f78d..00000000 --- a/test/invariant/static_volatile_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if static inv declared volatile. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "static_volatile.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/static_volatile_permissive.cpp b/test/invariant/static_volatile_permissive.cpp deleted file mode 100644 index afc91706..00000000 --- a/test/invariant/static_volatile_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if permissive even when static inv declared volatile. - -#define BOOST_CONTRACT_PERMISSIVE -#include "static_volatile.hpp" - diff --git a/test/invariant/volatile.hpp b/test/invariant/volatile.hpp deleted file mode 100644 index 08a2c1ad..00000000 --- a/test/invariant/volatile.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if non-static inv declared volatile (unless PERMISSIVE #defined). - -#include -#include - -struct a { - void invariant() volatile {} - - void f() { - // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::check c = boost::contract::public_function(this); - } -}; - -int main() { - a aa; - aa.f(); - return 0; -}; - diff --git a/test/invariant/volatile_error.cpp b/test/invariant/volatile_error.cpp deleted file mode 100644 index 5326c2a1..00000000 --- a/test/invariant/volatile_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if non-static inv declared volatile. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "volatile.hpp" -#ifdef BOOST_CONTRACT_NO_INVARIANTS - #error "Forcing error even when invariants not checked" -#endif - diff --git a/test/invariant/volatile_permissive.cpp b/test/invariant/volatile_permissive.cpp deleted file mode 100644 index d5ac634e..00000000 --- a/test/invariant/volatile_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no error if permissive even when non-static inv declared volatile. - -#define BOOST_CONTRACT_PERMISSIVE -#include "volatile.hpp" - diff --git a/test/old/auto.cpp b/test/old/auto.cpp deleted file mode 100644 index cdc5d99e..00000000 --- a/test/old/auto.cpp +++ /dev/null @@ -1,42 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test that OLD macro allows to use C++11 auto declarations. - -#include -#ifndef BOOST_NO_CXX11_AUTO_DECLARATIONS - #include - #include - #include - #include -#endif - -int main() { - #ifndef BOOST_NO_CXX11_AUTO_DECLARATIONS - int x = -123; - auto old_x = BOOST_CONTRACT_OLDOF(x); - x = 123; - BOOST_STATIC_ASSERT(boost::is_same >::value); - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST_EQ(*old_x, -123); - #endif - BOOST_TEST_EQ(x, 123); - - boost::contract::virtual_* v = 0; - char y = 'j'; - auto old_y = BOOST_CONTRACT_OLDOF(v, y); - y = 'k'; - BOOST_STATIC_ASSERT(boost::is_same >::value); - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST_EQ(*old_y, 'j'); - #endif - BOOST_TEST_EQ(y, 'k'); - #endif // Else, nothing to test. - return boost::report_errors(); -} - diff --git a/test/old/copyable_traits.cpp b/test/old/copyable_traits.cpp deleted file mode 100644 index 4135bb5f..00000000 --- a/test/old/copyable_traits.cpp +++ /dev/null @@ -1,106 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specializations of old value copy type traits. - -#include -#include -#include -#include -#include - -template -void f(T& x) { - boost::contract::old_ptr_if_copyable old_x = BOOST_CONTRACT_OLDOF(x); -} - -// Test copyable type but... -struct w { - w() {} - w(w const&) { BOOST_TEST(false); } // Test this doesn't get copied. -}; - -// ...never copy old values for type `w` (because its copy is too expensive). -namespace boost { namespace contract { - template<> - struct is_old_value_copyable : boost::false_type {}; -} } // namespace - -// Test non-copyable type but... -struct p : private boost::noncopyable { // Non-copyable via Boost. - static bool copied; - p() : num_(new int(0)) {} - ~p() { delete num_; } -private: - int* num_; - friend struct boost::contract::old_value_copy

; -}; -bool p::copied = false; - -// ...still copy old values for type `p` (using a deep copy). -namespace boost { namespace contract { - template<> - struct old_value_copy

{ - explicit old_value_copy(p const& old) { - *old_.num_ = *old.num_; // Deep copy pointed value. - p::copied = true; - } - - p const& old() const { return old_; } - - private: - p old_; - }; - - template<> - struct is_old_value_copyable

: boost::true_type {}; -} } // namespace - -// Non-copyable type so... -struct n { - n() {} -private: - n(n const&); // Non-copyable (but not via Boost). -}; - -// ...specialize `boost::is_copy_constructible` (no need for this on C++11). -namespace boost { namespace contract { - template<> - struct is_old_value_copyable : boost::false_type {}; -} } // namespace - -int main() { - // NOTE: No test::detail::counter below because that is for copyable types. - - { - int x; // Test has copy ctor so copy olds. - f(x); - } - - { - w x; // Test has copy ctor but never copy olds (see TEST(...) above). - f(x); - } - - p::copied = false; - { - p x; // Test no copy ctor but still old copies. - f(x); - } - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(p::copied); - #else - BOOST_TEST(!p::copied); - #endif - - { - n x; // Test no copy ctor so no old copies. - f(x); - } - - return boost::report_errors(); -} - diff --git a/test/old/if_copyable.cpp b/test/old/if_copyable.cpp deleted file mode 100644 index 5a8a1fd6..00000000 --- a/test/old/if_copyable.cpp +++ /dev/null @@ -1,133 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old values of non-copyable types. - -#include "if_copyable.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -unsigned old_checks; - -template -struct b { - virtual void next(T& x, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr_if_copyable old_x = - BOOST_CONTRACT_OLDOF(v, x); - boost::contract::check c = boost::contract::public_function(v, this) - .postcondition([&] { - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; - } - BOOST_CONTRACT_OVERRIDE(next) -}; - -template -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual void next(T& x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr_if_copyable old_x = - BOOST_CONTRACT_OLDOF(v, x); - boost::contract::check c = boost::contract::public_function< - override_next>(v, &a::next, this, x) - .postcondition([&] { - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; - } - BOOST_CONTRACT_OVERRIDE(next) -}; - -template -void next(T& x) { - boost::contract::old_ptr_if_copyable old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::check c = boost::contract::function() - .postcondition([&] { - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; -} - -int main() { - int i = 1; // Test built-in copyable type. - cp c(1); // Test custom copyable type. - ncp n(1); // Test non-copyable type. - - // Test free functions (old values without `v`). - - unsigned cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 1 - #else - 0 - #endif - ; - - old_checks = 0; - next(i); - BOOST_TEST_EQ(old_checks, cnt); - - old_checks = 0; - next(c); - BOOST_TEST_EQ(old_checks, cnt); - - old_checks = 0; - next(n); - BOOST_TEST_EQ(old_checks, 0u); - - // Test virtual functions (old values with `v`). - - cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 2 - #else - 0 - #endif - ; - - a ai; - old_checks = 0; - ai.next(i); - BOOST_TEST_EQ(old_checks, cnt); - - a ac; - old_checks = 0; - ac.next(c); - BOOST_TEST_EQ(old_checks, cnt); - - a an; - old_checks = 0; - an.next(n); - BOOST_TEST_EQ(old_checks, 0u); - - return boost::report_errors(); -} - diff --git a/test/old/if_copyable.hpp b/test/old/if_copyable.hpp deleted file mode 100644 index 3b7ef30d..00000000 --- a/test/old/if_copyable.hpp +++ /dev/null @@ -1,45 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_IF_COPYABLE_HPP_ -#define BOOST_CONTRACT_TEST_IF_COPYABLE_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old values of non-copyable types. - -#define BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(class_) \ - public: \ - explicit class_(int value) : value_(value) {} \ - \ - friend class_& operator++(class_& me) { ++me.value_; return me; } \ - \ - friend bool operator>(class_ const& left, class_ const& right) { \ - return left.value_ > right.value_; \ - } \ - \ - friend bool operator==(class_ const& left, class_ const& right) { \ - return left.value_ == right.value_; \ - } \ - \ - friend class_ operator+(class_ const& left, class_ const& right) { \ - return class_(left.value_ + right.value_); \ - } \ - \ - private: \ - int value_; - -struct cp { // Copyable type. - BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(cp) -}; - -struct ncp { - BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(ncp) - -private: // Non (publicly) copyable type. - ncp(ncp const& other) : value_(other.value_) {} -}; - -#endif // #include guard - diff --git a/test/old/if_copyable_error.cpp b/test/old/if_copyable_error.cpp deleted file mode 100644 index 3c7da94c..00000000 --- a/test/old/if_copyable_error.cpp +++ /dev/null @@ -1,43 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test forcing compiler error for old values of non-copyable types. - -#include "if_copyable.hpp" -#include -#include -#include -#include -#include - - -template -void next(T& x) { - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::check c = boost::contract::function() - .postcondition([&] { - // No need to check `if(old_x) ...` here. - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - #ifdef BOOST_CONTRACT_NO_ALL - #error "force error if no contracts (ASSERT expands to nothing)" - #endif - }) - ; - ++x; -} - -int main() { - int i = 1; // Test built-in copyable type. - cp c(1); // Test custom copyable type. - ncp n(1); // Test non-copyable type. - - next(i); // OK. - next(c); // OK. - next(n); // Error. - - return 0; -} - diff --git a/test/old/if_copyable_macro.cpp b/test/old/if_copyable_macro.cpp deleted file mode 100644 index af252bb6..00000000 --- a/test/old/if_copyable_macro.cpp +++ /dev/null @@ -1,172 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old values of non-copyable types (using macro interface). - -#include "if_copyable.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include - -unsigned old_checks; - -template -struct b { - virtual void next(T& x, boost::contract::virtual_* v = 0) { - BOOST_CONTRACT_OLD_PTR_IF_COPYABLE( - typename boost::contract::test::detail::unprotected_commas::type1 - )( - (boost::contract::test::detail::unprotected_commas::same(v)), - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_PUBLIC_FUNCTION( - boost::contract::test::detail::unprotected_commas::same(v), - boost::contract::test::detail::unprotected_commas::same(this) - ) - BOOST_CONTRACT_POSTCONDITION([&] { - typedef boost::contract::test::detail::unprotected_commas t; - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; - } - BOOST_CONTRACT_OVERRIDE(next) -}; - -template -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual void next(T& x, boost::contract::virtual_* v = 0) /* override */ { - BOOST_CONTRACT_OLD_PTR_IF_COPYABLE( - typename boost::contract::test::detail::unprotected_commas::type1 - )( - (boost::contract::test::detail::unprotected_commas::same(v)), - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE( - typename boost::contract::test::detail::unprotected_commas< - override_next, void, void>::type1 - )( - boost::contract::test::detail::unprotected_commas::same(v), - &a::next, - boost::contract::test::detail::unprotected_commas::same(this), - boost::contract::test::detail::unprotected_commas::same(x) - ) - BOOST_CONTRACT_POSTCONDITION([&] { - typedef boost::contract::test::detail::unprotected_commas t; - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; - } - BOOST_CONTRACT_OVERRIDE(next) -}; - -template -void next(T& x) { - BOOST_CONTRACT_OLD_PTR_IF_COPYABLE( - typename boost::contract::test::detail::unprotected_commas::type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_FUNCTION() - BOOST_CONTRACT_POSTCONDITION([&] { - typedef boost::contract::test::detail::unprotected_commas t; - if(old_x) { - BOOST_CONTRACT_ASSERT(x == *old_x + T(1)); - ++old_checks; - } - }) - ; - ++x; -} - -int main() { - int i = 1; // Test built-in copyable type. - cp c(1); // Test custom copyable type. - ncp n(1); // Test non-copyable type. - - // Test free functions (old values without `v`). - - unsigned cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 1 - #else - 0 - #endif - ; - - old_checks = 0; - next(i); - BOOST_TEST_EQ(old_checks, cnt); - - old_checks = 0; - next(c); - BOOST_TEST_EQ(old_checks, cnt); - - old_checks = 0; - next(n); - BOOST_TEST_EQ(old_checks, 0u); - - // Test virtual functions (old values with `v`). - - cnt = - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - 2 - #else - 0 - #endif - ; - - a ai; - old_checks = 0; - ai.next(i); - BOOST_TEST_EQ(old_checks, cnt); - - a ac; - old_checks = 0; - ac.next(c); - BOOST_TEST_EQ(old_checks, cnt); - - a an; - old_checks = 0; - an.next(n); - BOOST_TEST_EQ(old_checks, 0u); - - return boost::report_errors(); -} - diff --git a/test/old/no_macro.cpp b/test/old/no_macro.cpp deleted file mode 100644 index 0efc4dd7..00000000 --- a/test/old/no_macro.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr -#include "no_macro.hpp" - diff --git a/test/old/no_macro.hpp b/test/old/no_macro.hpp deleted file mode 100644 index b8091482..00000000 --- a/test/old/no_macro.hpp +++ /dev/null @@ -1,190 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old values without BOOST_CONTRACT_OLD macro. - -#ifndef BOOST_CONTRACT_TEST_OLD_PTR_TYPE - #error "must define BOOST_CONTRACT_TEST_OLD_PTR_TYPE" -#endif - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct i_tag; typedef boost::contract::test::detail::counter i_type; -struct j_tag; typedef boost::contract::test::detail::counter j_type; - -struct b { - virtual void swap(i_type& i, j_type& j, boost::contract::virtual_* v = 0); -}; - -void b::swap(i_type& i, j_type& j, boost::contract::virtual_* v) { - BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_i = boost::contract::make_old( - v, boost::contract::copy_old(v) ? - i_type::eval(i) - : - boost::contract::null_old() - ); - BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_j; - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::swap::pre" << std::endl; - BOOST_CONTRACT_ASSERT(i.value != j.value); - }) - .old([&] { - out << "b::swap::old" << std::endl; - old_j = boost::contract::make_old(v, boost::contract::copy_old(v) ? - j_type::eval(j) : boost::contract::null_old()); - }) - .postcondition([&] { - out << "b::swap::post" << std::endl; - BOOST_CONTRACT_ASSERT(i.value == old_j->value); - BOOST_CONTRACT_ASSERT(j.value == old_i->value); - }) - ; - assert(false); -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void swap(i_type& i, j_type& j, boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::check c = boost::contract::public_function< - override_swap>(v, &a::swap, this, i, j); - - out << "a::swap::body" << std::endl; - int t = i.value; - i.value = j.value; - j.value = t; - } - BOOST_CONTRACT_OVERRIDE(swap) -}; - -struct x_tag; -typedef boost::contract::test::detail::counter x_type; - -struct y_tag; -typedef boost::contract::test::detail::counter y_type; - -void swap(x_type& x, y_type& y) { - BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_x = boost::contract::make_old( - boost::contract::copy_old() ? - x_type::eval(x) - : - boost::contract::null_old() - ); - BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_y; - boost::contract::check c = boost::contract::function() - .precondition([&] { - out << "swap::pre" << std::endl; - BOOST_CONTRACT_ASSERT(x.value != y.value); - }) - .old([&] { - out << "swap::old" << std::endl; - old_y = boost::contract::make_old(boost::contract::copy_old() ? - y_type::eval(y) : boost::contract::null_old()); - }) - .postcondition([&] { - out << "swap::post" << std::endl; - BOOST_CONTRACT_ASSERT(x.value == old_y->value); - BOOST_CONTRACT_ASSERT(y.value == old_x->value); - }) - ; - - out << "swap::body" << std::endl; - char t = x.value; - x.value = y.value; - y.value = t; -} - -int main() { - std::ostringstream ok; - - out.str(""); - x_type x; x.value = 'a'; - y_type y; y.value = 'b'; - swap(x, y); - - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "swap::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "swap::old" << std::endl - #endif - << "swap::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "swap::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(x.value, 'b'); - BOOST_TEST_EQ(x.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(x.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(x.ctors(), x.dtors() + 1); // 1 for local var. - - BOOST_TEST_EQ(y.value, 'a'); - BOOST_TEST_EQ(y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(y.ctors(), y.dtors() + 1); // 1 for local var. - - a aa; - i_type i; i.value = 1; - j_type j; j.value = 2; - out.str(""); - aa.swap(i, j); - - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::swap::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::swap::old" << std::endl - #endif - << "a::swap::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::swap::old" << std::endl - << "b::swap::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - BOOST_TEST_EQ(i.value, 2); - BOOST_TEST_EQ(i.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(i.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(i.ctors(), i.dtors() + 1); // 1 for local var. - - BOOST_TEST_EQ(j.value, 1); - BOOST_TEST_EQ(j.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(j.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(j.ctors(), j.dtors() + 1); // 1 for local var. - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/old/no_macro_if_copyable.cpp b/test/old/no_macro_if_copyable.cpp deleted file mode 100644 index 7863de4e..00000000 --- a/test/old/no_macro_if_copyable.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_if_copyable -#include "no_macro.hpp" - diff --git a/test/old/no_make_old_error.cpp b/test/old/no_make_old_error.cpp deleted file mode 100644 index 77fdc54d..00000000 --- a/test/old/no_make_old_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr -#include "no_make_old_error.hpp" - diff --git a/test/old/no_make_old_error.hpp b/test/old/no_make_old_error.hpp deleted file mode 100644 index 1d47cbe7..00000000 --- a/test/old/no_make_old_error.hpp +++ /dev/null @@ -1,21 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error when make_old(...) not used by mistake. - -#ifndef BOOST_CONTRACT_TEST_OLD_PTR_TYPE - #error "must define BOOST_CONTRACT_TEST_OLD_PTR_TYPE" -#endif - -#include - -int main() { - int x = 1; - BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_x = boost::contract::copy_old() ? - x : boost::contract::null_old(); // Error (missing make_old(...)). - return 0; -} - diff --git a/test/old/no_make_old_if_copyable_error.cpp b/test/old/no_make_old_if_copyable_error.cpp deleted file mode 100644 index 8f57f34c..00000000 --- a/test/old/no_make_old_if_copyable_error.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_if_copyable -#include "no_make_old_error.hpp" - diff --git a/test/public_function/access.cpp b/test/public_function/access.cpp deleted file mode 100644 index 29216f5d..00000000 --- a/test/public_function/access.cpp +++ /dev/null @@ -1,136 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test making all contract extra declarations (base types, inv, etc.) private. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class b { - friend class boost::contract::access; - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - -public: - virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'b'); - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } -}; - -class a - #define BASES public b - : BASES -{ - friend class boost::contract::access; - - // Private base types. - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // Private invariants. - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - // Private override (always possible even when access is not friend). - BOOST_CONTRACT_OVERRIDE(f) - -public: - virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this, ch) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'a'); - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - a aa; - out.str(""); - aa.f('a'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - b bb; - out.str(""); - bb.f('b'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/decl.hpp b/test/public_function/decl.hpp deleted file mode 100644 index 4a4d867b..00000000 --- a/test/public_function/decl.hpp +++ /dev/null @@ -1,162 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_PUBLIC_FUNCTION_DECL_HPP_ -#define BOOST_CONTRACT_TEST_PUBLIC_FUNCTION_DECL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with and without pre, post, and inv declarations. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -bool c_pre = true, c_post = true; -bool c_entering_static_inv = true, c_entry_static_inv = true, - c_exit_static_inv = true; -bool c_entering_inv = true, c_entry_inv = true, c_exit_inv = true; -struct c { - #ifndef BOOST_CONTRACT_TEST_NO_C_STATIC_INV - static void static_invariant() { - out << "c::static_inv" << std::endl; - if(c_entering_static_inv) BOOST_CONTRACT_ASSERT(c_entry_static_inv); - else BOOST_CONTRACT_ASSERT(c_exit_static_inv); - c_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_C_INV - void invariant() const { - out << "c::inv" << std::endl; - if(c_entering_inv) BOOST_CONTRACT_ASSERT(c_entry_inv); - else BOOST_CONTRACT_ASSERT(c_exit_inv); - c_entering_inv = false; - } - #endif - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - #ifndef BOOST_CONTRACT_TEST_NO_C_PRE - .precondition([] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(c_pre); - }) - #endif - .old([] { out << "c::f::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_C_POST - .postcondition([] { - out << "c::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(c_post); - }) - #endif - ; - out << "c::f::body" << std::endl; - } -}; - -bool b_pre = true, b_post = true; -bool b_entering_static_inv = true, b_entry_static_inv = true, - b_exit_static_inv = true; -bool b_entering_inv = true, b_entry_inv = true, b_exit_inv = true; -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_B_STATIC_INV - static void static_invariant() { - out << "b::static_inv" << std::endl; - if(b_entering_static_inv) BOOST_CONTRACT_ASSERT(b_entry_static_inv); - else BOOST_CONTRACT_ASSERT(b_exit_static_inv); - b_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_B_INV - void invariant() const { - out << "b::inv" << std::endl; - if(b_entering_inv) BOOST_CONTRACT_ASSERT(b_entry_inv); - else BOOST_CONTRACT_ASSERT(b_exit_inv); - b_entering_inv = false; - } - #endif - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - #ifndef BOOST_CONTRACT_TEST_NO_B_PRE - .precondition([] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(b_pre); - }) - #endif - .old([] { out << "b::f::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_B_POST - .postcondition([] { - out << "b::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(b_post); - }) - #endif - ; - out << "a::f::body" << std::endl; - } -}; - -bool a_pre = true, a_post = true; -bool a_entering_static_inv = true, a_entry_static_inv = true, - a_exit_static_inv = true; -bool a_entering_inv = true, a_entry_inv = true, a_exit_inv = true; -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - #ifndef BOOST_CONTRACT_TEST_NO_A_STATIC_INV - static void static_invariant() { - out << "a::static_inv" << std::endl; - if(a_entering_static_inv) BOOST_CONTRACT_ASSERT(a_entry_static_inv); - else BOOST_CONTRACT_ASSERT(a_exit_static_inv); - a_entering_static_inv = false; - } - #endif - #ifndef BOOST_CONTRACT_TEST_NO_A_INV - void invariant() const { - out << "a::inv" << std::endl; - if(a_entering_inv) BOOST_CONTRACT_ASSERT(a_entry_inv); - else BOOST_CONTRACT_ASSERT(a_exit_inv); - a_entering_inv = false; - } - #endif - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - #ifndef BOOST_CONTRACT_TEST_NO_A_PRE - .precondition([] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(a_pre); - }) - #endif - .old([] { out << "a::f::old" << std::endl; }) - #ifndef BOOST_CONTRACT_TEST_NO_A_POST - .postcondition([] { - out << "a::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(a_post); - }) - #endif - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -#endif // #include guard - diff --git a/test/public_function/decl_entry_inv_all.cpp b/test/public_function/decl_entry_inv_all.cpp deleted file mode 100644 index 7a28459a..00000000 --- a/test/public_function/decl_entry_inv_all.cpp +++ /dev/null @@ -1,184 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with entry invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_inv_ends.cpp b/test/public_function/decl_entry_inv_ends.cpp deleted file mode 100644 index 79b50bb2..00000000 --- a/test/public_function/decl_entry_inv_ends.cpp +++ /dev/null @@ -1,178 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with entry invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_inv_mid.cpp b/test/public_function/decl_entry_inv_mid.cpp deleted file mode 100644 index efdad981..00000000 --- a/test/public_function/decl_entry_inv_mid.cpp +++ /dev/null @@ -1,171 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this fail. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did). - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_inv_none.cpp b/test/public_function/decl_entry_inv_none.cpp deleted file mode 100644 index f7f6138a..00000000 --- a/test/public_function/decl_entry_inv_none.cpp +++ /dev/null @@ -1,105 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without entry invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; - ok.str(""); ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = false; - b_entry_inv = true; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = true; - b_entry_inv = false; - c_entry_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = true; - b_entry_inv = true; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_inv = false; - b_entry_inv = false; - c_entry_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_static_inv_all.cpp b/test/public_function/decl_entry_static_inv_all.cpp deleted file mode 100644 index eaffbbc0..00000000 --- a/test/public_function/decl_entry_static_inv_all.cpp +++ /dev/null @@ -1,182 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with entry static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - // Test this failed (as all did). - << "c::static_inv" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_static_inv_ends.cpp b/test/public_function/decl_entry_static_inv_ends.cpp deleted file mode 100644 index f7a7d893..00000000 --- a/test/public_function/decl_entry_static_inv_ends.cpp +++ /dev/null @@ -1,197 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with entry static inv. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl // Test this failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - // Test this failed (as all did). - << "c::static_inv" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_static_inv_mid.cpp b/test/public_function/decl_entry_static_inv_mid.cpp deleted file mode 100644 index cb790ba0..00000000 --- a/test/public_function/decl_entry_static_inv_mid.cpp +++ /dev/null @@ -1,168 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_entry_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this fail. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv =true; - out.str(""); - try { - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - // Test this failed (as all did). - << "b::static_inv" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_entry_static_inv_none.cpp b/test/public_function/decl_entry_static_inv_none.cpp deleted file mode 100644 index 44a10433..00000000 --- a/test/public_function/decl_entry_static_inv_none.cpp +++ /dev/null @@ -1,104 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without entry static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = false; - b_entry_static_inv = true; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = true; - b_entry_static_inv = false; - c_entry_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = true; - b_entry_static_inv = true; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_entry_static_inv = false; - b_entry_static_inv = false; - c_entry_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_inv_all.cpp b/test/public_function/decl_exit_inv_all.cpp deleted file mode 100644 index 6b21acd0..00000000 --- a/test/public_function/decl_exit_inv_all.cpp +++ /dev/null @@ -1,195 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with exit invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_inv_ends.cpp b/test/public_function/decl_exit_inv_ends.cpp deleted file mode 100644 index 9172bf4e..00000000 --- a/test/public_function/decl_exit_inv_ends.cpp +++ /dev/null @@ -1,188 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with exit invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#undef BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl // Test this failed (as all did). - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_inv_mid.cpp b/test/public_function/decl_exit_inv_mid.cpp deleted file mode 100644 index a49e8335..00000000 --- a/test/public_function/decl_exit_inv_mid.cpp +++ /dev/null @@ -1,186 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with exit invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#undef BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - // Test no failure here. - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = false; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl // Test this failed (as all did). - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_inv_none.cpp b/test/public_function/decl_exit_inv_none.cpp deleted file mode 100644 index 8632c048..00000000 --- a/test/public_function/decl_exit_inv_none.cpp +++ /dev/null @@ -1,109 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without exit invariants. - -#define BOOST_CONTRACT_TEST_NO_A_INV -#define BOOST_CONTRACT_TEST_NO_B_INV -#define BOOST_CONTRACT_TEST_NO_C_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; - ok.str(""); ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - // No invariants. - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "b::static_inv" << std::endl - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a aa; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_inv = false; - b_exit_inv = true; - c_exit_inv = true; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_inv = true; - b_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_inv = true; - b_exit_inv = true; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_inv = false; - b_exit_inv = false; - c_exit_inv = false; - a_entering_inv = b_entering_inv = c_entering_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_static_inv_all.cpp b/test/public_function/decl_exit_static_inv_all.cpp deleted file mode 100644 index ad3a0eb3..00000000 --- a/test/public_function/decl_exit_static_inv_all.cpp +++ /dev/null @@ -1,194 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - // Test this failed (as all did). - << "c::static_inv" << std::endl - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_static_inv_ends.cpp b/test/public_function/decl_exit_static_inv_ends.cpp deleted file mode 100644 index dea52373..00000000 --- a/test/public_function/decl_exit_static_inv_ends.cpp +++ /dev/null @@ -1,190 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with exit static invariants. - -#undef BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - // Test no failure here. - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - // Test this failed (as all did). - << "c::static_inv" << std::endl - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_static_inv_mid.cpp b/test/public_function/decl_exit_static_inv_mid.cpp deleted file mode 100644 index 672be0b7..00000000 --- a/test/public_function/decl_exit_static_inv_mid.cpp +++ /dev/null @@ -1,189 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#undef BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - // Test no failure here. - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::static_inv" << std::endl // Test this failed. - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - // Test no failure here. - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - // Test this failed (as all did). - << "b::static_inv" << std::endl - #elif !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_exit_static_inv_none.cpp b/test/public_function/decl_exit_static_inv_none.cpp deleted file mode 100644 index 8ece28da..00000000 --- a/test/public_function/decl_exit_static_inv_none.cpp +++ /dev/null @@ -1,109 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without exit static invariants. - -#define BOOST_CONTRACT_TEST_NO_A_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_B_STATIC_INV -#define BOOST_CONTRACT_TEST_NO_C_STATIC_INV -#include "decl.hpp" - -#include -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - // No static invariants. - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - - struct err {}; - boost::contract::set_exit_invariant_failure( - [] (boost::contract::from) { throw err(); }); - - #ifdef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 0 - #else - #define BOOST_CONTRACT_TEST_entry_inv 1 - #endif - - a aa; - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = false; - b_exit_static_inv = true; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = true; - b_exit_static_inv = false; - c_exit_static_inv = true; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = true; - b_exit_static_inv = true; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_exit_static_inv = false; - b_exit_static_inv = false; - c_exit_static_inv = false; - a_entering_static_inv = b_entering_static_inv = c_entering_static_inv = - BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - #undef BOOST_CONTRACT_TEST_entry_inv - return boost::report_errors(); -} - diff --git a/test/public_function/decl_post_all.cpp b/test/public_function/decl_post_all.cpp deleted file mode 100644 index 8548df52..00000000 --- a/test/public_function/decl_post_all.cpp +++ /dev/null @@ -1,162 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed (as all did). - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_post_ends.cpp b/test/public_function/decl_post_ends.cpp deleted file mode 100644 index 68e3d6c9..00000000 --- a/test/public_function/decl_post_ends.cpp +++ /dev/null @@ -1,157 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with postconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#undef BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "a::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - // Test no failure here. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl // Test this failed (as all did). - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_post_mid.cpp b/test/public_function/decl_post_mid.cpp deleted file mode 100644 index 2352f2b4..00000000 --- a/test/public_function/decl_post_mid.cpp +++ /dev/null @@ -1,153 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#undef BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_post = false; - b_post = true; - c_post = true; - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // Test no failure here. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = false; - c_post = true; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = true; - b_post = true; - c_post = false; - out.str(""); - try { - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - // Test no failure here. - << "b::f::old" << std::endl - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_post = false; - b_post = false; - c_post = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this failed (as all did). - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_post_none.cpp b/test/public_function/decl_post_none.cpp deleted file mode 100644 index 99ccb600..00000000 --- a/test/public_function/decl_post_none.cpp +++ /dev/null @@ -1,90 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without postconditions. - -#define BOOST_CONTRACT_TEST_NO_A_POST -#define BOOST_CONTRACT_TEST_NO_B_POST -#define BOOST_CONTRACT_TEST_NO_C_POST -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No postconditions. - << "c::f::old" << std::endl - << "b::f::old" << std::endl - #endif - ; - - a aa; - - a_post = true; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_post = false; - b_post = true; - c_post = true; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_post = true; - b_post = false; - c_post = true; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_post = true; - b_post = true; - c_post = false; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_post = false; - b_post = false; - c_post = false; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_pre_all.cpp b/test/public_function/decl_pre_all.cpp deleted file mode 100644 index 132d1b7c..00000000 --- a/test/public_function/decl_pre_all.cpp +++ /dev/null @@ -1,153 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes with preconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_PRE -#undef BOOST_CONTRACT_TEST_NO_B_PRE -#undef BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl // Old only if post (or except) run. - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_pre = true; - b_pre = true; - c_pre = true; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl // Test only c::f::pre checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = true; - b_pre = false; - c_pre = false; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl // Test all pre checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = true; - c_pre = false; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - // Test only a::f::pre not checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = false; - c_pre = true; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl // Test only c::f::pre checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = false; - b_pre = false; - c_pre = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl // Test all pre checked and failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_pre_ends.cpp b/test/public_function/decl_pre_ends.cpp deleted file mode 100644 index 7affc903..00000000 --- a/test/public_function/decl_pre_ends.cpp +++ /dev/null @@ -1,158 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only derived and grandparent classes (ends) with preconditions. - -#undef BOOST_CONTRACT_TEST_NO_A_PRE -#define BOOST_CONTRACT_TEST_NO_B_PRE -#undef BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl // Old only if post (or except) run. - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_pre = true; - b_pre = true; - c_pre = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl // Test only c pre checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = true; - b_pre = false; - c_pre = false; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - // Test b's pre not checked. - << "a::f::pre" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = false; - c_pre = true; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl // Test only c pre checked. - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = false; - b_pre = true; - c_pre = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl // Only ends pre checked and failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = false; - b_pre = false; - c_pre = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl // Only ends pre checked and failed. - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_pre_mid.cpp b/test/public_function/decl_pre_mid.cpp deleted file mode 100644 index af14158b..00000000 --- a/test/public_function/decl_pre_mid.cpp +++ /dev/null @@ -1,165 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test only middle base class with preconditions. - -#define BOOST_CONTRACT_TEST_NO_A_PRE -#undef BOOST_CONTRACT_TEST_NO_B_PRE -#define BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include -#include - -std::string ok_begin() { - std::ostringstream ok; ok << "" // Suppress a warning. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - ; - return ok.str(); -} - -std::string ok_end() { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl // Old only if post (or except) run. - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - - a aa; - - a_pre = true; - b_pre = true; - c_pre = true; - out.str(""); - aa.f(); - ok.str(""); ok // Test nothing failed. - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = true; - c_pre = false; - out.str(""); - aa.f(); - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - // Test only middle pre checked and no fail. - << "b::f::pre" << std::endl - #endif - << ok_end() - ; - BOOST_TEST(out.eq(ok.str())); - - struct err {}; - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw err(); }); - - a_pre = true; - b_pre = false; - c_pre = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - // Test only middle pre checked and failed. - << "b::f::pre" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = false; - b_pre = false; - c_pre = true; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - // Test only middle pre checked and failed. - << "b::f::pre" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - a_pre = false; - b_pre = false; - c_pre = false; - out.str(""); - try { - aa.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(err const&) { - #endif - ok.str(""); ok - << ok_begin() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - // Test only middle pre checked and failed. - << "b::f::pre" << std::endl - #else - << ok_end() - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/decl_pre_none.cpp b/test/public_function/decl_pre_none.cpp deleted file mode 100644 index c2885c68..00000000 --- a/test/public_function/decl_pre_none.cpp +++ /dev/null @@ -1,90 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test all derived and base classes without preconditions. - -#define BOOST_CONTRACT_TEST_NO_A_PRE -#define BOOST_CONTRACT_TEST_NO_B_PRE -#define BOOST_CONTRACT_TEST_NO_C_PRE -#include "decl.hpp" - -#include -#include - -int main() { - std::ostringstream ok; ok // Test nothing fails. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - // No preconditions here. - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl // Old only if post (or except) run. - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - - a aa; - - a_pre = true; - b_pre = true; - c_pre = true; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_pre = true; - b_pre = false; - c_pre = false; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = true; - c_pre = false; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = false; - c_pre = true; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - a_pre = false; - b_pre = false; - c_pre = false; - out.str(""); - aa.f(); - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/friend.cpp b/test/public_function/friend.cpp deleted file mode 100644 index af18104f..00000000 --- a/test/public_function/friend.cpp +++ /dev/null @@ -1,107 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test friend functions (also forcing them to check invariants). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -class y; -class z; - -class x { -public: - void invariant() const { - out << "x::inv" << std::endl; - BOOST_CONTRACT_ASSERT(get() >= 0); - } - - x() : value_(0) {} - int get() const { return value_; } - - friend void f(x&, y&, int value); - -private: - int value_; -}; - -class y { -public: - void invariant() const { - out << "y::inv" << std::endl; - BOOST_CONTRACT_ASSERT(get() >= 0); - } - - y() : value_(0) {} - int get() const { return value_; } - - friend void f(x&, y&, int value); - -private: - int value_; -}; - -void f(x& a, y& b, int value) { - boost::contract::check post = boost::contract::function() - .postcondition([&] { - out << "f::post" << std::endl; - BOOST_CONTRACT_ASSERT(a.get() == value); - BOOST_CONTRACT_ASSERT(b.get() == value); - }) - ; - boost::contract::check inv_b = boost::contract::public_function(&b); - boost::contract::check inv_a = boost::contract::public_function(&a); - boost::contract::check pre = boost::contract::function() - .precondition([&] { - out << "f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(value > 0); - }) - ; - - out << "f::body" << std::endl; - a.value_ = b.value_ = value; -} - -int main() { - std::ostringstream ok; - - x a; - y b; - - out.str(""); - f(a, b, 123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "y::inv" << std::endl - << "x::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "x::inv" << std::endl - << "y::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - BOOST_TEST_EQ(a.get(), 123); - BOOST_TEST_EQ(b.get(), 123); - - return boost::report_errors(); -} - diff --git a/test/public_function/ifdef.cpp b/test/public_function/ifdef.cpp deleted file mode 100644 index 1042e5d0..00000000 --- a/test/public_function/ifdef.cpp +++ /dev/null @@ -1,122 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#include -#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #include - #include - #include - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - #endif - - virtual void f(int x, boost::contract::virtual_* v = 0) = 0; -}; - -void b::f(int x, boost::contract::virtual_* v) { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); - #endif - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function(v, this) - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([] { out << "b::f::pre" << std::endl; }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - #endif - ; - #endif - out << "b::f::body" << std::endl; -} - -struct a - #define BASES public b - : BASES -{ - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - BOOST_CONTRACT_OVERRIDE(f) - #endif - - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - #endif - - virtual void f(int x, boost::contract::virtual_* v = 0) { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); - #endif - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function< - override_f>(v, &a::f, this, x) - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([] { out << "a::f::pre" << std::endl; }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - #endif - ; - #endif - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - a aa; - out.str(""); - aa.f(123); - ok.str(); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/ifdef_macro.cpp b/test/public_function/ifdef_macro.cpp deleted file mode 100644 index b479e8b4..00000000 --- a/test/public_function/ifdef_macro.cpp +++ /dev/null @@ -1,171 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test contract compilation on/off (using macro interface). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::inv" << std::endl; - }) - - virtual void f(int x, boost::contract::virtual_* v = 0) = 0; -}; - -void b::f(int x, boost::contract::virtual_* v) { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas:: - type1 - )( - (boost::contract::test::detail::unprotected_commas:: - same(v)), - old_x, - (boost::contract::test::detail::unprotected_commas:: - same(x)) - ); - BOOST_CONTRACT_PUBLIC_FUNCTION( - boost::contract::test::detail::unprotected_commas:: - same(v), - boost::contract::test::detail::unprotected_commas:: - same(this) - ) - BOOST_CONTRACT_PRECONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::f::pre" << std::endl; - }) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "b::f::post" << std::endl; - }) - ; - out << "b::f::body" << std::endl; -} - -struct a - #define BASES public boost::contract::test::detail::unprotected_commas< \ - b, void, void>::type1 - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - BOOST_CONTRACT_OVERRIDE(f) - - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::inv" << std::endl; - }) - - virtual void f(int x, boost::contract::virtual_* v = 0) { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas:: - type1 - )( - (boost::contract::test::detail::unprotected_commas::same(v)), - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE( - boost::contract::test::detail::unprotected_commas::type1 - )( - boost::contract::test::detail::unprotected_commas - ::same(v), - &a::f, - boost::contract::test::detail::unprotected_commas - ::same(this), - boost::contract::test::detail::unprotected_commas - ::same(x) - ) - BOOST_CONTRACT_PRECONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::pre" << std::endl; - }) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::post" << std::endl; - }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - a aa; - out.str(""); - aa.f(123); - ok.str(); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl // Called by post (so under NO_POST). - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/max_args.cpp b/test/public_function/max_args.cpp deleted file mode 100644 index ccfb92d7..00000000 --- a/test/public_function/max_args.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with default max argument number (leave MAX_ARGS #undef). - -#include "max_args.hpp" - diff --git a/test/public_function/max_args.hpp b/test/public_function/max_args.hpp deleted file mode 100644 index a5686fc7..00000000 --- a/test/public_function/max_args.hpp +++ /dev/null @@ -1,194 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test max argument number for public function (with and without result). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -#define BOOST_CONTRACT_TEST_MAX_ARGS_PARAM_COMMA_(z, n, unused) \ - int BOOST_PP_CAT(a, n) , - -#define BOOST_CONTRACT_TEST_MAX_ARGS_COMMA_ARG_(z, n, unused) \ - , BOOST_PP_CAT(a, n) - -#define BOOST_CONTRACT_TEST_MAX_ARGS_N_(z, n, unused) \ - n - -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - #define BOOST_CONTRACT_TEST_MAX_ARGS_B_F_(z, n, unused) \ - virtual int BOOST_PP_CAT(f, n)( \ - BOOST_PP_REPEAT_ ## z( \ - n, BOOST_CONTRACT_TEST_MAX_ARGS_PARAM_COMMA_, ~) \ - boost::contract::virtual_* v = 0 \ - ) { \ - int result = 0; \ - boost::contract::check c = boost::contract::public_function( \ - v, result, this) \ - .precondition([] { \ - out << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::pre" << std::endl; \ - }) \ - .old([] { \ - out << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::old" << std::endl; \ - }) \ - .postcondition([] (int result) { \ - out << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::post" << std::endl; \ - }) \ - ; \ - out << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::body" << std::endl; \ - return result; \ - } - - BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), - BOOST_CONTRACT_TEST_MAX_ARGS_B_F_, ~) -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - #define BOOST_CONTRACT_TEST_MAX_ARGS_A_F_(z, n, unused) \ - int BOOST_PP_CAT(f, n)( \ - BOOST_PP_REPEAT_ ## z( \ - n, BOOST_CONTRACT_TEST_MAX_ARGS_PARAM_COMMA_, ~) \ - boost::contract::virtual_* v = 0 \ - ) /* override */ { \ - int result = 0; \ - boost::contract::check c = boost::contract::public_function< \ - BOOST_PP_CAT(override_, BOOST_PP_CAT(f, n)) \ - >( \ - v, result, &a::BOOST_PP_CAT(f, n), this \ - BOOST_PP_REPEAT_ ## z( \ - n, BOOST_CONTRACT_TEST_MAX_ARGS_COMMA_ARG_, ~) \ - ) \ - .precondition([] { \ - out << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::pre" << std::endl; \ - }) \ - .old([] { \ - out << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::old" << std::endl; \ - }) \ - .postcondition([] (int result) { \ - out << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::post" << std::endl; \ - }) \ - ; \ - out << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::body" << std::endl; \ - return result; \ - } \ - BOOST_CONTRACT_OVERRIDE(BOOST_PP_CAT(f, n)) - - BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), - BOOST_CONTRACT_TEST_MAX_ARGS_A_F_, ~) -}; - -int main() { - std::ostringstream ok; - a aa; - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - #define BOOST_CONTRACT_TEST_entry_inv 1 - #else - #define BOOST_CONTRACT_TEST_entry_inv 0 - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #define BOOST_CONTRACT_TEST_pre 1 - #else - #define BOOST_CONTRACT_TEST_pre 0 - #endif - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - #define BOOST_CONTRACT_TEST_exit_inv 1 - #else - #define BOOST_CONTRACT_TEST_exit_inv 0 - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_TEST_post 1 - #else - #define BOOST_CONTRACT_TEST_post 0 - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1 - #else - #define BOOST_CONTRACT_TEST_old 0 - #endif - - #define BOOST_CONTRACT_TEST_MAX_ARGS_TEST_(z, n, unused) \ - out.str(""); \ - aa.BOOST_PP_CAT(f, n)(BOOST_PP_ENUM_ ## z( \ - n, BOOST_CONTRACT_TEST_MAX_ARGS_N_, ~)); \ - ok.str(""); ok \ - BOOST_PP_EXPR_IIF(BOOST_CONTRACT_TEST_entry_inv, \ - << "b::static_inv\n" \ - << "b::inv\n"\ - << "a::static_inv\n" \ - << "a::inv\n" \ - ) \ - BOOST_PP_EXPR_IIF(BOOST_CONTRACT_TEST_pre, \ - << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::pre\n" \ - ) \ - BOOST_PP_EXPR_IIF(BOOST_CONTRACT_TEST_old, \ - << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::old\n" \ - << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::old\n" \ - ) \ - << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << "::body\n" \ - BOOST_PP_EXPR_IIF(BOOST_CONTRACT_TEST_exit_inv, \ - << "b::static_inv\n" \ - << "b::inv\n"\ - << "a::static_inv\n" \ - << "a::inv\n" \ - ) \ - BOOST_PP_EXPR_IIF(BOOST_CONTRACT_TEST_post, \ - << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::old\n" \ - << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::post\n" \ - << "a::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ - "::post\n" \ - ) \ - ; \ - BOOST_TEST(out.eq(ok.str())); - - BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), - BOOST_CONTRACT_TEST_MAX_ARGS_TEST_, ~) - - #undef BOOST_CONTRACT_TEST_entry_inv - #undef BOOST_CONTRACT_TEST_pre - #undef BOOST_CONTRACT_TEST_exit_inv - #undef BOOST_CONTRACT_TEST_post - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/public_function/max_args0.cpp b/test/public_function/max_args0.cpp deleted file mode 100644 index fa033341..00000000 --- a/test/public_function/max_args0.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 0. - -#define BOOST_CONTRACT_MAX_ARGS 0 -#include "max_args.hpp" - diff --git a/test/public_function/max_args0_no_tva.cpp b/test/public_function/max_args0_no_tva.cpp deleted file mode 100644 index 4f7285ee..00000000 --- a/test/public_function/max_args0_no_tva.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 0 and no variadic templates. - -#define BOOST_NO_CXX11_VARIADIC_TEMPLATES -#define BOOST_CONTRACT_MAX_ARGS 0 -#include "max_args.hpp" - diff --git a/test/public_function/max_args1.cpp b/test/public_function/max_args1.cpp deleted file mode 100644 index 2a9cae83..00000000 --- a/test/public_function/max_args1.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 1. - -#define BOOST_CONTRACT_MAX_ARGS 1 -#include "max_args.hpp" - diff --git a/test/public_function/max_args1_no_tva.cpp b/test/public_function/max_args1_no_tva.cpp deleted file mode 100644 index b1ed828e..00000000 --- a/test/public_function/max_args1_no_tva.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 1 and no variadic templates. - -#define BOOST_NO_CXX11_VARIADIC_TEMPLATES -#define BOOST_CONTRACT_MAX_ARGS 1 -#include "max_args.hpp" - diff --git a/test/public_function/max_args2.cpp b/test/public_function/max_args2.cpp deleted file mode 100644 index 0d6bc769..00000000 --- a/test/public_function/max_args2.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 2. - -#define BOOST_CONTRACT_MAX_ARGS 2 -#include "max_args.hpp" - diff --git a/test/public_function/max_args2_no_tva.cpp b/test/public_function/max_args2_no_tva.cpp deleted file mode 100644 index fdad8af4..00000000 --- a/test/public_function/max_args2_no_tva.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max argument number set to 2 and no variadic templates. - -#define BOOST_NO_CXX11_VARIADIC_TEMPLATES -#define BOOST_CONTRACT_MAX_ARGS 2 -#include "max_args.hpp" - diff --git a/test/public_function/max_args_no_tva.cpp b/test/public_function/max_args_no_tva.cpp deleted file mode 100644 index 9f88deb1..00000000 --- a/test/public_function/max_args_no_tva.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with default max arg number (leave MAX_ARGS #undef) and no variadic tpl. - -#define BOOST_NO_CXX11_VARIADIC_TEMPLATES -#include "max_args.hpp" - diff --git a/test/public_function/max_bases.cpp b/test/public_function/max_bases.cpp deleted file mode 100644 index 67cf3ee9..00000000 --- a/test/public_function/max_bases.cpp +++ /dev/null @@ -1,59 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test with max possible number of bases. - -#include -#include -#include -#include -#include -#include -#include - -// Limited by max size of current impl of Boost.MPL vector. -#ifndef BOOST_CONTRACT_TEST_CONFIG_MAX_BASES - #define BOOST_CONTRACT_TEST_CONFIG_MAX_BASES 20 -#endif - -#define BOOST_CONTRACT_TEST_base_decl(z, n, unused) \ - struct BOOST_PP_CAT(b, n) { \ - virtual void f(boost::contract::virtual_* v = 0) { \ - boost::contract::check c = boost::contract::public_function( \ - v, this); \ - } \ - }; - -BOOST_PP_REPEAT(BOOST_CONTRACT_TEST_CONFIG_MAX_BASES, - BOOST_CONTRACT_TEST_base_decl, ~) - -#define BOOST_CONTRACT_TEST_public_base(z, n, unused) public BOOST_PP_CAT(b, n) - -struct a - #define BASES \ - BOOST_PP_ENUM(BOOST_CONTRACT_TEST_CONFIG_MAX_BASES, \ - BOOST_CONTRACT_TEST_public_base, ~) - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - a aa; - aa.f(); - return 0; -} - -#undef BOOST_CONTRACT_TEST_base_decl -#undef BOOST_CONTRACT_TEST_public_base - diff --git a/test/public_function/old_virtual.cpp b/test/public_function/old_virtual.cpp deleted file mode 100644 index 562a912d..00000000 --- a/test/public_function/old_virtual.cpp +++ /dev/null @@ -1,214 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old inits/ftors and of mixed types up inheritance tree. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct num { - static num make(int i) { // Test no ctor (not even explicit) but for copy. - num n; - n.value(i); - return n; - } - - num(num const& other) : value_(other.value_) {} - - void value(int i) { value_ = boost::lexical_cast(i); } - int value() const { return boost::lexical_cast(value_); } - - num operator+(int left) { - num n; - n.value(value() + left); - return n; - } - -private: - num() {} // Test no visible default ctor (only copy ctor). - num& operator=(num const&); // Test no copy operator (only copy ctor). - - std::string value_; // Test this size-of != from other old type `int` below. -}; - -struct c { - virtual void f(int& i, num& n, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_a = BOOST_CONTRACT_OLDOF(v, i + 1); - boost::contract::old_ptr old_b = BOOST_CONTRACT_OLDOF(v, n + 2); - boost::contract::old_ptr old_x; - boost::contract::old_ptr old_y; - boost::contract::check c = boost::contract::public_function(v, this) - .old([&] { - out << "c::f::old" << std::endl; - old_x = BOOST_CONTRACT_OLDOF(v, i + 3); - old_y = BOOST_CONTRACT_OLDOF(v, n + 4); - }) - .postcondition([&] { - out << "c::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(*old_a == n.value() + 1); - BOOST_CONTRACT_ASSERT(old_b->value() == i + 2); - BOOST_CONTRACT_ASSERT(*old_x == n.value() + 3); - BOOST_CONTRACT_ASSERT(old_y->value() == i + 4); - }) - ; - out << "c::f::body" << std::endl; - int tmp = i; - i = n.value(); - n.value(tmp); - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual void f(int& i, num& n, boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::old_ptr old_a = BOOST_CONTRACT_OLDOF(v, i + 1); - boost::contract::old_ptr old_b = BOOST_CONTRACT_OLDOF(v, n + 2); - boost::contract::old_ptr old_x; - boost::contract::old_ptr old_y; - boost::contract::check c = boost::contract::public_function< - override_f>(v, &c::f, this, i, n) - .old([&] { - out << "b::f::old" << std::endl; - old_x = BOOST_CONTRACT_OLDOF(v, i + 3); - old_y = BOOST_CONTRACT_OLDOF(v, n + 4); - }) - .postcondition([&] { - out << "b::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(*old_a == n.value() + 1); - BOOST_CONTRACT_ASSERT(old_b->value() == i + 2); - BOOST_CONTRACT_ASSERT(*old_x == n.value() + 3); - BOOST_CONTRACT_ASSERT(old_y->value() == i + 4); - }) - ; - out << "b::f::body" << std::endl; - int tmp = i; - i = n.value(); - n.value(tmp); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual void f(int& i, num& n, boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::old_ptr old_a = BOOST_CONTRACT_OLDOF(v, i + 1); - boost::contract::old_ptr old_b = BOOST_CONTRACT_OLDOF(v, n + 2); - boost::contract::old_ptr old_x; - boost::contract::old_ptr old_y; - boost::contract::check c = boost::contract::public_function< - override_f>(v, &c::f, this, i, n) - .old([&] { - out << "a::f::old" << std::endl; - old_x = BOOST_CONTRACT_OLDOF(v, i + 3); - old_y = BOOST_CONTRACT_OLDOF(v, n + 4); - }) - .postcondition([&] { - out << "a::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(*old_a == n.value() + 1); - BOOST_CONTRACT_ASSERT(old_b->value() == i + 2); - BOOST_CONTRACT_ASSERT(*old_x == n.value() + 3); - BOOST_CONTRACT_ASSERT(old_y->value() == i + 4); - }) - ; - out << "a::f::body" << std::endl; - int tmp = i; - i = n.value(); - n.value(tmp); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - int i = 0; - num n = num::make(0); - - i = 123; - n.value(-123); - a aa; // Test virtual call with 2 bases. - out.str(""); - aa.f(i, n); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - i = 456; - n.value(-456); - b bb; // Test virtual call with 1 base. - out.str(""); - bb.f(i, n); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - // No old call here because not a base object. - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - i = 789; - n.value(-789); - c cc; // Test virtual call with no bases. - out.str(""); - cc.f(i, n); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - #endif - << "c::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not a base object. - << "c::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/overload.cpp b/test/public_function/overload.cpp deleted file mode 100644 index a7aa0bb4..00000000 --- a/test/public_function/overload.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public function overloads (with variadic templates if supported). - -#include "overload.hpp" - diff --git a/test/public_function/overload.hpp b/test/public_function/overload.hpp deleted file mode 100644 index d0f5b949..00000000 --- a/test/public_function/overload.hpp +++ /dev/null @@ -1,343 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public function overloads. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - virtual void f(int x, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f(int)::pre" << std::endl; }) - .old([] { out << "b::f(int)::old" << std::endl; }) - .postcondition([] { out << "b::f(int)::post" << std::endl; }) - ; - out << "b::f(int)::body" << std::endl; - } - - virtual void f(char const* x, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f(char const*)::pre" << std::endl; }) - .old([] { out << "b::f(char const*)::old" << std::endl; }) - .postcondition( - [] { out << "b::f(char const*)::post" << std::endl; }) - ; - out << "b::f(char const*)::body" << std::endl; - } - - virtual void f(int x, int y, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f(int, int)::pre" << std::endl; }) - .old([] { out << "b::f(int, int)::old" << std::endl; }) - .postcondition([] { out << "b::f(int, int)::post" << std::endl; }) - ; - out << "b::f(int, int)::body" << std::endl; - } - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f()::pre" << std::endl; }) - .old([] { out << "b::f()::old" << std::endl; }) - .postcondition([] { out << "b::f()::post" << std::endl; }) - ; - out << "b::f()::body" << std::endl; - } - - void f(int x[2][3], boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f(int[2][3])::pre" << std::endl; }) - .old([] { out << "b::f(int[2][3])::old" << std::endl; }) - .postcondition([] { out << "b::f(int[2][3])::post" << std::endl; }) - ; - out << "b::f(int[2][3])::body" << std::endl; - } - - void f(void (*x)(int), boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition( - [] { out << "b::f(void (*)(int))::pre" << std::endl; }) - .old( - [] { out << "b::f(void (*)(int))::old" << std::endl; }) - .postcondition( - [] { out << "b::f(void (*)(int))::post" << std::endl; }) - ; - out << "b::f(void (*)(int))::body" << std::endl; - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - void f(int x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, - static_cast(&a::f), - this, x - ) - .precondition([] { out << "a::f(int)::pre" << std::endl; }) - .old([] { out << "a::f(int)::old" << std::endl; }) - .postcondition([] { out << "a::f(int)::post" << std::endl; }) - ; - out << "a::f(int)::body" << std::endl; - } - - // Test overload via argument type. - void f(char const* x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, - static_cast( - &a::f), - this, x - ) - .precondition([] { out << "a::f(char const*)::pre" << std::endl; }) - .old([] { out << "a::f(char const*)::old" << std::endl; }) - .postcondition( - [] { out << "a::f(char const*)::post" << std::endl; }) - ; - out << "a::f(char const*)::body" << std::endl; - } - - // Test overload via argument count. - void f(int x, int y, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, - static_cast( - &a::f), - this, x, y - ) - .precondition([] { out << "a::f(int, int)::pre" << std::endl; }) - .old([] { out << "a::f(int, int)::old" << std::endl; }) - .postcondition([] { out << "a::f(int, int)::post" << std::endl; }) - ; - out << "a::f(int, int)::body" << std::endl; - } - - // Test overload via template argument type. - template - void f(T x) { // Template cannot be virtual (or override) in C++. - boost::contract::check c = boost::contract::public_function(this) - .precondition([] { out << "a::f(T)::pre" << std::endl; }) - .old([] { out << "a::f(T)::old" << std::endl; }) - .postcondition([] { out << "a::f(T)::post" << std::endl; }) - ; - out << "a::f(T)::body" << std::endl; - } - - // Test no overload ambiguity in public_function called by these two cases. - - // NOTE: In *all* other cases, public_function is always called with a - // different number of arguments so there cannot be ambiguity either - // (0 args for static, 1 arg for non-virtual, 2 or 3 args for virtual, - // >= 3 for override, so only in cases below of 3 args for virtual and 3 - // for override there could be ambiguity but there is not because of - // presence or absence of override_... template parameter). - - typedef void (a::* f0_ptr)(boost::contract::virtual_*); - - void f(boost::contract::virtual_* v = 0) /* override */ { - f0_ptr f0 = static_cast(&a::f); - // Test this and public_function call in func below both take same 3 - // args but they are ambiguous because of presence override_f. - boost::contract::check c = boost::contract::public_function( - v, f0, this) - .precondition([] { out << "a::f()::pre" << std::endl; }) - .old([] { out << "a::f()::old" << std::endl; }) - .postcondition([] { out << "a::f()::post" << std::endl; }) - ; - out << "a::f()::body" << std::endl; - } - - virtual f0_ptr f(bool x, boost::contract::virtual_* v = 0) - /* not an override */ { - f0_ptr f0 = static_cast(&a::f); - // Test this and public_function call in func above both take same 3 - // args but they are ambiguous because of lack of override_f. - boost::contract::check c = boost::contract::public_function( - v, f0, this) - .precondition([] { out << "a::f(bool)::pre" << std::endl; }) - .old([] { out << "a::f(bool)::old" << std::endl; }) - .postcondition([] (f0_ptr const&) { - out << "a::f(bool)::post" << std::endl; }) - ; - out << "a::f(bool)::body" << std::endl; - return f0; - } - - // Test overload with array parameter. - void f(int x[2][3], boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, - static_cast( - &a::f), - this, x - ) - .precondition([] { out << "a::f(int[2][3])::pre" << std::endl; }) - .old([] { out << "a::f(int[2][3])::old" << std::endl; }) - .postcondition([] { out << "a::f(int[2][3])::post" << std::endl; }) - ; - out << "a::f(int[2][3])::body" << std::endl; - } - - // Test overload with function pointer parameter. - void f(void (*x)(int), boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, - static_cast( - &a::f), - this, x - ) - .precondition( - [] { out << "a::f(void (*)(int))::pre" << std::endl; }) - .old( - [] { out << "a::f(void (*)(int))::old" << std::endl; }) - .postcondition( - [] { out << "a::f(void (*)(int))::post" << std::endl; }) - ; - out << "a::f(void (*)(int))::body" << std::endl; - } - - BOOST_CONTRACT_OVERRIDE(f) -}; - -void g(int) {} - -std::string ok_args(std::string const& args) { - std::ostringstream ok; ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f(" << args << ")::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f(" << args << ")::old" << std::endl - << "a::f(" << args << ")::old" << std::endl - #endif - << "a::f(" << args << ")::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f(" << args << ")::old" << std::endl - << "b::f(" << args << ")::post" << std::endl - << "a::f(" << args << ")::post" << std::endl - #endif - ; - return ok.str(); -} - -int main() { - std::ostringstream ok; - a aa; - - out.str(""); - aa.f(123); - ok.str(""); ok << ok_args("int"); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f("abc"); - ok.str(""); ok << ok_args("char const*"); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f(123, 456); - ok.str(""); ok << ok_args("int, int"); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - struct {} zz; - aa.f(zz); // Call template (so no override because no virtual). - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f(T)::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f(T)::old" << std::endl - #endif - << "a::f(T)::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f(T)::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f(); - ok.str(""); ok << ok_args(""); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f(true); // This does not override (public_function ambiguity testing). - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f(bool)::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f(bool)::old" << std::endl - #endif - << "a::f(bool)::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f(bool)::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - int i[2][3]; - aa.f(i); - ok.str(""); ok << ok_args("int[2][3]"); - BOOST_TEST(out.eq(ok.str())); - - out.str(""); - aa.f(&g); - ok.str(""); ok << ok_args("void (*)(int)"); - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/overload_no_tva.cpp b/test/public_function/overload_no_tva.cpp deleted file mode 100644 index 3eaa2e00..00000000 --- a/test/public_function/overload_no_tva.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public function overloads (always without variadic templates). - -#define BOOST_NO_CXX11_VARIADIC_TEMPLATES -#include "overload.hpp" - diff --git a/test/public_function/override.hpp b/test/public_function/override.hpp deleted file mode 100644 index 70c71893..00000000 --- a/test/public_function/override.hpp +++ /dev/null @@ -1,41 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if override func does not actually override (unless PERMISSIVE). - -#include -#include -#include -#include - -struct b { - virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this); - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>(v, &a::f, this); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - a aa; - aa.f(); - return 0; -} - diff --git a/test/public_function/override_error.cpp b/test/public_function/override_error.cpp deleted file mode 100644 index c4e05e12..00000000 --- a/test/public_function/override_error.cpp +++ /dev/null @@ -1,14 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test error if override func does not actually override. - -#undef BOOST_CONTRACT_PERMISSIVE -#include "override.hpp" -#ifdef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #error "Forcing error even when public functions not checked" -#endif - diff --git a/test/public_function/override_permissive.cpp b/test/public_function/override_permissive.cpp deleted file mode 100644 index 1d32af25..00000000 --- a/test/public_function/override_permissive.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no error if permissive even when override f does not actually override. - -#define BOOST_CONTRACT_PERMISSIVE -#include "override.hpp" - diff --git a/test/public_function/protected.cpp b/test/public_function/protected.cpp deleted file mode 100644 index ed452d78..00000000 --- a/test/public_function/protected.cpp +++ /dev/null @@ -1,88 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test overriding function never overrides protected function contract. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - -protected: - // NOTE: This is the correct way of programming contracts for overridden - // protected and overriding public functions: Both must use virtual_ - // (otherwise C++ won't override because mismatching parameters), but - // overridden protected does not use public_function. - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "b::f::pre" << std::endl; }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } -}; -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - void f(boost::contract::virtual_* v = 0) /* not override */ { - // C++ func a::f overrides b::f, but contracts don't (so no override_f). - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - a aa; - out.str(""); - aa.f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/protected_error.cpp b/test/public_function/protected_error.cpp deleted file mode 100644 index e81c180e..00000000 --- a/test/public_function/protected_error.cpp +++ /dev/null @@ -1,52 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test a public function contract cannot override from a protected one. - -#include -#include -#include -#include - -struct b { -protected: - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this); - } - - friend class boost::contract::access; // Test this cannot prevent error. -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this); // Error (override cannot access b::f). - #ifdef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #error "Forcing error even when public functions not checked" - #endif - } - - // Correctly, GCC and CLang cannot even see b::f as part of overloaded bases - // because it is protected. MSVC also fails compilation but only when - // override_f below tries to call b::f (because it is protected so it cannot - // be seen from within override_f). - BOOST_CONTRACT_OVERRIDE(f) - - friend class boost::contract::access; // Test this cannot prevent error. -}; - -int main() { - a aa; - aa.f(); - return 0; -} - diff --git a/test/public_function/smoke.cpp b/test/public_function/smoke.cpp deleted file mode 100644 index 0105e560..00000000 --- a/test/public_function/smoke.cpp +++ /dev/null @@ -1,104 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public member function subcontracting. - -#include "smoke.hpp" -#include -#include -#include - -int main() { - std::ostringstream ok; - - a aa; // Test call to derived out-most leaf. - s_type s; s.value = "A"; - out.str(""); - result_type& r = aa.f(s); - - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(r.value, "A"); - BOOST_TEST_EQ(s.value, "acde"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 for local var. - - BOOST_TEST_EQ(aa.x.value, "aA"); - BOOST_TEST_EQ(aa.x.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(aa.y.value, "cA"); - BOOST_TEST_EQ(aa.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.y.ctors(), aa.y.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(aa.t<'d'>::z.value, "dA"); - BOOST_TEST_EQ(aa.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'d'>::z.ctors(), aa.t<'d'>::z.dtors() + 1); // 1 member. - - BOOST_TEST_EQ(aa.t<'e'>::z.value, "eA"); - BOOST_TEST_EQ(aa.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'e'>::z.ctors(), aa.t<'e'>::z.dtors() + 1); // 1 member. - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/public_function/smoke.hpp b/test/public_function/smoke.hpp deleted file mode 100644 index c7a59a6b..00000000 --- a/test/public_function/smoke.hpp +++ /dev/null @@ -1,261 +0,0 @@ - -#ifndef BOOST_CONTRACT_TEST_PUBLIC_FUNCTION_CONTRACTS_HPP_ -#define BOOST_CONTRACT_TEST_PUBLIC_FUNCTION_CONTRACTS_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public member function subcontracting (also with old and return values). - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct s_tag; -typedef boost::contract::test::detail::counter s_type; - -struct except_error {}; - -struct result_type { - std::string value; - explicit result_type(std::string const& s) : value(s) {} - -private: // Test non-copyable and non-default-constructible result. - result_type(); - result_type(result_type const&); - result_type& operator=(result_type const&); -}; - -// Test base without additional bases and pure virtual. -template -struct t { - static void static_invariant() { out << Id << "::static_inv" << std::endl; } - - void invariant() const { - out << Id << "::inv" << std::endl; - BOOST_CONTRACT_ASSERT(z.value != ""); - } - - struct z_tag; - typedef boost::contract::test::detail::counter z_type; - z_type z; - - t() { z.value.push_back(Id); } - - virtual result_type& f(s_type& s, boost::contract::virtual_* v = 0) = 0; -}; - -template // Requires: Only pass lower case Id so it'll never be 'X'. -result_type& t::f(s_type& s, boost::contract::virtual_* v) { - std::ostringstream r; r << "none-" << Id; - static result_type result(r.str()); - boost::contract::old_ptr old_z = - BOOST_CONTRACT_OLDOF(v, z_type::eval(z)); - boost::contract::old_ptr old_s; - boost::contract::check c = boost::contract::public_function(v, result, this) - .precondition([&] { - out << Id << "::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(s.value[0] == Id || s.value[0] == 'X'); - }) - .old([&] { - out << Id << "::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - }) - .postcondition([&] (result_type const& result) { - out << Id << "::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(z.value == old_z->value + old_s->value); - BOOST_CONTRACT_ASSERT(s.value.find(old_z->value) != - std::string::npos); - BOOST_CONTRACT_ASSERT(result.value == old_s->value); - }) - .except([&] { - out << Id << "::f::except" << std::endl; - BOOST_CONTRACT_ASSERT(z.value == old_z->value); - BOOST_CONTRACT_ASSERT(s.value == old_s->value); - }) - ; - out << "t<" << Id << ">::f::body" << std::endl; - if(s.value == "X") throw except_error(); - return result; -} - -// Test base with other bases, multiple inheritance, and no subcontracting from -// protected and private bases (even if fully contracted). -struct c - #define BASES public t<'d'>, protected t<'p'>, private t<'q'>, public t<'e'> - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - - void invariant() const { - out << "c::inv" << std::endl; - BOOST_CONTRACT_ASSERT(y.value != ""); - } - - struct y_tag; - typedef boost::contract::test::detail::counter y_type; - y_type y; - - c() { y.value = "c"; } - - virtual result_type& f(s_type& s, boost::contract::virtual_* v = 0) - /* override */ { - static result_type result("none-c"); - boost::contract::old_ptr old_y = - BOOST_CONTRACT_OLDOF(v, y_type::eval(y)); - boost::contract::old_ptr old_s; - boost::contract::check c = boost::contract::public_function< - override_f>(v, result, &c::f, this, s) - .precondition([&] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(s.value == "C" || s.value == "X"); - }) - .old([&] { - out << "c::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - }) - .postcondition([&] (result_type const& result) { - out << "c::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(y.value == old_y->value + old_s->value); - BOOST_CONTRACT_ASSERT(s.value.find(old_y->value) != - std::string::npos); - BOOST_CONTRACT_ASSERT(result.value == old_s->value); - }) - .except([&] { - out << "c::f::except" << std::endl; - BOOST_CONTRACT_ASSERT(y.value == old_y->value); - BOOST_CONTRACT_ASSERT(s.value == old_s->value); - }) - ; - - out << "c::f::body" << std::endl; - if(s.value == "X") throw except_error(); - std::string save_s = s.value; - - std::string save = y.value; - y.value += save_s; - s.value = save; - - save = t<'d'>::z.value; - t<'d'>::z.value += save_s; - s.value += save; - - save = t<'e'>::z.value; - t<'e'>::z.value += save_s; - s.value += save; - - result.value = save_s; - return result; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -// Test no subcontracting from not (fully) contracted base. -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - virtual ~b() {} - - // No contract (no virtual_ so this is not actually overridden by a::f). - virtual result_type& f(s_type& s) { - static result_type result("none-b"); - out << "b::f::body" << std::endl; - result.value = s.value; - return result; - } -}; - -// Test public function with both non-contracted and contracted bases. -struct a - #define BASES public b, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - - void invariant() const { - out << "a::inv" << std::endl; - BOOST_CONTRACT_ASSERT(x.value != ""); - } - - struct x_tag; - typedef boost::contract::test::detail::counter x_type; - x_type x; - - a() { x.value = "a"; } - - // Must use virtual_ even if no longer decl virtual for correct overloading. - result_type& f(s_type& s, boost::contract::virtual_* v = 0) - /* override */ { - static result_type result("none-a"); - boost::contract::old_ptr old_x = - BOOST_CONTRACT_OLDOF(v, x_type::eval(x)); - boost::contract::old_ptr old_s; - boost::contract::check c = boost::contract::public_function< - override_f>(v, result, &a::f, this, s) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(s.value == "A" || s.value == "X"); - }) - .old([&] { - out << "a::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - }) - .postcondition([&] (result_type const& result) { - out << "a::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(x.value == old_x->value + old_s->value); - BOOST_CONTRACT_ASSERT(s.value.find(old_x->value) != - std::string::npos); - BOOST_CONTRACT_ASSERT(result.value == old_s->value); - }) - .except([&] { - out << "a::f::except" << std::endl; - BOOST_CONTRACT_ASSERT(x.value == old_x->value); - BOOST_CONTRACT_ASSERT(s.value == old_s->value); - }) - ; - - out << "a::f::body" << std::endl; - if(s.value == "X") throw except_error(); - std::string save_s = s.value; - - std::string save = x.value; - x.value += save_s; - s.value = save; - - save = y.value; - y.value += save_s; - s.value += save; - - save = t<'d'>::z.value; - t<'d'>::z.value += save_s; - s.value += save; - - save = t<'e'>::z.value; - t<'e'>::z.value += save_s; - s.value += save; - - result.value = save_s; - return result; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -#endif // #include guard - diff --git a/test/public_function/static.cpp b/test/public_function/static.cpp deleted file mode 100644 index e7188dbc..00000000 --- a/test/public_function/static.cpp +++ /dev/null @@ -1,82 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public static member function contracts. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "b::f::pre" << std::endl; }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - out.str(""); - a::f(); - ok.str(""); ok - // Static so no object thus only static inv, plus never virtual so subst - // principle does not apply and no subcontracting. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/static_ifdef.cpp b/test/public_function/static_ifdef.cpp deleted file mode 100644 index a8fee26e..00000000 --- a/test/public_function/static_ifdef.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public static member function contract compilation on/off. - -#include "../detail/oteststream.hpp" -#include -#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #include - #include - #include -#endif -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - #endif - - static void f(int x) { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - #endif - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check c = boost::contract::public_function() - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition([] { out << "a::f::pre" << std::endl; }) - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - #endif - ; - #endif - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - out.str(""); - a::f(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - // Test no post (but still static inv) because body threw. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/static_ifdef_macro.cpp b/test/public_function/static_ifdef_macro.cpp deleted file mode 100644 index 1dc0800d..00000000 --- a/test/public_function/static_ifdef_macro.cpp +++ /dev/null @@ -1,90 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public static member function contract compilation on/off (w/ macros). - -#include "../detail/oteststream.hpp" -#include "../detail/unprotected_commas.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - BOOST_CONTRACT_STATIC_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::static_inv" << std::endl; - }) - - BOOST_CONTRACT_INVARIANT({ - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::inv" << std::endl; - }) - - static void f(int x) { - BOOST_CONTRACT_OLD_PTR( - boost::contract::test::detail::unprotected_commas:: - type1 - )( - old_x, - (boost::contract::test::detail::unprotected_commas::same(x)) - ); - BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(boost::contract::test::detail:: - unprotected_commas::type1) - BOOST_CONTRACT_PRECONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::pre" << std::endl; - }) - BOOST_CONTRACT_OLD([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::old" << std::endl; - }) - BOOST_CONTRACT_POSTCONDITION([] { - typedef boost::contract::test::detail::unprotected_commas t; - out << "a::f::post" << std::endl; - }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - out.str(""); - a::f(123); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - // Test no post (but still static inv) because body threw. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/static_throwing_body.cpp b/test/public_function/static_throwing_body.cpp deleted file mode 100644 index 20e20ec6..00000000 --- a/test/public_function/static_throwing_body.cpp +++ /dev/null @@ -1,67 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public static member function throwing. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - throw a::err(); // Test this throws. - } -}; - -int main() { - std::ostringstream ok; - - try { - out.str(""); - a::f(); - BOOST_TEST(false); - } catch(a::err const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl // Test this threw. - // Test no post (but still static inv) because body threw. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "a::f::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/static_throwing_old.cpp b/test/public_function/static_throwing_old.cpp deleted file mode 100644 index 3eb7bd70..00000000 --- a/test/public_function/static_throwing_old.cpp +++ /dev/null @@ -1,71 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public static member function .old(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { - out << "a::f::old" << std::endl; - throw a::err(); // Test this throws. - }) - .postcondition([] { out << "a::f::post" << std::endl; }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - try { - out.str(""); - a::f(); - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(false); - } catch(a::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl // Test this threw. - #else - << "a::f::body" << std::endl - // Test no post (but still static inv) because .old() threw. - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/static_throwing_post.cpp b/test/public_function/static_throwing_post.cpp deleted file mode 100644 index 656b6f6b..00000000 --- a/test/public_function/static_throwing_post.cpp +++ /dev/null @@ -1,73 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public static member function .post(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { - out << "a::f::post" << std::endl; - throw a::err(); // Test this throws. - }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - a::f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(a::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl // Test this threw. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/static_throwing_pre.cpp b/test/public_function/static_throwing_pre.cpp deleted file mode 100644 index b9a4c74c..00000000 --- a/test/public_function/static_throwing_pre.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public static member function .pre(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct a { - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - static void f() { - boost::contract::check c = boost::contract::public_function() - .precondition([] { - out << "a::f::pre" << std::endl; - throw a::err(); // Test this throws. - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw; }); - - try { - out.str(""); - a::f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(a::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::f::pre" << std::endl // Test this threw. - #else - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::f::post" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_body.cpp b/test/public_function/throwing_body.cpp deleted file mode 100644 index 5e858ca9..00000000 --- a/test/public_function/throwing_body.cpp +++ /dev/null @@ -1,106 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public member function body throws with subcontracting. - -#include "smoke.hpp" -#include -#include -#include -#include - -int main() { - std::ostringstream ok; - - a aa; // Test call to derived out-most leaf. - s_type s; s.value = "X"; // So body will throw. - out.str(""); - boost::optional r; - try { - r = aa.f(s); - BOOST_TEST(false); - } catch(except_error const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "d::f::old" << std::endl - << "d::f::except" << std::endl - << "e::f::old" << std::endl - << "e::f::except" << std::endl - << "c::f::old" << std::endl - << "c::f::except" << std::endl - // No old call here because not a base object. - << "a::f::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST(!r); // Boost.Optional result not init (as body threw). - BOOST_TEST_EQ(s.value, "X"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 for local var. - - BOOST_TEST_EQ(aa.x.value, "a"); - BOOST_TEST_EQ(aa.x.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(aa.y.value, "c"); - BOOST_TEST_EQ(aa.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.y.ctors(), aa.y.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(aa.t<'d'>::z.value, "d"); - BOOST_TEST_EQ(aa.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'d'>::z.ctors(), aa.t<'d'>::z.dtors() + 1); // 1 mem. - - BOOST_TEST_EQ(aa.t<'e'>::z.value, "e"); - BOOST_TEST_EQ(aa.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.t<'e'>::z.ctors(), aa.t<'e'>::z.dtors() + 1); // 1 mem. - - #undef BOOST_CONTRACT_TEST_old - } - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_body_virtual.cpp b/test/public_function/throwing_body_virtual.cpp deleted file mode 100644 index edb3b208..00000000 --- a/test/public_function/throwing_body_virtual.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test virtual public member function body throws with subcontracting. - -#include "smoke.hpp" -#include -#include -#include -#include - -int main() { - std::ostringstream ok; - - a aa; // Test call to derived out-most leaf. - c& ca = aa; // Test polymorphic virtual call (via reference to base c). - s_type s; s.value = "X"; // So body will throw. - out.str(""); - boost::optional r; - try { - r = ca.f(s); - BOOST_TEST(false); - } catch(except_error const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "d::f::old" << std::endl - << "d::f::except" << std::endl - << "e::f::old" << std::endl - << "e::f::except" << std::endl - << "c::f::old" << std::endl - << "c::f::except" << std::endl - // No old call here because not a base object. - << "a::f::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST(!r); // Boost.Optional result not init (as body threw). - BOOST_TEST_EQ(s.value, "X"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 for local var. - - // Cannot access x via ca, but only via aa. - BOOST_TEST_EQ(aa.x.value, "a"); - BOOST_TEST_EQ(aa.x.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(ca.y.value, "c"); - BOOST_TEST_EQ(ca.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.y.ctors(), aa.y.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(ca.t<'d'>::z.value, "d"); - BOOST_TEST_EQ(ca.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'d'>::z.ctors(), aa.t<'d'>::z.dtors() + 1); // 1 mem. - - BOOST_TEST_EQ(ca.t<'e'>::z.value, "e"); - BOOST_TEST_EQ(ca.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'e'>::z.ctors(), aa.t<'e'>::z.dtors() + 1); // 1 mem. - - #undef BOOST_CONTRACT_TEST_old - } - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_body_virtual_branch.cpp b/test/public_function/throwing_body_virtual_branch.cpp deleted file mode 100644 index 5cc69e61..00000000 --- a/test/public_function/throwing_body_virtual_branch.cpp +++ /dev/null @@ -1,94 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test virt pub func body throws with subcontr from middle of inheritance tree. - -#include "smoke.hpp" -#include -#include -#include -#include - -int main() { - std::ostringstream ok; - - c cc; // Test call to class at mid- inheritance tree (as base with bases). - s_type s; s.value = "X"; // So body will throw. - out.str(""); - boost::optional r; - try { - r = cc.f(s); - BOOST_TEST(false); - } catch(except_error const&) { - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - #endif - << "c::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - << "d::f::old" << std::endl - << "d::f::except" << std::endl - << "e::f::old" << std::endl - << "e::f::except" << std::endl - // No old call here because not a base object. - << "c::f::except" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST(!r); // Boost.Optional result not init (as body threw). - BOOST_TEST_EQ(s.value, "X"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 3); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 3); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 for local var. - - BOOST_TEST_EQ(cc.y.value, "c"); - BOOST_TEST_EQ(cc.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.y.ctors(), cc.y.dtors() + 1); // 1 for member var. - - BOOST_TEST_EQ(cc.t<'d'>::z.value, "d"); - BOOST_TEST_EQ(cc.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'d'>::z.ctors(), cc.t<'d'>::z.dtors() + 1); // 1 mem. - - BOOST_TEST_EQ(cc.t<'e'>::z.value, "e"); - BOOST_TEST_EQ(cc.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'e'>::z.ctors(), cc.t<'e'>::z.dtors() + 1); // 1 mem. - - #undef BOOST_CONTRACT_TEST_old - } - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_old.cpp b/test/public_function/throwing_old.cpp deleted file mode 100644 index cbdb3bd9..00000000 --- a/test/public_function/throwing_old.cpp +++ /dev/null @@ -1,149 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public function (derived and bases) .old(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { - out << "c::f::old" << std::endl; - throw c::err(); // Test this throws. - }) - .postcondition([] { out << "c::f::post" << std::endl; }) - .except([] { out << "c::f::except" << std::endl; }) - ; - out << "c::f::body" << std::endl; - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &b::f, this) - .precondition([] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { - out << "b::f::old" << std::endl; - throw b::err(); // Test this throws. - }) - .postcondition([] { out << "b::f::post" << std::endl; }) - .except([] { out << "b::f::except" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { - out << "a::f::old" << std::endl; - throw a::err(); // Test this throws. - }) - .postcondition([] { out << "a::f::post" << std::endl; }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_old_failure([] (boost::contract::from) { throw; }); - - a aa; - b& ba = aa; // Test as virtual call via polymorphism. - try { - out.str(""); - ba.f(); - #ifndef BOOST_CONTRACT_NO_OLDS - BOOST_TEST(false); - } catch(c::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl // Test this threw. - #else - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_post.cpp b/test/public_function/throwing_post.cpp deleted file mode 100644 index 20172fb2..00000000 --- a/test/public_function/throwing_post.cpp +++ /dev/null @@ -1,157 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public function (derived and bases) .post(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { out << "c::f::old" << std::endl; }) - .postcondition([] { - out << "c::f::post" << std::endl; - // Test derived will throw. - }) - .except([] { out << "c::f::except" << std::endl; }) - ; - out << "c::f::body" << std::endl; - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &b::f, this) - .precondition([] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { - out << "b::f::post" << std::endl; - throw b::err(); // Test this (both derived and base) throws. - }) - .except([] { out << "b::f::except" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { - out << "a::f::post" << std::endl; - throw a::err(); // Test base already threw. - }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_postcondition_failure( - [] (boost::contract::from) { throw; }); - - a aa; - b& ba = aa; // Test as virtual call via polymorphism. - try { - out.str(""); - ba.f(); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_TEST(false); - } catch(b::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl // Test this threw. - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/throwing_pre.cpp b/test/public_function/throwing_pre.cpp deleted file mode 100644 index f8347f17..00000000 --- a/test/public_function/throwing_pre.cpp +++ /dev/null @@ -1,154 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test throw from public function (derived and bases) .pre(). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { out << "c::f::old" << std::endl; }) - .postcondition([] { out << "c::f::post" << std::endl; }) - .except([] { out << "c::f::except" << std::endl; }) - ; - out << "c::f::body" << std::endl; - } -}; - -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - struct err {}; - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &b::f, this) - .precondition([] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(false); // To check derived pre. - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - .except([] { out << "b::f::except" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - struct err {}; - - void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - .precondition([] { - out << "a::f::pre" << std::endl; - throw a::err(); // Test this throws. - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - .except([] { out << "a::f::except" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - boost::contract::set_precondition_failure( - [] (boost::contract::from) { throw; }); - - a aa; - b& ba = aa; // Test as virtual call via polymorphism. - try { - out.str(""); - ba.f(); - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - BOOST_TEST(false); - } catch(a::err const&) { - #endif - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl // Test this threw. - #else - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - #endif - ; - BOOST_TEST(out.eq(ok.str())); - } catch(...) { BOOST_TEST(false); } - - return boost::report_errors(); -} - diff --git a/test/public_function/virtual.cpp b/test/public_function/virtual.cpp deleted file mode 100644 index 8d5fa908..00000000 --- a/test/public_function/virtual.cpp +++ /dev/null @@ -1,106 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public function subcontracting via virtual functions. - -#include "smoke.hpp" -#include -#include -#include - -int main() { - std::ostringstream ok; - - a aa; - c& ca = aa; // Test polymorphic virtual call (via reference to base c). - s_type s; s.value = "A"; - out.str(""); - result_type& r = ca.f(s); - - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(r.value, "A"); - BOOST_TEST_EQ(s.value, "acde"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 4); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 local var. - - // Cannot access x via ca, but only via aa. - BOOST_TEST_EQ(aa.x.value, "aA"); - BOOST_TEST_EQ(aa.x.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 data member. - - BOOST_TEST_EQ(ca.y.value, "cA"); - BOOST_TEST_EQ(ca.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.y.ctors(), ca.y.dtors() + 1); // 1 data member. - - BOOST_TEST_EQ(ca.t<'d'>::z.value, "dA"); - BOOST_TEST_EQ(ca.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'d'>::z.ctors(), ca.t<'d'>::z.dtors() + 1); // 1 member. - - BOOST_TEST_EQ(ca.t<'e'>::z.value, "eA"); - BOOST_TEST_EQ(ca.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(ca.t<'e'>::z.ctors(), ca.t<'e'>::z.dtors() + 1); // 1 member. - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/public_function/virtual_access.cpp b/test/public_function/virtual_access.cpp deleted file mode 100644 index 0d546046..00000000 --- a/test/public_function/virtual_access.cpp +++ /dev/null @@ -1,220 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test overrides with mixed access level from (single) base. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b { // Test all access levels (public, protected, and private). - friend void call(b& me) { // Test polymorphic calls (object by &). - me.f(); - me.g(); - me.h(); - } - - static void statci_inv() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f::pre" << std::endl; }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - - // NOTE: Both protected and private virtual members must declare - // extra `virtual_* = 0` parameter (otherwise they cannot be overridden in - // derived classes with contracts because C++ uses also default parameters - // to match signature of overriding functions). - -protected: - virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "b::g::pre" << std::endl; }) - .old([] { out << "b::g::old" << std::endl; }) - .postcondition([] { out << "b::g::post" << std::endl; }) - ; - out << "b::g::body" << std::endl; - } - -private: - virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "b::h::pre" << std::endl; }) - .old([] { out << "b::h::old" << std::endl; }) - .postcondition([] { out << "b::h::post" << std::endl; }) - ; - out << "b::h::body" << std::endl; - } -}; - -struct a // Test overrides with mixed access levels from base. - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void statci_inv() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDES(f); - - // Following do not override public members so no `override_...` param and - // they do not actually subcontract. - - virtual void g(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "a::g::pre" << std::endl; }) - .old([] { out << "a::g::old" << std::endl; }) - .postcondition([] { out << "a::g::post" << std::endl; }) - ; - out << "a::g::body" << std::endl; - } - - virtual void h(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "a::h::pre" << std::endl; }) - .old([] { out << "a::h::old" << std::endl; }) - .postcondition([] { out << "a::h::post" << std::endl; }) - ; - out << "a::h::body" << std::endl; - } -}; - -int main() { - std::ostringstream ok; - - b bb; - out.str(""); - call(bb); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::g::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::g::old" << std::endl - #endif - << "b::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::g::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::h::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::h::old" << std::endl - #endif - << "b::h::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::h::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - a aa; - out.str(""); - call(aa); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::g::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::g::old" << std::endl - #endif - << "a::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::g::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::h::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "a::h::old" << std::endl - #endif - << "a::h::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::h::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/public_function/virtual_access_multi.cpp b/test/public_function/virtual_access_multi.cpp deleted file mode 100644 index 3f4d21bb..00000000 --- a/test/public_function/virtual_access_multi.cpp +++ /dev/null @@ -1,283 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test overrides with mixed access levels from different (multiple) bases. - -#include -#ifdef BOOST_MSVC - -// WARNING: MSVC (at least up to VS 2015) gives a compile-time error if SFINAE -// cannot introspect a member because of its private or protected access level. -// That is incorrect, SFINAE should fail in these cases without generating -// compile-time errors like GCC and CLang do. Therefore, currently it is not -// possible to override a member that is public in one base but private or -// protected in other base using this library on MSVC (that can be done instead -// using this library on GCC or CLang). -int main() { return 0; } // This test trivially passes on MSVC. - -#else - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct c { // Test public access different from base `b`'s access below. - static void statci_inv() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "c::f::pre" << std::endl; }) - .old([] { out << "c::f::old" << std::endl; }) - .postcondition([] { out << "c::f::post" << std::endl; }) - ; - out << "c::f::body" << std::endl; - } - - virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "c::g::pre" << std::endl; }) - .old([] { out << "c::g::old" << std::endl; }) - .postcondition([] { out << "c::g::post" << std::endl; }) - ; - out << "c::g::body" << std::endl; - } - - virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "c::h::pre" << std::endl; }) - .old([] { out << "c::h::old" << std::endl; }) - .postcondition([] { out << "c::h::post" << std::endl; }) - ; - out << "c::h::body" << std::endl; - } -}; - -struct b { // Test all access levels (public, protected, and private). - friend void call(b& me) { // Test polymorphic calls (object by &). - me.f(); - me.g(); - me.h(); - } - - static void statci_inv() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([] { out << "b::f::pre" << std::endl; }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - - // NOTE: Both protected and private virtual members must declare - // extra `virtual_* = 0` parameter (otherwise they cannot be overridden in - // derived classes with contracts because C++ uses also default parameters - // to match signature of overriding functions). - -protected: - virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "b::g::pre" << std::endl; }) - .old([] { out << "b::g::old" << std::endl; }) - .postcondition([] { out << "b::g::post" << std::endl; }) - ; - out << "b::g::body" << std::endl; - } - -private: - virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "b::h::pre" << std::endl; }) - .old([] { out << "b::h::old" << std::endl; }) - .postcondition([] { out << "b::h::post" << std::endl; }) - ; - out << "b::h::body" << std::endl; - } -}; - -struct a // Test overrides with mixed access levels from different bases. - #define BASES public b, public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void statci_inv() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::f, this) - .precondition([] { out << "a::f::pre" << std::endl; }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - - virtual void g(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::g, this) - .precondition([] { out << "a::g::pre" << std::endl; }) - .old([] { out << "a::g::old" << std::endl; }) - .postcondition([] { out << "a::g::post" << std::endl; }) - ; - out << "a::g::body" << std::endl; - } - - virtual void h(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function( - v, &a::h, this) - .precondition([] { out << "a::h::pre" << std::endl; }) - .old([] { out << "a::h::old" << std::endl; }) - .postcondition([] { out << "a::h::post" << std::endl; }) - ; - out << "a::h::body" << std::endl; - } - - BOOST_CONTRACT_OVERRIDES(f, g, h); -}; - -int main() { - std::ostringstream ok; - - b bb; - out.str(""); - call(bb); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::g::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::g::old" << std::endl - #endif - << "b::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::g::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::h::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::h::old" << std::endl - #endif - << "b::h::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::h::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - a aa; - out.str(""); - call(aa); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::inv" << std::endl - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "b::f::old" << std::endl - << "c::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::inv" << std::endl - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "a::f::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::g::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::g::old" << std::endl - << "a::g::old" << std::endl - #endif - << "a::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::g::old" << std::endl - << "c::g::post" << std::endl - << "a::g::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::h::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::h::old" << std::endl - << "a::h::old" << std::endl - #endif - << "a::h::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::h::old" << std::endl - << "c::h::post" << std::endl - << "a::h::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - -#endif // MSVC - diff --git a/test/public_function/virtual_branch.cpp b/test/public_function/virtual_branch.cpp deleted file mode 100644 index ee4e84e4..00000000 --- a/test/public_function/virtual_branch.cpp +++ /dev/null @@ -1,90 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test public function subcontracting from middle branch of inheritance tree. - -#include "smoke.hpp" -#include -#include - -int main() { - std::ostringstream ok; - - c cc; // Test call to class at mid- inheritance tree (a base with bases). - s_type s; s.value = "C"; - out.str(""); - result_type& r = cc.f(s); - - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "e::f::pre" << std::endl - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "e::f::old" << std::endl - << "c::f::old" << std::endl - #endif - << "c::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - // No old call here because not a base object. - << "c::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - #ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_TEST_old 1u - #else - #define BOOST_CONTRACT_TEST_old 0u - #endif - - BOOST_TEST_EQ(r.value, "C"); - BOOST_TEST_EQ(s.value, "cde"); - BOOST_TEST_EQ(s.copies(), BOOST_CONTRACT_TEST_old * 3); - BOOST_TEST_EQ(s.evals(), BOOST_CONTRACT_TEST_old * 3); - BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 local var. - - BOOST_TEST_EQ(cc.y.value, "cC"); - BOOST_TEST_EQ(cc.y.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.y.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.y.ctors(), cc.y.dtors() + 1); // 1 data member. - - BOOST_TEST_EQ(cc.t<'d'>::z.value, "dC"); - BOOST_TEST_EQ(cc.t<'d'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'d'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'d'>::z.ctors(), cc.t<'d'>::z.dtors() + 1); // 1 member. - - BOOST_TEST_EQ(cc.t<'e'>::z.value, "eC"); - BOOST_TEST_EQ(cc.t<'e'>::z.copies(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'e'>::z.evals(), BOOST_CONTRACT_TEST_old); - BOOST_TEST_EQ(cc.t<'e'>::z.ctors(), cc.t<'e'>::z.dtors() + 1); // 1 member. - - #undef BOOST_CONTRACT_TEST_old - return boost::report_errors(); -} - diff --git a/test/public_function/virtual_sparse.cpp b/test/public_function/virtual_sparse.cpp deleted file mode 100644 index 2b4ffc39..00000000 --- a/test/public_function/virtual_sparse.cpp +++ /dev/null @@ -1,418 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test subcontracting with sparse and complex inheritance graph. - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct j { - static void static_invariant() { out << "j::static_inv" << std::endl; } - void invariant() const { out << "j::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "j::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'j'); - }) - .old([] { out << "j::f::old" << std::endl; }) - .postcondition([] { out << "j::f::post" << std::endl; }) - ; - out << "j::f::body" << std::endl; - } -}; - -struct i { - static void static_invariant() { out << "i::static_inv" << std::endl; } - void invariant() const { out << "i::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "i::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'i'); - }) - .old([] { out << "i::f::old" << std::endl; }) - .postcondition([] { out << "i::f::post" << std::endl; }) - ; - out << "i::f::body" << std::endl; - } -}; - -struct k {}; - -struct h - #define BASES public j - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "h::static_inv" << std::endl; } - void invariant() const { out << "h::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>(v, &h::f, this, ch) - .precondition([&] { - out << "h::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'h'); - }) - .old([] { out << "h::f::old" << std::endl; }) - .postcondition([] { out << "h::f::post" << std::endl; }) - ; - out << "h::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct e - #define BASES public virtual i - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "e::static_inv" << std::endl; } - void invariant() const { out << "e::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>(v, &e::f, this, ch) - .precondition([&] { - out << "e::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'e'); - }) - .old([] { out << "e::f::old" << std::endl; }) - .postcondition([] { out << "e::f::post" << std::endl; }) - ; - out << "e::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -struct d - #define BASES public k, virtual public i - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "d::static_inv" << std::endl; } - void invariant() const { out << "d::inv" << std::endl; } -}; - -struct c { - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'c'); - }) - .old([] { out << "c::f::old" << std::endl; }) - .postcondition([] { out << "c::f::post" << std::endl; }) - ; - out << "c::f::body" << std::endl; - } -}; - -struct b - #define BASES public c, public d - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } -}; - -struct x {}; -struct y {}; -struct z {}; - -struct a - #define BASES public b, public x, public e, protected y, public h, \ - private z - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_f>(v, &a::f, this, ch) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch == 'a'); - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - - a aa; - out.str(""); - aa.f('a'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - << "i::f::pre" << std::endl - << "e::f::pre" << std::endl - << "j::f::pre" << std::endl - << "h::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - << "i::f::old" << std::endl - << "e::f::old" << std::endl - << "j::f::old" << std::endl - << "h::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "i::f::old" << std::endl - << "i::f::post" << std::endl - << "e::f::old" << std::endl - << "e::f::post" << std::endl - << "j::f::old" << std::endl - << "j::f::post" << std::endl - << "h::f::old" << std::endl - << "h::f::post" << std::endl - // No old call here because not a base object. - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - c cc; - out.str(""); - cc.f('c'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "c::f::old" << std::endl - #endif - << "c::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not a base object. - << "c::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - d dd; - out.str(""); - dd.f('i'); // d's f inherited from i. - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "i::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "i::f::old" << std::endl - #endif - << "i::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not a base object. - << "i::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - e ee; - out.str(""); - ee.f('e'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "i::f::pre" << std::endl - << "e::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "i::f::old" << std::endl - << "e::f::old" << std::endl - #endif - << "e::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "i::f::old" << std::endl - << "i::f::post" << std::endl - // No old call here because not a base object. - << "e::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - i ii; - out.str(""); - ii.f('i'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "i::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "i::f::old" << std::endl - #endif - << "i::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "i::static_inv" << std::endl - << "i::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not a base object. - << "i::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - h hh; - out.str(""); - hh.f('h'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "j::f::pre" << std::endl - << "h::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "j::f::old" << std::endl - << "h::f::old" << std::endl - #endif - << "h::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "j::static_inv" << std::endl - << "j::inv" << std::endl - << "h::static_inv" << std::endl - << "h::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "j::f::old" << std::endl - << "j::f::post" << std::endl - // No old call here because not a base object. - << "h::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - j jj; - out.str(""); - jj.f('j'); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "j::static_inv" << std::endl - << "j::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "j::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "j::f::old" << std::endl - #endif - << "j::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "j::static_inv" << std::endl - << "j::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - // No old call here because not a base object. - << "j::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/result/mixed_optional.cpp b/test/result/mixed_optional.cpp deleted file mode 100644 index 56fe335f..00000000 --- a/test/result/mixed_optional.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test base and derived classes mixing boost::optional and non- result types. - -#include "mixed_optional.hpp" - diff --git a/test/result/mixed_optional.hpp b/test/result/mixed_optional.hpp deleted file mode 100644 index 18729292..00000000 --- a/test/result/mixed_optional.hpp +++ /dev/null @@ -1,410 +0,0 @@ - -// no #include guard - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test base and derived classes mixing boost::optional and non- result types. - -#include "../detail/oteststream.hpp" -#include "../detail/counter.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct ch_tag; -typedef boost::contract::test::detail::counter ch_type; - -#ifdef BOOST_CONTRACT_TEST_REF // Test with result types by reference. - #define BOOST_CONTRACT_TEST_CH_TYPE ch_type& - #define BOOST_CONTRACT_TEST_CH_INIT = ch_init - ch_type ch_init; - unsigned const ch_extras = 2; // 1 local and 1 global var. -#else // Test with result types by value. - #define BOOST_CONTRACT_TEST_CH_TYPE ch_type - #define BOOST_CONTRACT_TEST_CH_INIT /* nothing */ - unsigned const ch_extras = 1; // 1 for local var (no global var). -#endif - -bool tested_d_copies = false; -struct d { - static void static_invariant() { out << "d::static_inv" << std::endl; } - void invariant() const { out << "d::inv" << std::endl; } - - virtual BOOST_CONTRACT_TEST_CH_TYPE f( - ch_type& ch, boost::contract::virtual_* v = 0) { - unsigned const old_ch_copies = ch_type::copies(); - boost::optional result; - boost::contract::check c = boost::contract::public_function( - v, result, this) - .precondition([&] { - out << "d::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch.value == 'd'); - }) - .old([] { out << "d::f::old" << std::endl; }) - .postcondition([&] (boost::optional const& result) { - out << "d::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(result->value == ch.value); - }) - ; - BOOST_TEST_EQ(ch_type::copies(), old_ch_copies); - tested_d_copies = true; - - out << "d::f::body" << std::endl; - return *(result = ch); - } -}; - -bool tested_c_copies = false; -struct c - #define BASES public d - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "c::static_inv" << std::endl; } - void invariant() const { out << "c::inv" << std::endl; } - - virtual BOOST_CONTRACT_TEST_CH_TYPE f( - ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { - unsigned const old_ch_copies = ch_type::copies(); - boost::optional result; - boost::contract::check c = boost::contract::public_function( - v, result, &c::f, this, ch) - .precondition([&] { - out << "c::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch.value == 'c'); - }) - .old([] { out << "c::f::old" << std::endl; }) - .postcondition([&] (boost::optional const& result) { - out << "c::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(result->value == ch.value); - }) - ; - BOOST_TEST_EQ(ch_type::copies(), old_ch_copies); - tested_c_copies = true; - - out << "c::f::body" << std::endl; - return *(result = ch); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -bool tested_b_copies = false; -struct b - #define BASES public c - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - virtual BOOST_CONTRACT_TEST_CH_TYPE f( - ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { - unsigned const old_ch_copies = ch_type::copies(); - BOOST_CONTRACT_TEST_CH_TYPE result BOOST_CONTRACT_TEST_CH_INIT; - boost::contract::check c = boost::contract::public_function( - v, result, &b::f, this, ch) - .precondition([&] { - out << "b::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch.value == 'b'); - }) - .old([] { out << "b::f::old" << std::endl; }) - .postcondition([&] (ch_type const& result) { - out << "b::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(result.value == ch.value); - }) - ; - BOOST_TEST_EQ(ch_type::copies(), old_ch_copies); - tested_b_copies = true; - - out << "b::f::body" << std::endl; - return result = ch; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -bool tested_a_copies = false; -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - virtual BOOST_CONTRACT_TEST_CH_TYPE f( - ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { - unsigned const old_ch_copies = ch_type::copies(); - boost::optional result; - boost::contract::check c = boost::contract::public_function( - v, result, &a::f, this, ch) - .precondition([&] { - out << "a::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch.value == 'a'); - }) - .old([] { out << "a::f::old" << std::endl; }) - .postcondition([&] (boost::optional const& result) { - out << "a::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(result->value == ch.value); - }) - ; - BOOST_TEST_EQ(ch_type::copies(), old_ch_copies); - tested_a_copies = true; - - out << "a::f::body" << std::endl; - return *(result = ch); - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -bool tested_e_copies = false; -struct e - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "e::static_inv" << std::endl; } - void invariant() const { out << "e::inv" << std::endl; } - - virtual BOOST_CONTRACT_TEST_CH_TYPE f( - ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { - unsigned const old_ch_copies = ch_type::copies(); - BOOST_CONTRACT_TEST_CH_TYPE result BOOST_CONTRACT_TEST_CH_INIT; - boost::contract::check c = boost::contract::public_function( - v, result, &e::f, this, ch) - .precondition([&] { - out << "e::f::pre" << std::endl; - BOOST_CONTRACT_ASSERT(ch.value == 'e'); - }) - .old([] { out << "e::f::old" << std::endl; }) - .postcondition([&] (ch_type const& result) { - out << "e::f::post" << std::endl; - BOOST_CONTRACT_ASSERT(result.value == ch.value); - }) - ; - BOOST_TEST_EQ(ch_type::copies(), old_ch_copies); - tested_e_copies = true; - - out << "e::f::body" << std::endl; - return result = ch; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - std::ostringstream ok; - ch_type ch; - #ifdef BOOST_CONTRACT_TEST_REF - ch_init.value = '\0'; - #endif - - // Test optional in overriding a::f and non-optional in overridden b::f. - a aa; - ch.value = 'a'; - out.str(""); - aa.f(ch); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "a::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - BOOST_TEST(tested_a_copies); - BOOST_TEST_EQ(ch_type::ctors(), ch_type::dtors() + ch_extras); - - // Test non-optional in overriding b::f and optional in overridden c::f. - b bb; - ch.value = 'b'; - out.str(""); - bb.f(ch); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - #endif - << "b::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - BOOST_TEST(tested_b_copies); - BOOST_TEST_EQ(ch_type::ctors(), ch_type::dtors() + ch_extras); - - // Test optional in both overriding c::f and overridden d::f. - c cc; - ch.value = 'c'; - out.str(""); - cc.f(ch); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "c::f::old" << std::endl - #endif - << "c::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - BOOST_TEST(tested_c_copies); - BOOST_TEST_EQ(ch_type::ctors(), ch_type::dtors() + ch_extras); - - // Test non-optional in both overriding c::f and overridden d::f. - e ee; - ch.value = 'e'; - out.str(""); - ee.f(ch); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "d::f::pre" << std::endl - << "c::f::pre" << std::endl - << "b::f::pre" << std::endl - << "e::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "d::f::old" << std::endl - << "c::f::old" << std::endl - << "b::f::old" << std::endl - << "e::f::old" << std::endl - #endif - << "e::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "d::static_inv" << std::endl - << "d::inv" << std::endl - << "c::static_inv" << std::endl - << "c::inv" << std::endl - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "e::static_inv" << std::endl - << "e::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "d::f::old" << std::endl - << "d::f::post" << std::endl - << "c::f::old" << std::endl - << "c::f::post" << std::endl - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "e::f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - BOOST_TEST(tested_e_copies); - BOOST_TEST_EQ(ch_type::ctors(), ch_type::dtors() + ch_extras); - - return boost::report_errors(); -} - diff --git a/test/result/mixed_optional_ref.cpp b/test/result/mixed_optional_ref.cpp deleted file mode 100644 index 5342e48f..00000000 --- a/test/result/mixed_optional_ref.cpp +++ /dev/null @@ -1,11 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test base and derived classes mixing boost::optional and non- result by ref. - -#define BOOST_CONTRACT_TEST_REF -#include "mixed_optional.hpp" - diff --git a/test/result/type_mismatch_error.cpp b/test/result/type_mismatch_error.cpp deleted file mode 100644 index 691162c2..00000000 --- a/test/result/type_mismatch_error.cpp +++ /dev/null @@ -1,50 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test override public function error on result type mismatch. - -#include -#include -#include -#include - -struct b { - virtual int f(boost::contract::virtual_* v = 0) { - // Unfortunately, this cannot be made to error at compile-time because - // in this case public_function does not that &b::f as param (but this - // will error at run-time on a virtual call via a derived class). - char result; - boost::contract::check c = boost::contract::public_function( - v, result, this); - return result; - } -}; - -struct a - #define BASES public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - virtual int f(boost::contract::virtual_* v = 0) /* override */ { - char result; - boost::contract::check c = boost::contract::public_function( - v, result, &a::f, this); // Error (result time mismatch). - #ifdef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #error "Forcing error even when public functions not checked" - #endif - return result; - } - BOOST_CONTRACT_OVERRIDE(f) -}; - -int main() { - a aa; - aa.f(); - return 0; -} - diff --git a/test/specify/auto_error.cpp b/test/specify/auto_error.cpp deleted file mode 100644 index daf6aad7..00000000 --- a/test/specify/auto_error.cpp +++ /dev/null @@ -1,15 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test auto error (for free func, but same for all contracts). - -#include - -int main() { - auto c = boost::contract::function(); // Error (can't use auto). - return 0; -} - diff --git a/test/specify/auto_pre_error.cpp b/test/specify/auto_pre_error.cpp deleted file mode 100644 index 41cccdfa..00000000 --- a/test/specify/auto_pre_error.cpp +++ /dev/null @@ -1,17 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test auto error after pre (for free func, but same for all contracts). - -#include - -int main() { - auto c = boost::contract::function() // Error (can't use auto). - .precondition([] {}) - ; - return 0; -} - diff --git a/test/specify/auto_pre_old_error.cpp b/test/specify/auto_pre_old_error.cpp deleted file mode 100644 index bd25cbec..00000000 --- a/test/specify/auto_pre_old_error.cpp +++ /dev/null @@ -1,18 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test auto error after old (for free func, but same for all contracts). - -#include - -int main() { - auto c = boost::contract::function() // Error (can't use auto). - .precondition([] {}) - .old([] {}) - ; - return 0; -} - diff --git a/test/specify/auto_pre_old_post_error.cpp b/test/specify/auto_pre_old_post_error.cpp deleted file mode 100644 index 6eb04b8f..00000000 --- a/test/specify/auto_pre_old_post_error.cpp +++ /dev/null @@ -1,19 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test auto error after post (for free func, but same for all contracts). - -#include - -int main() { - auto c = boost::contract::function() // Error (can't use auto). - .precondition([] {}) - .old([] {}) - .postcondition([] {}) - ; - return 0; -} - diff --git a/test/specify/auto_pre_old_post_except_error.cpp b/test/specify/auto_pre_old_post_except_error.cpp deleted file mode 100644 index 208fb2b1..00000000 --- a/test/specify/auto_pre_old_post_except_error.cpp +++ /dev/null @@ -1,20 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test auto error after except (for free func, but same for all contracts). - -#include - -int main() { - auto c = boost::contract::function() // Error (can't use auto). - .precondition([] {}) - .old([] {}) - .postcondition([] {}) - .except([] {}) - ; - return 0; -} - diff --git a/test/specify/except.cpp b/test/specify/except.cpp deleted file mode 100644 index 7e0eeb26..00000000 --- a/test/specify/except.cpp +++ /dev/null @@ -1,37 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying except, no pre, old, or post (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/except_old_error.cpp b/test/specify/except_old_error.cpp deleted file mode 100644 index e1013028..00000000 --- a/test/specify/except_old_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old after except error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .except([] {}) - .old([] {}) // Error (old after except). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/except_post_error.cpp b/test/specify/except_post_error.cpp deleted file mode 100644 index d629ca5b..00000000 --- a/test/specify/except_post_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test post after except error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .except([] {}) - .postcondition([] {}) // Error (post after except). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/except_pre_error.cpp b/test/specify/except_pre_error.cpp deleted file mode 100644 index 4efb9e01..00000000 --- a/test/specify/except_pre_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test pre after except error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .except([] {}) - .precondition([] {}) // Error (pre after except). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/missing_check.cpp b/test/specify/missing_check.cpp deleted file mode 100644 index 2a442bdb..00000000 --- a/test/specify/missing_check.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test missing contract check declaration gives run-time error. - -struct err {}; -#define BOOST_CONTRACT_ON_MISSING_CHECK_DECL { throw err(); } - -#include -#include -#include - -int main() { - boost::contract::check c = boost::contract::function() // Test this is OK. - .precondition([] {}) - .old([] {}) - .postcondition([] {}) - ; - - try { - boost::contract::function() // Test no `check c = ...` errors. - .precondition([] {}) - .old([] {}) - .postcondition([] {}) - ; - #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) - BOOST_TEST(false); // Error, must throw. - #endif - } catch(err const&) { - // OK, threw as expected. - } catch(...) { - BOOST_TEST(false); // Error, unexpected throw. - } - return boost::report_errors(); -} - diff --git a/test/specify/nothing.cpp b/test/specify/nothing.cpp deleted file mode 100644 index 8e44310a..00000000 --- a/test/specify/nothing.cpp +++ /dev/null @@ -1,32 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test no pre or post (for free func, but same for all contracts). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function(); - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); ok << "f::body" << std::endl; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/old.cpp b/test/specify/old.cpp deleted file mode 100644 index 6d318c5a..00000000 --- a/test/specify/old.cpp +++ /dev/null @@ -1,39 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying old, no pre, post, or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .old([] { out << "f::old" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/old_except.cpp b/test/specify/old_except.cpp deleted file mode 100644 index 6df1283e..00000000 --- a/test/specify/old_except.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying old and except, no pre or post (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .old([] { out << "f::old" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/old_post.cpp b/test/specify/old_post.cpp deleted file mode 100644 index dc90470e..00000000 --- a/test/specify/old_post.cpp +++ /dev/null @@ -1,44 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying old and post, no pre or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/old_post_except.cpp b/test/specify/old_post_except.cpp deleted file mode 100644 index 6afc73b6..00000000 --- a/test/specify/old_post_except.cpp +++ /dev/null @@ -1,45 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying old, post, and except, not pre (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/old_pre_error.cpp b/test/specify/old_pre_error.cpp deleted file mode 100644 index faa0fa5a..00000000 --- a/test/specify/old_pre_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test pre after old error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .old([] {}) - .precondition([] {}) // Error (pre after old). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/post.cpp b/test/specify/post.cpp deleted file mode 100644 index 38ed21a5..00000000 --- a/test/specify/post.cpp +++ /dev/null @@ -1,39 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying post, no pre, old, or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .postcondition([] { out << "f::post" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); ok - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/post_except.cpp b/test/specify/post_except.cpp deleted file mode 100644 index ead2e5e8..00000000 --- a/test/specify/post_except.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying post and except, no pre or old (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/post_old_error.cpp b/test/specify/post_old_error.cpp deleted file mode 100644 index bf493fac..00000000 --- a/test/specify/post_old_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test old after post error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .postcondition([] {}) - .old([] {}) // Error (old after post). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/post_pre_error.cpp b/test/specify/post_pre_error.cpp deleted file mode 100644 index 568aeb1a..00000000 --- a/test/specify/post_pre_error.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test pre after post error (same if not free func). - -#include -#include - -void f() { - boost::contract::check c = boost::contract::function() - .postcondition([] {}) - .precondition([] {}) // Error (pre after post). - ; -} - -int main() { - f(); - return 0; -} - diff --git a/test/specify/pre.cpp b/test/specify/pre.cpp deleted file mode 100644 index dbd6658b..00000000 --- a/test/specify/pre.cpp +++ /dev/null @@ -1,39 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre, no old, post, or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_except.cpp b/test/specify/pre_except.cpp deleted file mode 100644 index 55963f43..00000000 --- a/test/specify/pre_except.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre and except, no old or post (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_old.cpp b/test/specify/pre_old.cpp deleted file mode 100644 index 9996cac7..00000000 --- a/test/specify/pre_old.cpp +++ /dev/null @@ -1,44 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre and old, no post or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_old_except.cpp b/test/specify/pre_old_except.cpp deleted file mode 100644 index 2d659a46..00000000 --- a/test/specify/pre_old_except.cpp +++ /dev/null @@ -1,45 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specify pre, old, and except, no post (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_old_post.cpp b/test/specify/pre_old_post.cpp deleted file mode 100644 index 1377bc75..00000000 --- a/test/specify/pre_old_post.cpp +++ /dev/null @@ -1,48 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre, old, and post, no except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_old_post_except.cpp b/test/specify/pre_old_post_except.cpp deleted file mode 100644 index a9918208..00000000 --- a/test/specify/pre_old_post_except.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre, old, post, and except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .old([] { out << "f::old" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - << "f::old" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_post.cpp b/test/specify/pre_post.cpp deleted file mode 100644 index 559911ac..00000000 --- a/test/specify/pre_post.cpp +++ /dev/null @@ -1,44 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specifying pre and post, no old or except (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/specify/pre_post_except.cpp b/test/specify/pre_post_except.cpp deleted file mode 100644 index a96566a0..00000000 --- a/test/specify/pre_post_except.cpp +++ /dev/null @@ -1,45 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Test specify pre, post, and except, no old (same if not free func). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -void f() { - boost::contract::check c = boost::contract::function() - .precondition([] { out << "f::pre" << std::endl; }) - .postcondition([] { out << "f::post" << std::endl; }) - .except([] { out << "f::except" << std::endl; }) - ; - out << "f::body" << std::endl; -} - -int main() { - std::ostringstream ok; - - out.str(""); - f(); - ok.str(""); - ok - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "f::pre" << std::endl - #endif - << "f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "f::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} -

: boost::true_type {}; -} } // namespace -//] - -//[old_if_copyable_n_decl -class n { // Do not want to use boost::noncopyable but... - int num_; - -private: - n(n const&); // ...unimplemented private copy constructor (so non-copyable). - - /* ... */ -//] - -public: - n() : num_(0) {} - int operator+(int i) const { return num_ + i; } - n& operator+=(int i) { num_ += i; return *this; } - bool operator==(int i) const { return num_ == i; } -}; - -//[old_if_copyable_n_spec -// Specialize `boost::is_copy_constructible` (no need for this on C++11). -namespace boost { namespace contract { - template<> - struct is_old_value_copyable : boost::false_type {}; -} } // namespace -//] - -int main() { - int i = 0; // Copy constructor, copy and check old values. - offset(i, 3); - assert(i == 3); - - w j; // Expensive copy constructor, so never copy or check old values. - offset(j, 3); - assert(j == 3); - - p k; // No copy constructor, but still copy and check old values. - offset(k, 3); - assert(k == 3); - - n h; // No copy constructor, no compiler error but no old value checks. - offset(h, 3); - assert(h == 3); - - return 0; -} - diff --git a/example/features/old_no_macro.cpp b/example/features/old_no_macro.cpp deleted file mode 100644 index 41824dd0..00000000 --- a/example/features/old_no_macro.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[old_no_macro -template -class vector { -public: - virtual void push_back(T const& value, boost::contract::virtual_* v = 0) { - // Program old value instead of using `OLD(size())` macro. - boost::contract::old_ptr old_size = - boost::contract::make_old(v, boost::contract::copy_old(v) ? - size() : boost::contract::null_old()) - ; - - boost::contract::check c = boost::contract::public_function(v, this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - ; - - vect_.push_back(value); - } - - /* ... */ -//] - - unsigned size() const { return vect_.size(); } - -private: - std::vector vect_; -}; - -int main() { - vector vect; - vect.push_back(123); - assert(vect.size() == 1); - return 0; -} - diff --git a/example/features/optional_result.cpp b/example/features/optional_result.cpp deleted file mode 100644 index 98522ea4..00000000 --- a/example/features/optional_result.cpp +++ /dev/null @@ -1,41 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -//[optional_result -template -T& get(std::vector& vect) { - boost::optional result; // Result not initialized here... - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(Index < vect.size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(*result == vect[Index]); - }) - ; - - // Function body (executed after preconditions checked). - return *(result = vect[Index]); // ...result initialized here instead. -} -//] - -int main() { - std::vector v; - v.push_back(123); - v.push_back(456); - v.push_back(789); - int& x = get<1>(v); - assert(x == 456); - x = -456; - assert(v[1] == -456); - return 0; -} - diff --git a/example/features/optional_result_virtual.cpp b/example/features/optional_result_virtual.cpp deleted file mode 100644 index 3aee7aa5..00000000 --- a/example/features/optional_result_virtual.cpp +++ /dev/null @@ -1,88 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -template -class accessible { -public: - virtual T& at(unsigned index, boost::contract::virtual_* v = 0) = 0; - - // Could program class invariants and contracts for following too. - virtual T const& operator[](unsigned index) const = 0; - virtual unsigned size() const = 0; -}; - -//[optional_result_virtual -template -T& accessible::at(unsigned index, boost::contract::virtual_* v) { - boost::optional result; - // Pass `result` right after `v`... - boost::contract::check c = boost::contract::public_function(v, result, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index < size()); - }) - // ...plus postconditions take `result` as a parameter (not capture). - .postcondition([&] (boost::optional const& result) { - BOOST_CONTRACT_ASSERT(*result == operator[](index)); - }) - ; - - assert(false); - return *result; -} -//] - -template -class vector - #define BASES public accessible - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - T& at(unsigned index, boost::contract::virtual_* v = 0) /* override */ { - boost::optional result; - // Pass `result` right after `v`... - boost::contract::check c = boost::contract::public_function< - override_at>(v, result, &vector::at, this, index) - // ...plus postconditions take `result` as parameter (not capture). - .postcondition([&] (boost::optional const& result) { - if(index == 0) BOOST_CONTRACT_ASSERT(*result == front()); - }) - ; - - return *(result = vect_[index]); - } - - // Could program class invariants and contracts for following too. - T const& operator[](unsigned index) const { return vect_[index]; } - unsigned size() const { return vect_.size(); } - T const& front() const { return vect_.front(); } - void push_back(T const& value) { vect_.push_back(value); } - - BOOST_CONTRACT_OVERRIDE(at) - -private: - std::vector vect_; -}; - -int main() { - vector v; - v.push_back(123); - v.push_back(456); - v.push_back(789); - int& x = v.at(1); - assert(x == 456); - x = -456; - assert(v.at(1) == -456); - return 0; -} - diff --git a/example/features/overload.cpp b/example/features/overload.cpp deleted file mode 100644 index 36db4485..00000000 --- a/example/features/overload.cpp +++ /dev/null @@ -1,202 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include - -class lines { -public: - virtual std::string str(boost::contract::virtual_* v = 0) const = 0; - virtual std::string& str(boost::contract::virtual_* v = 0) = 0; - - virtual void put(std::string const& x, - boost::contract::virtual_* v = 0) = 0; - - virtual void put(char x, boost::contract::virtual_* v = 0) = 0; - - virtual void put(int x, bool tab = false, - boost::contract::virtual_* v = 0) = 0; -}; - -std::string lines::str(boost::contract::virtual_* v) const { - std::string result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (std::string const& result) { - if(result != "") BOOST_CONTRACT_ASSERT(*result.rbegin() == '\n'); - }) - ; - assert(false); - return result; -} - -std::string& lines::str(boost::contract::virtual_* v) { - boost::optional result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (boost::optional const& result) { - if(*result != "") BOOST_CONTRACT_ASSERT(*result->rbegin() == '\n'); - }) - ; - assert(false); - return *result; -} - -void lines::put(std::string const& x, boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(*x.rbegin() != '\n'); - }) - ; - assert(false); -} - -void lines::put(char x, boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(x != '\n'); - }) - ; - assert(false); -} - -void lines::put(int x, bool tab, - boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(x >= 0); - }) - ; - assert(false); -} - -//[overload -class string_lines - #define BASES public lines - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - BOOST_CONTRACT_OVERRIDES(str) // Invoked only once for all `str` overloads. - - std::string str(boost::contract::virtual_* v = 0) const /* override */ { - std::string result; - boost::contract::check c = boost::contract::public_function< - override_str>( - v, result, - // `static_cast` resolves overloaded function pointer ambiguities. - static_cast(&string_lines::str), - this - ); - - return result = str_; - } - - // Overload on (absence of) `const` qualifier. - std::string& str(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_str>( - v, str_, - // `static_cast` resolves overloaded function pointer ambiguities. - static_cast(&string_lines::str), - this - ); - - return str_; - } - - BOOST_CONTRACT_OVERRIDES(put) // Invoked only once for all `put` overloads. - - void put(std::string const& x, - boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::check c = boost::contract::public_function< - override_put>( - v, - // `static_cast` resolves overloaded function pointer ambiguities. - static_cast(&string_lines::put), - this, x - ) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(str() == *old_str + x + '\n'); - }) - ; - - str_ = str_ + x + '\n'; - } - - // Overload on argument type. - void put(char x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::check c = boost::contract::public_function< - override_put>( - v, - // `static_cast` resolves overloaded function pointer ambiguities. - static_cast(&string_lines::put), - this, x - ) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(str() == *old_str + x + '\n'); - }) - ; - - str_ = str_ + x + '\n'; - } - - // Overload on argument type and arity (also with default parameter). - void put(int x, bool tab = false, - boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::check c = boost::contract::public_function< - override_put>( - v, - // `static_cast` resolves overloaded function pointer ambiguities. - static_cast(&string_lines::put), - this, x, tab - ) - .postcondition([&] { - std::ostringstream s; - s << x; - BOOST_CONTRACT_ASSERT( - str() == *old_str + (tab ? "\t" : "") + s.str() + '\n'); - }) - ; - - std::ostringstream s; - s << str_ << (tab ? "\t" : "") << x << '\n'; - str_ = s.str(); - } - -private: - std::string str_; -}; -//] - -int main() { - string_lines s; - s.put("abc"); - assert(s.str() == "abc\n"); - s.put('x'); - assert(s.str() == "abc\nx\n"); - s.put(10); - assert(s.str() == "abc\nx\n10\n"); - s.put(20, true); - lines const& l = s; - assert(l.str() == "abc\nx\n10\n\t20\n"); - return 0; -} - diff --git a/example/features/private_protected.cpp b/example/features/private_protected.cpp deleted file mode 100644 index 304e7739..00000000 --- a/example/features/private_protected.cpp +++ /dev/null @@ -1,77 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[private_protected -class counter { -protected: // Protected functions use `function()` (like non-members). - void set(int n) { - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(n <= 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - - n_ = n; - } - -private: // Private functions use `function()` (like non-members). - void dec() { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT( - get() + 1 >= std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == *old_get - 1); - }) - ; - - set(get() - 1); - } - - int n_; - - /* ... */ -//] - -public: - int get() const { - int result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result <= 0); - BOOST_CONTRACT_ASSERT(result == n_); - }) - ; - - return result = n_; - } - - counter() : n_(0) {} // Should contract constructor and destructor too. - - void invariant() const { - BOOST_CONTRACT_ASSERT(get() <= 0); - } - - friend int main(); -}; - -int main() { - counter cnt; - assert(cnt.get() == 0); - cnt.dec(); - assert(cnt.get() == -1); - return 0; -} - diff --git a/example/features/private_protected_virtual.cpp b/example/features/private_protected_virtual.cpp deleted file mode 100644 index a145cadc..00000000 --- a/example/features/private_protected_virtual.cpp +++ /dev/null @@ -1,145 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[private_protected_virtual_counter -class counter { - // Virtual private and protected functions still declare extra - // `virtual_* = 0` parameter (otherwise they cannot be overridden), but... -protected: - virtual void set(int n, boost::contract::virtual_* = 0) { - boost::contract::check c = boost::contract::function() // ...no `v`. - .precondition([&] { - BOOST_CONTRACT_ASSERT(n <= 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - - n_ = n; - } - -private: - virtual void dec(boost::contract::virtual_* = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); // ...no `v`. - boost::contract::check c = boost::contract::function() // ...no `v`. - .precondition([&] { - BOOST_CONTRACT_ASSERT( - get() + 1 >= std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == *old_get - 1); - }) - ; - - set(get() - 1); - } - - int n_; - - /* ... */ -//] - -public: - virtual int get(boost::contract::virtual_* v = 0) const { - int result; - boost::contract::check c = boost::contract::public_function( - v, result, this) - .postcondition([&] (int const result) { - BOOST_CONTRACT_ASSERT(result <= 0); - BOOST_CONTRACT_ASSERT(result == n_); - }) - ; - - return result = n_; - } - - counter() : n_(0) {} // Should contract constructor and destructor too. - - void invariant() const { - BOOST_CONTRACT_ASSERT(get() <= 0); - } - - friend int main(); -}; - -//[private_protected_virtual_counter10 -class counter10 - #define BASES public counter - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // Overriding from non-public members so no subcontracting, no override_... - - virtual void set(int n, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(n % 10 == 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - - counter::set(n); - } - - virtual void dec(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT( - get() + 10 >= std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == *old_get - 10); - }) - ; - - set(get() - 10); - } - - /* ... */ -//] - - virtual int get(boost::contract::virtual_* v = 0) const { - int result; - boost::contract::check c = boost::contract::public_function< - override_get>(v, result, &counter10::get, this); - - return result = counter::get(); - } - BOOST_CONTRACT_OVERRIDE(get) - - // Should contract default constructor and destructor too. - - void invariant() const { - BOOST_CONTRACT_ASSERT(get() % 10 == 0); - } -}; - -int main() { - counter cnt; - assert(cnt.get() == 0); - cnt.dec(); - assert(cnt.get() == -1); - - counter10 cnt10; - counter& b = cnt10; // Polymorphic calls. - assert(b.get() == 0); - b.dec(); - assert(b.get() == -10); - - return 0; -} - diff --git a/example/features/private_protected_virtual_multi.cpp b/example/features/private_protected_virtual_multi.cpp deleted file mode 100644 index 17fb25c8..00000000 --- a/example/features/private_protected_virtual_multi.cpp +++ /dev/null @@ -1,209 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#ifdef BOOST_MSVC - -// WARNING: MSVC (at least up to VS 2015) gives a compile-time error if SFINAE -// cannot introspect a member because of its private or protected access level. -// That is incorrect, SFINAE should fail in these cases without generating -// compile-time errors like GCC and CLang do. Therefore, currently it is not -// possible to override a member that is public in one base but private or -// protected in other base using this library on MSVC (that can be done instead -// using this library on GCC or CLang). -int main() { return 0; } // Trivial program for MSVC. - -#else - -#include -#include -#include - -class counter { - // Virtual private and protected functions still declare extra - // `virtual_* = 0` parameter (otherwise they cannot be overridden). -protected: - virtual void set(int n, boost::contract::virtual_* = 0) { - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(n <= 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - - n_ = n; - } - -private: - virtual void dec(boost::contract::virtual_* = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT( - get() + 1 >= std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == *old_get - 1); - }) - ; - - set(get() - 1); - } - - int n_; - -public: - virtual int get(boost::contract::virtual_* v = 0) const { - int result; - boost::contract::check c = boost::contract::public_function( - v, result, this) - .postcondition([&] (int const result) { - BOOST_CONTRACT_ASSERT(result <= 0); - BOOST_CONTRACT_ASSERT(result == n_); - }) - ; - - return result = n_; - } - - counter() : n_(0) {} // Should contract constructor and destructor too. - - void invariant() const { - BOOST_CONTRACT_ASSERT(get() <= 0); - } - - friend int main(); -}; - -//[private_protected_virtual_multi_countable -class countable { -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(get() <= 0); - } - - virtual void dec(boost::contract::virtual_* v = 0) = 0; - virtual void set(int n, boost::contract::virtual_* v = 0) = 0; - virtual int get(boost::contract::virtual_* v = 0) const = 0; -}; - -/* ... */ -//] - -void countable::dec(boost::contract::virtual_* v) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(get() > std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() < *old_get); - }) - ; - assert(false); // Never executed by this library. -} - -void countable::set(int n, boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function( - v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(n <= 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - assert(false); // Never executed by this library. -} - -int countable::get(boost::contract::virtual_* v) const { - int result; - boost::contract::check c = boost::contract::public_function( - v, result, this); - assert(false); // Never executed by this library. -} - -//[private_protected_virtual_multi_counter10 -class counter10 - #define BASES public countable, public counter // Multiple inheritance. - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - // Overriding from public members from `countable` so use `override_...`. - - virtual void set(int n, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_set>(v, &counter10::set, this, n) - .precondition([&] { - BOOST_CONTRACT_ASSERT(n % 10 == 0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == n); - }) - ; - - counter::set(n); - } - - virtual void dec(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::check c = boost::contract::public_function< - override_dec>(v, &counter10::dec, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT( - get() + 10 >= std::numeric_limits::min()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(get() == *old_get - 10); - }) - ; - - set(get() - 10); - } - - BOOST_CONTRACT_OVERRIDES(set, dec) - - /* ... */ -//] - - virtual int get(boost::contract::virtual_* v = 0) const { - int result; - boost::contract::check c = boost::contract::public_function< - override_get>(v, result, &counter10::get, this); - - return result = counter::get(); - } - BOOST_CONTRACT_OVERRIDE(get) - - // Should contract default constructor and destructor too. - - void invariant() const { - BOOST_CONTRACT_ASSERT(get() % 10 == 0); - } -}; - -int main() { - counter cnt; - assert(cnt.get() == 0); - cnt.dec(); - assert(cnt.get() == -1); - - counter10 cnt10; - countable& b = cnt10; // Polymorphic calls. - assert(b.get() == 0); - b.dec(); - assert(b.get() == -10); - - return 0; -} - -#endif // MSVC - diff --git a/example/features/public.cpp b/example/features/public.cpp deleted file mode 100644 index 8ef443d9..00000000 --- a/example/features/public.cpp +++ /dev/null @@ -1,183 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -//[public_class_begin -class unique_identifiers - : private boost::contract::constructor_precondition -{ -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(size() >= 0); - } -//] - -//[public_constructor -public: - // Contract for a constructor. - unique_identifiers(int from, int to) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(from <= to); - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == (to - from + 1)); - }) - ; - - // Constructor body. - for(int id = from; id <= to; ++id) vect_.push_back(id); - } -//] - -//[public_destructor -public: - // Contract for a destructor. - virtual ~unique_identifiers() { - // Following contract checks class invariants. - boost::contract::check c = boost::contract::destructor(this); - - // Destructor body here... (do nothing in this example). - } -//] - - int size() const { - // Following contract checks invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.size(); - } - -//[public_function -public: - // Contract for a public function (but no static, virtual, or override). - bool find(int id) const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(size() == 0) BOOST_CONTRACT_ASSERT(!result); - }) - ; - - // Function body. - return result = std::find(vect_.begin(), vect_.end(), id) != - vect_.end(); - } -//] - -//[public_virtual_function -public: - // Contract for a public virtual function (but no override). - virtual int push_back(int id, boost::contract::virtual_* v = 0) { // Extra `v`. - int result; - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(id)); // Pass `v`. - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); // Pass `v`. - boost::contract::check c = boost::contract::public_function( - v, result, this) // Pass `v` and `result`. - .precondition([&] { - BOOST_CONTRACT_ASSERT(!find(id)); // ID cannot be already present. - }) - .postcondition([&] (int const result) { - if(!*old_find) { - BOOST_CONTRACT_ASSERT(find(id)); - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - } - BOOST_CONTRACT_ASSERT(result == id); - }) - ; - - // Function body. - vect_.push_back(id); - return result = id; - } -//] - -private: - std::vector vect_; -//[public_class_end - /* ... */ -}; -//] - -//[public_derived_class_begin -class identifiers - #define BASES public unique_identifiers - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Bases typedef. - #undef BASES - - void invariant() const { // Check in AND with bases. - BOOST_CONTRACT_ASSERT(empty() == (size() == 0)); - } -//] - -//[public_function_override -public: - // Contract for a public function override. - int push_back(int id, boost::contract::virtual_* v = 0) /* override */ { - int result; - boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(id)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function< - override_push_back // Pass override plus below function pointer... - >(v, result, &identifiers::push_back, this, id) // ...and arguments. - .precondition([&] { // Check in OR with bases. - BOOST_CONTRACT_ASSERT(find(id)); // ID can be already present. - }) - .postcondition([&] (int const result) { // Check in AND with bases. - if(*old_find) BOOST_CONTRACT_ASSERT(size() == *old_size); - }) - ; - - // Function body. - if(!find(id)) unique_identifiers::push_back(id); // Else, do nothing. - return result = id; - } - BOOST_CONTRACT_OVERRIDE(push_back) // Define `override_push_back`. -//] - - bool empty() const { - // Following contract checks invariants. - boost::contract::check c = boost::contract::public_function(this); - return size() == 0; - } - - identifiers(int from, int to) : unique_identifiers(from, to) { - // Following contract checks invariants. - boost::contract::check c = boost::contract::constructor(this); - } - -//[public_derived_class_end - /* ... */ -}; -//] - -int main() { - unique_identifiers uids(1, 4); - assert(uids.find(2)); - assert(!uids.find(5)); - uids.push_back(5); - assert(uids.find(5)); - - identifiers ids(10, 40); - assert(!ids.find(50)); - ids.push_back(50); - ids.push_back(50); - assert(ids.find(50)); - - return 0; -} - diff --git a/example/features/pure_virtual_public.cpp b/example/features/pure_virtual_public.cpp deleted file mode 100644 index ac15d23c..00000000 --- a/example/features/pure_virtual_public.cpp +++ /dev/null @@ -1,89 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -//[pure_virtual_public_base_begin -template -class range { -public: - // Pure virtual function declaration (contract in definition below). - virtual Iterator begin(boost::contract::virtual_* v = 0) = 0; -//] - - // Could program class invariants and contracts for the following too. - virtual Iterator end() = 0; - virtual bool empty() const = 0; - -//[pure_virtual_public_base_end - /* ... */ -}; -//] - -//[pure_virtual_public_base_impl -// Pure virtual function default implementation (out-of-line in C++). -template -Iterator range::begin(boost::contract::virtual_* v) { - Iterator result; // As usual, virtual pass `result` right after `v`... - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (Iterator const& result) { - if(empty()) BOOST_CONTRACT_ASSERT(result == end()); - }) - ; - - // Pure function body (never executed by this library). - assert(false); - return result; -} -//] - -template -class vector - #define BASES public range::iterator> - : BASES -{ -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - typedef typename std::vector::iterator iterator; - - iterator begin(boost::contract::virtual_* v = 0) /* override */ { - iterator result; - // Again, pass result right after `v`... - boost::contract::check c = boost::contract::public_function< - override_begin>(v, result, &vector::begin, this) - // ...plus postconditions take `result` as parameter (not capture). - .postcondition([&] (iterator const& result) { - if(!empty()) BOOST_CONTRACT_ASSERT(*result == front()); - }) - ; - - return result = vect_.begin(); - } - BOOST_CONTRACT_OVERRIDE(begin) - - // Could program class invariants and contracts for the following too. - iterator end() { return vect_.end(); } - bool empty() const { return vect_.empty(); } - T const& front() const { return vect_.front(); } - void push_back(T const& value) { vect_.push_back(value); } - -private: - std::vector vect_; -}; - -int main() { - vector v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - range::iterator>& r = v; - assert(*(r.begin()) == 1); - return 0; -} - diff --git a/example/features/separate_body.cpp b/example/features/separate_body.cpp deleted file mode 100644 index 268d4da1..00000000 --- a/example/features/separate_body.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include "separate_body.hpp" -#include - -//[separate_body_cpp -template -void array::constructor_body(unsigned count) { - for(unsigned i = 0; i < count; ++i) values_[i] = T(); - size_ = count; -} - -template -void array::destructor_body() { delete[] values_; } - -template -void array::push_back_body(T const& value) { - values_[size_++] = value; -} - -/* ... */ -//] - -template -unsigned array::size_body() const { return size_; } - -int main() { - array a(2); - assert(a.size() == 2); - a.push_back('x'); - assert(a.size() == 3); - return 0; -} - diff --git a/example/features/separate_body.hpp b/example/features/separate_body.hpp deleted file mode 100644 index 8e359f7c..00000000 --- a/example/features/separate_body.hpp +++ /dev/null @@ -1,78 +0,0 @@ - -#ifndef SEPARATE_BODY_HPP_ -#define SEPARATE_BODY_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -//[separate_body_hpp -template -class array : - private boost::contract::constructor_precondition > { -public: - void invariant() const { - BOOST_CONTRACT_ASSERT(size() <= MaxSize); - } - - explicit array(unsigned count) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(count <= MaxSize); - }), - values_(new T[MaxSize]) // Still, member initializations must be here. - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - }) - ; - constructor_body(count); // Separate constructor body implementation. - } - - virtual ~array() { - boost::contract::check c = boost::contract::destructor(this); // Inv. - destructor_body(); // Separate destructor body implementation. - } - - virtual void push_back(T const& value, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() < MaxSize); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - }) - ; - push_back_body(value); - } - -private: - // Contracts in class declaration (above), but body implementations are not. - void constructor_body(unsigned count); - void destructor_body(); - void push_back_body(T const& value); - - /* ... */ -//] - -public: - unsigned size() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return size_body(); - } - -private: - unsigned size_body() const; - - T* values_; - unsigned size_; -}; - -#endif // #include guard - diff --git a/example/features/static_public.cpp b/example/features/static_public.cpp deleted file mode 100644 index 92534906..00000000 --- a/example/features/static_public.cpp +++ /dev/null @@ -1,69 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -//[static_public -template -class make { -public: - static void static_invariant() { // Static class invariants. - BOOST_CONTRACT_ASSERT(instances() >= 0); - } - - // Contract for a static public function. - static int instances() { - // Explicit template parameter `make` (check static invariants). - boost::contract::check c = boost::contract::public_function(); - - return instances_; // Function body. - } - - /* ... */ -//] - - make() : object() { - boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); - }) - ; - - ++instances_; - } - - ~make() { - boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::check c = boost::contract::destructor(this) - .postcondition([&] { // (An example of destructor postconditions.) - BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1); - }) - ; - - --instances_; - } - - C object; - -private: - static int instances_; -}; - -template -int make::instances_ = 0; - -int main() { - struct x {}; - make x1, x2, x3; - assert(make::instances() == 3); - - return 0; -} - diff --git a/example/features/throw_on_failure.cpp b/example/features/throw_on_failure.cpp deleted file mode 100644 index 2e9fbb64..00000000 --- a/example/features/throw_on_failure.cpp +++ /dev/null @@ -1,141 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -//[throw_on_failure_class_begin -struct too_large_error {}; - -template -class cstring - #define BASES private boost::contract::constructor_precondition > - : BASES -{ -//] -public: - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - -//[throw_on_failure_ctor -public: - /* implicit */ cstring(char const* chars) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(chars); // Throw `assertion_failure`. - // Or, throw user-defined exception. - if(std::strlen(chars) > MaxSize) throw too_large_error(); - }) - { -//] - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == std::strlen(chars)); - }) - ; - - size_ = std::strlen(chars); - for(unsigned i = 0; i < size_; ++i) chars_[i] = chars[i]; - chars_[size_] = '\0'; - } - -//[throw_on_failure_dtor -public: - void invariant() const { - if(size() > MaxSize) throw too_large_error(); // Throw user-defined ex. - BOOST_CONTRACT_ASSERT(chars_); // Or, throw `assertion_failure`. - BOOST_CONTRACT_ASSERT(chars_[size()] == '\0'); - } - - ~cstring() noexcept { // Exception specifiers apply to contract code. - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } -//] - - unsigned size() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return size_; - } - -private: - char chars_[MaxSize + 1]; - unsigned size_; -//[throw_on_failure_class_end - /* ... */ -}; -//] - -void bad_throwing_handler() { // For docs only (not actually called here). - //[throw_on_failure_bad_handler - // Warning... might cause destructors to throw (unless declared noexcept). - boost::contract::set_invariant_failure( - [] (boost::contract::from) { - throw; // Throw no matter if from destructor, etc. - } - ); - //] -} - -//[throw_on_failure_handlers -int main() { - boost::contract::set_precondition_failure( - boost::contract::set_postcondition_failure( - boost::contract::set_invariant_failure( - boost::contract::set_old_failure( - [] (boost::contract::from where) { - if(where == boost::contract::from_destructor) { - // Cannot throw from destructors in C++. - std::clog << "ignored destructor contract failure" << std::endl; - } else throw; // Re-throw (assertion_failure, user-defined, etc.). - } - )))); - boost::contract::set_except_failure( - [] (boost::contract::from where) { - // Already an active exception so can't throw another in C++. - std::clog << "ignored exception guarantee failure" << std::endl; - } - ); - boost::contract::set_check_failure( - [] { - // But now CHECK cannot be used within destructor implementations. - throw; // Re-throw (assertion_failure, user-defined, etc.). - } - ); - - /* ... */ -//] - - { - cstring<3> s("abc"); - assert(s.size() == 3); - } - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - // These failures properly handled only when preconditions checked. - - try { - char* c = 0; - cstring<3> s(c); - assert(false); - } catch(boost::contract::assertion_failure const& error) { - // OK (expected). - std::clog << "ignored: " << error.what() << std::endl; - } catch(...) { assert(false); } - - try { - cstring<3> s("abcd"); - assert(false); - } catch(too_large_error const&) {} // OK (expected). - catch(...) { assert(false); } - #endif - - return 0; -} - diff --git a/example/features/union.cpp b/example/features/union.cpp deleted file mode 100644 index d73b09ab..00000000 --- a/example/features/union.cpp +++ /dev/null @@ -1,136 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -#ifdef BOOST_GCC // G++ does not support static union members yet. - int instances_ = 0; -#endif - -//[union -union positive { -public: - static void static_invariant() { // Static class invariants. - BOOST_CONTRACT_ASSERT(instances() >= 0); - } - - void invariant() const { // Class invariants. - BOOST_CONTRACT_ASSERT(i_ > 0); - BOOST_CONTRACT_ASSERT(d_ > 0); - } - - // Contracts for constructor, as usual but... - explicit positive(int x) { - // ...unions cannot have bases so constructor preconditions here. - boost::contract::constructor_precondition pre([&] { - BOOST_CONTRACT_ASSERT(x > 0); - }); - boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); - }) - ; - - i_ = x; - ++instances_; - } - - // Contracts for destructor (as usual). - ~positive() { - boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::check c = boost::contract::destructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1); - }) - ; - - --instances_; - } - - // Contracts for public function (as usual, but no virtual or override). - void get(int& x) { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(x > 0); - }); - ; - - x = i_; - } - - // Contracts for static public function (as usual). - static int instances() { - boost::contract::check c = boost::contract::public_function(); - return instances_; - } - -private: - int i_; - double d_; - - /* ... */ -//] - -public: - explicit positive(double x) { - // Unions cannot have bases so constructor preconditions here. - boost::contract::constructor_precondition pre([&] { - BOOST_CONTRACT_ASSERT(x > 0); - }); - boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); - }) - ; - - d_ = x; - ++instances_; - } - - void get(double& x) { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(x > 0); - }); - ; - - x = d_; - } - - #ifndef BOOST_GCC // G++ does not support static union members yet. - static int instances_; - #endif -}; - -#ifndef BOOST_GCC // G++ does not support static union members yet. - int positive::instances_ = 0; -#endif - -int main() { - { - int i = -456; - positive p(123); - assert(p.instances() == 1); - p.get(i); - assert(i == 123); - - double d = -4.56; - positive q(1.23); - assert(q.instances() == 2); - q.get(d); - assert(d == 1.23); - } - assert(positive::instances() == 0); - return 0; -} - diff --git a/example/features/volatile.cpp b/example/features/volatile.cpp deleted file mode 100644 index c89f1a0e..00000000 --- a/example/features/volatile.cpp +++ /dev/null @@ -1,102 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -//[volatile -class a { -public: - static void static_invariant(); // Static invariants. - void invariant() const volatile; // Volatile invariants. - void invariant() const; // Const invariants. - - a() { // Check static, volatile, and const invariants. - boost::contract::check c= boost::contract::constructor(this); - } - - ~a() { // Check static, volatile, and const invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - void nc() { // Check static and const invariants. - boost::contract::check c = boost::contract::public_function(this); - } - - void c() const { // Check static and const invariants. - boost::contract::check c = boost::contract::public_function(this); - } - - void v() volatile { // Check static and volatile invariants. - boost::contract::check c = boost::contract::public_function(this); - } - - void cv() const volatile { // Check static and volatile invariants. - boost::contract::check c = boost::contract::public_function(this); - } - - static void s() { // Check static invariants only. - boost::contract::check c = boost::contract::public_function(); - } -}; -//] - -bool static_inv_checked, cv_inv_checked, const_inv_checked; -void a::static_invariant() { static_inv_checked = true; } -void a::invariant() const volatile { cv_inv_checked = true; } -void a::invariant() const { const_inv_checked = true; } - -int main() { - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - { - static_inv_checked = cv_inv_checked = const_inv_checked = false; - a x; - assert(static_inv_checked); - assert(cv_inv_checked); - assert(const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - x.nc(); - assert(static_inv_checked); - assert(!cv_inv_checked); - assert(const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - x.c(); - assert(static_inv_checked); - assert(!cv_inv_checked); - assert(const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - x.v(); - assert(static_inv_checked); - assert(cv_inv_checked); - assert(!const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - x.cv(); - assert(static_inv_checked); - assert(cv_inv_checked); - assert(!const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - x.s(); - assert(static_inv_checked); - assert(!cv_inv_checked); - assert(!const_inv_checked); - - static_inv_checked = cv_inv_checked = const_inv_checked = false; - } // Call destructor. - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - assert(static_inv_checked); - assert(cv_inv_checked); - assert(const_inv_checked); - #endif - #endif - - return 0; -} - diff --git a/example/meyer97/stack3.cpp b/example/meyer97/stack3.cpp deleted file mode 100644 index e91378b6..00000000 --- a/example/meyer97/stack3.cpp +++ /dev/null @@ -1,192 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[meyer97_stack3 -// File: stack3.cpp -#include "stack4.hpp" -#include -#include -#include - -// Dispenser LIFO with max capacity using error codes. -template -class stack3 { - friend class boost::contract::access; - - void invariant() const { - if(!error()) { - BOOST_CONTRACT_ASSERT(count() >= 0); // Count non-negative. - BOOST_CONTRACT_ASSERT(count() <= capacity()); // Count bounded. - // Empty if no element. - BOOST_CONTRACT_ASSERT(empty() == (count() == 0)); - } - } - -public: - enum error_code { - no_error = 0, - overflow_error, - underflow_error, - size_error - }; - - /* Initialization */ - - // Create stack for max of n elems, if n < 0 set error (no preconditions). - explicit stack3(int n, T const& default_value = T()) : - stack_(0), error_(no_error) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - // Error if impossible. - BOOST_CONTRACT_ASSERT((n < 0) == (error() == size_error)); - // No error if possible. - BOOST_CONTRACT_ASSERT((n >= 0) == !error()); - // Created if no error. - if(!error()) BOOST_CONTRACT_ASSERT(capacity() == n); - }) - ; - - if(n >= 0) stack_ = stack4(n); - else error_ = size_error; - } - - /* Access */ - - // Max number of stack elements. - int capacity() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return stack_.capacity(); - } - - // Number of stack elements. - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return stack_.count(); - } - - // Top element if present, otherwise none and set error (no preconditions). - boost::optional item() const { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Error if impossible. - BOOST_CONTRACT_ASSERT(empty() == (error() == underflow_error)); - // No error if possible. - BOOST_CONTRACT_ASSERT(!empty() == !error()); - }) - ; - - if(!empty()) { - error_ = no_error; - return boost::optional(stack_.item()); - } else { - error_ = underflow_error; - return boost::optional(); - } - } - - /* Status Report */ - - // Error indicator set by various operations. - error_code error() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return error_; - } - - bool empty() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return stack_.empty(); - } - - bool full() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return stack_.full(); - } - - /* Element Change */ - - // Add x to top if capacity allows, otherwise set error (no preconditions). - void put(T const& x) { - boost::contract::old_ptr old_full = BOOST_CONTRACT_OLDOF(full()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Error if impossible. - BOOST_CONTRACT_ASSERT(*old_full == (error() == overflow_error)); - // No error if possible. - BOOST_CONTRACT_ASSERT(!*old_full == !error()); - if(!error()) { // If no error... - BOOST_CONTRACT_ASSERT(!empty()); // ...not empty. - BOOST_CONTRACT_ASSERT(*item() == x); // ...added to top. - // ...one more. - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); - } - }) - ; - - if(full()) error_ = overflow_error; - else { - stack_.put(x); - error_ = no_error; - } - } - - // Remove top element if possible, otherwise set error (no preconditions). - void remove() { - boost::contract::old_ptr old_empty = - BOOST_CONTRACT_OLDOF(empty()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Error if impossible. - BOOST_CONTRACT_ASSERT(*old_empty == (error() == - underflow_error)); - // No error if possible. - BOOST_CONTRACT_ASSERT(!*old_empty == !error()); - if(!error()) { // If no error... - BOOST_CONTRACT_ASSERT(!full()); // ...not full. - // ...one less. - BOOST_CONTRACT_ASSERT(count() == *old_count - 1); - } - }) - ; - - if(empty()) error_ = underflow_error; - else { - stack_.remove(); - error_ = no_error; - } - } - -private: - stack4 stack_; - mutable error_code error_; -}; - -int main() { - stack3 s(3); - assert(s.capacity() == 3); - assert(s.count() == 0); - assert(s.empty()); - assert(!s.full()); - - s.put(123); - assert(!s.empty()); - assert(!s.full()); - assert(*s.item() == 123); - - s.remove(); - assert(s.empty()); - assert(!s.full()); - - return 0; -} -//] - diff --git a/example/meyer97/stack4.e b/example/meyer97/stack4.e deleted file mode 100644 index b9827f52..00000000 --- a/example/meyer97/stack4.e +++ /dev/null @@ -1,201 +0,0 @@ - --- Copyright (C) 2008-2017 Lorenzo Caminiti --- Distributed under the Boost Software License, Version 1.0 (see accompanying --- file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). --- See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[meyer97_stack4_e --- Extra spaces, newlines, etc. for visual alignment with this library code. - - - - - -indexing - destription: "Dispenser with LIFO access policy and a fixed max capacity." -class interface STACK4[G] creation make -- Interface only (no implementation). - - - - - - - -invariant - count_non_negative: count >= 0 - count_bounded: count <= capacity - empty_if_no_elements: empty = (count = 0) - - - -feature -- Initialization - - -- Allocate stack for a maximum of n elements. - make(n: INTEGER) is - require - non_negative_capacity: n >= 0 - ensure - capacity_set: capacity = n - end - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -feature -- Access - - -- Max number of stack elements. - capacity: INTEGER - - - - - - -- Number of stack elements. - count: INTEGER - - - - - - -- Top element. - item: G is - require - not_empty: not empty -- i.e., count > 0 - end - - - - - - -feature -- Status report - - -- Is stack empty? - empty: BOOLEAN is - ensure - empty_definition: result = (count = 0) - end - - - - - - - - - -- Is stack full? - full: BOOLEAN is - ensure - full_definition: result = (count = capacity) - end - - - - - - - - -feature -- Element change - - -- Add x on top. - put(x: G) is - require - not_full: not full - ensure - not_empty: not empty - added_to_top: item = x - one_more_item: count = old count + 1 - end - - - - - - - - - -- Remove top element. - remove is - require - not_empty: not empty -- i.e., count > 0 - ensure - not_full: not full - one_fewer_item: count = old count - 1 - - end - - - - - - - - - - - - - - - - - - - - - - - -end -- class interface STACK4 - --- End. -//] - diff --git a/example/meyer97/stack4.hpp b/example/meyer97/stack4.hpp deleted file mode 100644 index 961632a1..00000000 --- a/example/meyer97/stack4.hpp +++ /dev/null @@ -1,201 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[meyer97_stack4 -// File: stack4.hpp -#ifndef STACK4_HPP_ -#define STACK4_HPP_ - -#include - -// Dispenser with LIFO access policy and fixed max capacity. -template -class stack4 - #define BASES private boost::contract::constructor_precondition > - : BASES -{ - friend boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Count non-negative. - BOOST_CONTRACT_ASSERT(count() <= capacity()); // Count bounded. - BOOST_CONTRACT_ASSERT(empty() == (count() == 0)); // Empty if no elem. - } - -public: - /* Initialization */ - - // Allocate static from a maximum of n elements. - explicit stack4(int n) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative capacity. - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() == n); // Capacity set. - }) - ; - - capacity_ = n; - count_ = 0; - array_ = new T[n]; - } - - // Deep copy via constructor. - /* implicit */ stack4(stack4 const& other) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() == other.capacity()); - BOOST_CONTRACT_ASSERT(count() == other.count()); - BOOST_CONTRACT_ASSERT_AXIOM(*this == other); - }) - ; - - capacity_ = other.capacity_; - count_ = other.count_; - array_ = new T[other.capacity_]; - for(int i = 0; i < other.count_; ++i) array_[i] = other.array_[i]; - } - - // Deep copy via assignment. - stack4& operator=(stack4 const& other) { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() == other.capacity()); - BOOST_CONTRACT_ASSERT(count() == other.count()); - BOOST_CONTRACT_ASSERT_AXIOM(*this == other); - }) - ; - - delete[] array_; - capacity_ = other.capacity_; - count_ = other.count_; - array_ = new T[other.capacity_]; - for(int i = 0; i < other.count_; ++i) array_[i] = other.array_[i]; - return *this; - } - - // Destroy this stack. - virtual ~stack4() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - delete[] array_; - } - - /* Access */ - - // Max number of stack elements. - int capacity() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return capacity_; - } - - // Number of stack elements. - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return count_; - } - - // Top element. - T const& item() const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); // Not empty (i.e., count > 0). - }) - ; - - return array_[count_ - 1]; - } - - /* Status Report */ - - // Is stack empty? - bool empty() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Empty definition. - BOOST_CONTRACT_ASSERT(result == (count() == 0)); - }) - ; - - return result = (count_ == 0); - } - - // Is stack full? - bool full() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT( // Full definition. - result == (count() == capacity())); - }) - ; - - return result = (count_ == capacity_); - } - - /* Element Change */ - - // Add x on top. - void put(T const& x) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!full()); // Not full. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); // Not empty. - BOOST_CONTRACT_ASSERT(item() == x); // Added to top. - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // One more. - }) - ; - - array_[count_++] = x; - } - - // Remove top element. - void remove() { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); // Not empty (i.e., count > 0). - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!full()); // Not full. - BOOST_CONTRACT_ASSERT(count() == *old_count - 1); // One less. - }) - ; - - --count_; - } - - /* Friend Helpers */ - - friend bool operator==(stack4 const& left, stack4 const& right) { - boost::contract::check inv1 = boost::contract::public_function(&left); - boost::contract::check inv2 = boost::contract::public_function(&right); - if(left.count_ != right.count_) return false; - for(int i = 0; i < left.count_; ++i) { - if(left.array_[i] != right.array_[i]) return false; - } - return true; - } - -private: - int capacity_; - int count_; - T* array_; // Internally use C-style array. -}; - -#endif // #include guard -//] - diff --git a/example/meyer97/stack4_main.cpp b/example/meyer97/stack4_main.cpp deleted file mode 100644 index a0c9c93c..00000000 --- a/example/meyer97/stack4_main.cpp +++ /dev/null @@ -1,30 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[meyer97_stack4_main -#include "stack4.hpp" -#include - -int main() { - stack4 s(3); - assert(s.capacity() == 3); - assert(s.count() == 0); - assert(s.empty()); - assert(!s.full()); - - s.put(123); - assert(!s.empty()); - assert(!s.full()); - assert(s.item() == 123); - - s.remove(); - assert(s.empty()); - assert(!s.full()); - - return 0; -} -//] - diff --git a/example/mitchell02/counter/counter.hpp b/example/mitchell02/counter/counter.hpp deleted file mode 100644 index f975ed79..00000000 --- a/example/mitchell02/counter/counter.hpp +++ /dev/null @@ -1,70 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_counter -#ifndef COUNTER_HPP_ -#define COUNTER_HPP_ - -#include "../observer/subject.hpp" -#include - -class counter - #define BASES public subject - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - -public: - /* Creation */ - - // Construct counter with specified value. - explicit counter(int a_value = 10) : value_(a_value) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(value() == a_value); // Value set. - }) - ; - } - - // Destroy counter. - virtual ~counter() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - /* Queries */ - - // Current counter value. - int value() const { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::public_function(this); - return value_; - } - - /* Commands */ - - // Decrement counter value. - void decrement() { - boost::contract::old_ptr old_value = BOOST_CONTRACT_OLDOF(value()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(value() == *old_value - 1); // Decrement. - }) - ; - - --value_; - notify(); // Notify all attached observers. - } - -private: - int value_; -}; - -#endif // #include guard -//] - diff --git a/example/mitchell02/counter/decrement_button.hpp b/example/mitchell02/counter/decrement_button.hpp deleted file mode 100644 index 4a20c123..00000000 --- a/example/mitchell02/counter/decrement_button.hpp +++ /dev/null @@ -1,92 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_decrement_button -#ifndef DECREMENT_BUTTON_HPP_ -#define DECREMENT_BUTTON_HPP_ - -#include "push_button.hpp" -#include "counter.hpp" -#include "../observer/observer.hpp" -#include -#include - -class decrement_button - #define BASES public push_button, public observer, \ - private boost::noncopyable - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - BOOST_CONTRACT_OVERRIDES(on_bn_clicked, up_to_date_with_subject, update); - -public: - /* Creation */ - - explicit decrement_button(counter& a_counter) : counter_(a_counter) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - // Enable iff positive value. - BOOST_CONTRACT_ASSERT(enabled() == (a_counter.value() > 0)); - }) - ; - counter_.attach(this); - } - - // Destroy button. - virtual ~decrement_button() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - /* Commands */ - - virtual void on_bn_clicked(boost::contract::virtual_* v = 0) - /* override */ { - boost::contract::old_ptr old_value = - BOOST_CONTRACT_OLDOF(v, counter_.value()); - boost::contract::check c = boost::contract::public_function< - override_on_bn_clicked - >(v, &decrement_button::on_bn_clicked, this) - .postcondition([&] { - // Counter decremented. - BOOST_CONTRACT_ASSERT(counter_.value() == *old_value - 1); - }) - ; - counter_.decrement(); - } - - virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0) - const /* override */ { - bool result; - boost::contract::check c = boost::contract::public_function< - override_up_to_date_with_subject - >(v, result, &decrement_button::up_to_date_with_subject, this); - - return result = true; // For simplicity, assume always up-to-date. - } - - virtual void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_update>(v, &decrement_button::update, this) - .postcondition([&] { - // Enabled iff positive value. - BOOST_CONTRACT_ASSERT(enabled() == (counter_.value() > 0)); - }) - ; - - if(counter_.value() == 0) disable(); - else enable(); - } - -private: - counter& counter_; -}; - -#endif // #include guard -//] - diff --git a/example/mitchell02/counter/push_button.hpp b/example/mitchell02/counter/push_button.hpp deleted file mode 100644 index f0b388ee..00000000 --- a/example/mitchell02/counter/push_button.hpp +++ /dev/null @@ -1,86 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_push_button -#ifndef PUSH_BUTTON_HPP_ -#define PUSH_BUTTON_HPP_ - -#include -#include - -class push_button { -public: - // No inv and no bases so contracts optional if no pre, post, and override. - - /* Creation */ - - // Create an enabled button. - push_button() : enabled_(true) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(enabled()); // Enabled. - }) - ; - } - - // Destroy button. - virtual ~push_button() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - /* Queries */ - - // If button is enabled. - bool enabled() const { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::public_function(this); - return enabled_; - } - - /* Commands */ - - // Enable button. - void enable() { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(enabled()); // Enabled. - }) - ; - - enabled_ = true; - } - - // Disable button. - void disable() { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(!enabled()); // Disabled. - }) - ; - - enabled_ = false; - } - - // Invoke externally when button clicked. - virtual void on_bn_clicked(boost::contract::virtual_* v = 0) = 0; - -private: - bool enabled_; -}; - -void push_button::on_bn_clicked(boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(enabled()); // Enabled. - }) - ; - assert(false); -} - -#endif // #include guard -//] - diff --git a/example/mitchell02/counter_main.cpp b/example/mitchell02/counter_main.cpp deleted file mode 100644 index 7c392451..00000000 --- a/example/mitchell02/counter_main.cpp +++ /dev/null @@ -1,79 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_counter_main -#include "counter/counter.hpp" -#include "counter/decrement_button.hpp" -#include "observer/observer.hpp" -#include - -int test_counter; - -class view_of_counter - #define BASES public observer - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - BOOST_CONTRACT_OVERRIDES(up_to_date_with_subject, update) - -public: - /* Creation */ - - // Create view associated with given counter. - explicit view_of_counter(counter& a_counter) : counter_(a_counter) { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::constructor(this); - - counter_.attach(this); - assert(counter_.value() == test_counter); - } - - // Destroy view. - virtual ~view_of_counter() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - /* Commands */ - - virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0) - const /* override */ { - bool result; - boost::contract::check c = boost::contract::public_function< - override_up_to_date_with_subject - >(v, result, &view_of_counter::up_to_date_with_subject, this); - - return result = true; // For simplicity, assume always up-to-date. - } - - virtual void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_update>(v, &view_of_counter::update, this); - - assert(counter_.value() == test_counter); - } - -private: - counter& counter_; -}; - -int main() { - counter cnt(test_counter = 1); - view_of_counter view(cnt); - - decrement_button dec(cnt); - assert(dec.enabled()); - - test_counter--; - dec.on_bn_clicked(); - assert(!dec.enabled()); - - return 0; -} -//] - diff --git a/example/mitchell02/courier.cpp b/example/mitchell02/courier.cpp deleted file mode 100644 index d1024134..00000000 --- a/example/mitchell02/courier.cpp +++ /dev/null @@ -1,204 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_courier -#include -#include -#include - -struct package { - double weight_kg; - std::string location; - double accepted_hour; - double delivered_hour; - - explicit package( - double _weight_kg, - std::string const& _location = "", - double _accepted_hour = 0.0, - double _delivered_hour = 0.0 - ) : - weight_kg(_weight_kg), - location(_location), - accepted_hour(_accepted_hour), - delivered_hour(_delivered_hour) - {} -}; - -// Courier for package delivery. -class courier - #define BASES private boost::contract::constructor_precondition - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { - // Positive min. insurance. - BOOST_CONTRACT_ASSERT(min_insurance_usd >= 0.0); - } - - void invariant() const { - // Above min. insurance. - BOOST_CONTRACT_ASSERT(insurance_cover_usd() >= min_insurance_usd); - } - -public: - static double min_insurance_usd; - - /* Creation */ - - // Create courier with specified insurance value. - explicit courier(double _insurance_cover_usd = min_insurance_usd) : - boost::contract::constructor_precondition([&] { - // Positive insurance. - BOOST_CONTRACT_ASSERT(_insurance_cover_usd >= 0.0); - }), - insurance_cover_usd_(_insurance_cover_usd) - { - // Check invariants. - boost::contract::check c = boost::contract::constructor(this); - } - - // Destroy courier. - virtual ~courier() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Queries */ - - // Return insurance cover. - double insurance_cover_usd() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return insurance_cover_usd_; - } - - /* Commands */ - - // Deliver package to destination. - virtual void deliver( - package& package_delivery, - std::string const& destination, - boost::contract::virtual_* v = 0 - ) { - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - // Within max weight of this delivery. - BOOST_CONTRACT_ASSERT(package_delivery.weight_kg < 5.0); - }) - .postcondition([&] { - // Within max delivery type. - BOOST_CONTRACT_ASSERT(double(package_delivery.delivered_hour - - package_delivery.accepted_hour) <= 3.0); - // Delivered at destination. - BOOST_CONTRACT_ASSERT(package_delivery.location == destination); - }) - ; - - package_delivery.location = destination; - // Delivery takes 2.5 hours. - package_delivery.delivered_hour = package_delivery.accepted_hour + 2.5; - } - -private: - double insurance_cover_usd_; -}; - -double courier::min_insurance_usd = 10.0e+6; - -// Different courier for package delivery. -class different_courier - #define BASES private boost::contract::constructor_precondition< \ - different_courier>, public courier - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Subcontracting. - #undef BASES - BOOST_CONTRACT_OVERRIDE(deliver) - - static void static_invariant() { - BOOST_CONTRACT_ASSERT( // Better insurance amount. - different_insurance_usd >= courier::min_insurance_usd); - } - - void invariant() const { - // Above different insurance value. - BOOST_CONTRACT_ASSERT(insurance_cover_usd() >= different_insurance_usd); - } - -public: - static double different_insurance_usd; - - /* Creation */ - - // Create courier with specified insurance value. - explicit different_courier( - double insurance_cover_usd = different_insurance_usd) : - boost::contract::constructor_precondition([&] { - // Positive insurance value. - BOOST_CONTRACT_ASSERT(insurance_cover_usd > 0.0); - }), - courier(insurance_cover_usd) - { - // Check invariants. - boost::contract::check c = boost::contract::constructor(this); - } - - // Destroy courier. - virtual ~different_courier() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Commands */ - - virtual void deliver( - package& package_delivery, - std::string const& destination, - boost::contract::virtual_* v = 0 - ) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_deliver - >(v, &different_courier::deliver, this, package_delivery, destination) - .precondition([&] { - // Package can weight more (weaker precondition). - BOOST_CONTRACT_ASSERT(package_delivery.weight_kg <= 8.0); - }) - .postcondition([&] { - // Faster delivery (stronger postcondition). - BOOST_CONTRACT_ASSERT(double(package_delivery.delivered_hour - - package_delivery.accepted_hour) <= 2.0); - // Inherited "delivery at destination" postcondition. - }) - ; - - package_delivery.location = destination; - // Delivery takes 0.5 hours. - package_delivery.delivered_hour = package_delivery.accepted_hour + 0.5; - } -}; - -double different_courier::different_insurance_usd = 20.0e+6; - -int main() { - package cups(3.6, "store"); - courier c; - c.deliver(cups, "home"); - assert(cups.location == "home"); - - package desk(7.2, "store"); - different_courier dc; - dc.deliver(desk, "office"); - assert(desk.location == "office"); - - return 0; -} -//] - diff --git a/example/mitchell02/customer_manager.cpp b/example/mitchell02/customer_manager.cpp deleted file mode 100644 index 2baf409d..00000000 --- a/example/mitchell02/customer_manager.cpp +++ /dev/null @@ -1,137 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_customer_manager -#include -#include -#include -#include -#include - -// Basic customer information. -struct customer_info { - friend class customer_manager; - - typedef std::string identifier; - - identifier id; - - explicit customer_info(identifier const& _id) : - id(_id), name_(), address_(), birthday_() {} - -private: - std::string name_; - std::string address_; - std::string birthday_; -}; - -// Manage customers. -class customer_manager { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Non-negative count. - } - -public: - /* Creation */ - - customer_manager() { - // Check invariants. - boost::contract::check c = boost::contract::constructor(this); - } - - virtual ~customer_manager() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Basic Queries */ - - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return customers_.size(); - } - - bool id_active(customer_info::identifier const& id) const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return customers_.find(id) != customers_.cend(); - } - - /* Derived Queries */ - - std::string const& name_for(customer_info::identifier const& id) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(id_active(id)); // Active. - }) - ; - - // Find != end because of preconditions (no defensive programming). - return customers_.find(id)->second.name_; - } - - /* Commands */ - - void add(customer_info const& info) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - // Not already active. - BOOST_CONTRACT_ASSERT(!id_active(info.id)); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc. - BOOST_CONTRACT_ASSERT(id_active(info.id)); // Activated. - }) - ; - - customers_.insert(std::make_pair(info.id, customer(info))); - } - - void set_name(customer_info::identifier const& id, - std::string const& name) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(id_active(id)); // Already active. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(name_for(id) == name); // Name set. - }) - ; - - // Find != end because of precondition (no defensive programming). - customers_.find(id)->second.name_ = name; - } - -private: - class agent {}; // Customer agent. - - struct customer : customer_info { - agent managing_agent; - std::string last_contact; - - explicit customer(customer_info const& info) : customer_info(info), - managing_agent(), last_contact() {} - }; - - std::map customers_; -}; - -int main() { - customer_manager m; - customer_info const js("john_smith_123"); - m.add(js); - m.set_name(js.id, "John Smith"); - assert(m.name_for(js.id) == "John Smith"); - assert(m.count() == 1); - assert(m.id_active(js.id)); - return 0; -} -//] - diff --git a/example/mitchell02/dictionary.cpp b/example/mitchell02/dictionary.cpp deleted file mode 100644 index 709254a2..00000000 --- a/example/mitchell02/dictionary.cpp +++ /dev/null @@ -1,128 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_dictionary -#include -#include -#include -#include - -template -class dictionary { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Non-negative count. - } - -public: - /* Creation */ - - // Create empty dictionary. - dictionary() { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == 0); // Empty. - }) - ; - } - - // Destroy dictionary. - virtual ~dictionary() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Basic Queries */ - - // Number of key entries. - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return items_.size(); - } - - // Has entry for key? - bool has(K const& key) const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Empty has no key. - if(count() == 0) BOOST_CONTRACT_ASSERT(!result); - }) - ; - - return result = (items_.find(key) != items_.end()); - } - - // Value for a given key. - T const& value_for(K const& key) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(has(key)); // Has key. - }) - ; - - // Find != end because of precondition (no defensive programming). - return items_.find(key)->second; - } - - /* Commands */ - - // Add value of a given key. - void put(K const& key, T const& value) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!has(key)); // Has not key already. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc. - BOOST_CONTRACT_ASSERT(has(key)); // Has key. - // Value set for key. - BOOST_CONTRACT_ASSERT(value_for(key) == value); - }) - ; - - items_.insert(std::make_pair(key, value)); - } - - // Remove value for given key. - void remove(K const& key) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(has(key)); // Has key. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count - 1); // Count dec. - BOOST_CONTRACT_ASSERT(!has(key)); // Has not key. - }) - ; - - items_.erase(key); - } - -private: - std::map items_; -}; - -int main() { - std::string const js = "John Smith"; - - dictionary ages; - assert(!ages.has(js)); - - ages.put(js, 23); - assert(ages.value_for(js) == 23); - - ages.remove(js); - assert(ages.count() == 0); - - return 0; -} -//] - diff --git a/example/mitchell02/name_list.cpp b/example/mitchell02/name_list.cpp deleted file mode 100644 index 8aa09b91..00000000 --- a/example/mitchell02/name_list.cpp +++ /dev/null @@ -1,143 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_name_list -#include -#include -#include -#include -#include - -// List of names. -class name_list { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Non-negative count. - } - -public: - /* Creation */ - - // Create an empty list. - name_list() { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == 0); // Empty list. - }) - ; - } - - // Destroy list. - virtual ~name_list() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Basic Queries */ - - // Number of names in list. - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return names_.size(); - } - - // Is name in list? - bool has(std::string const& name) const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // If empty, has not. - if(count() == 0) BOOST_CONTRACT_ASSERT(!result); - }) - ; - - return result = names_.cend() != std::find(names_.cbegin(), - names_.cend(), name); - } - - /* Commands */ - - // Add name to list, if name not already in list. - virtual void put(std::string const& name, - boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_has_name = - BOOST_CONTRACT_OLDOF(v, has(name)); - boost::contract::old_ptr old_count = - BOOST_CONTRACT_OLDOF(v, count()); - boost::contract::check c = boost::contract::public_function(v, this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!has(name)); // Not already in list. - }) - .postcondition([&] { - if(!*old_has_name) { // If-guard allows to relax subcontracts. - BOOST_CONTRACT_ASSERT(has(name)); // Name in list. - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Inc. - } - }) - ; - - names_.push_back(name); - } - -private: - std::vector names_; -}; - -class relaxed_name_list - #define BASES public name_list - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Subcontracting. - #undef BASES - BOOST_CONTRACT_OVERRIDE(put); - -public: - /* Commands */ - - // Add name to list, or do nothing if name already in list (relaxed). - void put(std::string const& name, - boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr old_has_name = - BOOST_CONTRACT_OLDOF(v, has(name)); - boost::contract::old_ptr old_count = - BOOST_CONTRACT_OLDOF(v, count()); - boost::contract::check c = boost::contract::public_function< - override_put>(v, &relaxed_name_list::put, this, name) - .precondition([&] { // Relax inherited preconditions. - BOOST_CONTRACT_ASSERT(has(name)); // Already in list. - }) - .postcondition([&] { // Inherited post. not checked given if-guard. - if(*old_has_name) { - // Count unchanged if name already in list. - BOOST_CONTRACT_ASSERT(count() == *old_count); - } - }) - ; - - if(!has(name)) name_list::put(name); // Else, do nothing. - } -}; - -int main() { - std::string const js = "John Smith"; - - relaxed_name_list rl; - rl.put(js); - assert(rl.has(js)); - rl.put(js); // OK, relaxed contracts allow calling this again (do nothing). - - name_list nl; - nl.put(js); - assert(nl.has(js)); - // nl.put(js); // Error, contracts do not allow calling this again. - - return 0; -} -//] - diff --git a/example/mitchell02/observer/observer.hpp b/example/mitchell02/observer/observer.hpp deleted file mode 100644 index bb731575..00000000 --- a/example/mitchell02/observer/observer.hpp +++ /dev/null @@ -1,59 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_observer -#ifndef OBSERVER_HPP_ -#define OBSERVER_HPP_ - -#include -#include - -// Observer. -class observer { - friend class subject; -public: - // No inv and no bases so contracts optional if no pre, post, and override. - - /* Creation */ - - observer() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::constructor(this); - } - - virtual ~observer() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - /* Commands */ - - // If up-to-date with related subject. - virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0) - const = 0; - - // Update this observer. - virtual void update(boost::contract::virtual_* v = 0) = 0; -}; - -bool observer::up_to_date_with_subject(boost::contract::virtual_* v) const { - boost::contract::check c = boost::contract::public_function(v, this); - assert(false); - return false; -} - -void observer::update(boost::contract::virtual_* v) { - boost::contract::check c = boost::contract::public_function(v, this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(up_to_date_with_subject()); // Up-to-date. - }) - ; - assert(false); -} - -#endif // #include guard -//] - diff --git a/example/mitchell02/observer/subject.hpp b/example/mitchell02/observer/subject.hpp deleted file mode 100644 index fad0ba79..00000000 --- a/example/mitchell02/observer/subject.hpp +++ /dev/null @@ -1,165 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_subject -#ifndef SUBJECT_HPP_ -#define SUBJECT_HPP_ - -#include "observer.hpp" -#include -#include -#include -#include - -// Subject for observer design pattern. -class subject { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT_AUDIT(all_observers_valid(observers())); // Valid. - } - -public: - /* Creation */ - - // Construct subject with no observer. - subject() { - // Check invariant. - boost::contract::check c = boost::contract::constructor(this); - } - - // Destroy subject. - virtual ~subject() { - // Check invariant. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Queries */ - - // If given object is attached. - bool attached(observer const* ob) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(ob); // Not null. - }) - ; - - return std::find(observers_.cbegin(), observers_.cend(), ob) != - observers_.cend(); - } - - /* Commands */ - - // Attach given object as an observer. - void attach(observer* ob) { - boost::contract::old_ptr > old_observers; - #ifdef BOOST_CONTRACT_AUDITS - old_observers = BOOST_CONTRACT_OLDOF(observers()); - #endif - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(ob); // Not null. - BOOST_CONTRACT_ASSERT(!attached(ob)); // Not already attached. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(attached(ob)); // Attached. - // Others not changed (frame rule). - BOOST_CONTRACT_ASSERT_AUDIT(other_observers_unchanged( - *old_observers, observers(), ob)); - }) - ; - - observers_.push_back(ob); - } - -protected: - // Contracts could have been omitted for protected/private with no pre/post. - - /* Queries */ - - // All observers attached to this subject. - std::vector observers() const { - std::vector obs; - for(std::vector::const_iterator i = observers_.cbegin(); - i != observers_.cend(); ++i) { - obs.push_back(*i); - } - return obs; - } - - /* Commands */ - - // Update all attached observers. - void notify() { - // Protected members use `function` (no inv and no subcontracting). - boost::contract::check c = boost::contract::function() - .postcondition([&] { - // All updated. - BOOST_CONTRACT_ASSERT_AUDIT(all_observers_updated(observers())); - }) - ; - - for(std::vector::iterator i = observers_.begin(); - i != observers_.end(); ++i) { - // Class invariants ensure no null pointers in observers but class - // invariants not checked for non-public functions so assert here. - assert(*i); // Pointer not null (defensive programming). - (*i)->update(); - } - } - -private: - /* Contract Helpers */ - - static bool all_observers_valid(std::vector const& obs) { - for(std::vector::const_iterator i = obs.cbegin(); - i != obs.cend(); ++i) { - if(!*i) return false; - } - return true; - } - - static bool other_observers_unchanged( - std::vector const& old_obs, - std::vector const& new_obs, - observer const* ob - ) { - // Private members use `function` (no inv and no subcontracting). - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(ob); // Not null. - }) - ; - - std::vector remaining = new_obs; - std::remove(remaining.begin(), remaining.end(), ob); - - std::vector::const_iterator remaining_it = - remaining.begin(); - std::vector::const_iterator old_it = old_obs.begin(); - while(remaining.cend() != remaining_it && old_obs.cend() != old_it) { - if(*remaining_it != *old_it) return false; - ++remaining_it; - ++old_it; - } - return true; - } - - static bool all_observers_updated(std::vector const& obs) { - for(std::vector::const_iterator i = obs.cbegin(); - i != obs.cend(); ++i) { - if(!*i) return false; - if(!(*i)->up_to_date_with_subject()) return false; - } - return true; - } - - std::vector observers_; -}; - -#endif // #include guard -//] - diff --git a/example/mitchell02/observer_main.cpp b/example/mitchell02/observer_main.cpp deleted file mode 100644 index a49c88ff..00000000 --- a/example/mitchell02/observer_main.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_observer_main -#include "observer/observer.hpp" -#include "observer/subject.hpp" -#include -#include - -int test_state; // For testing only. - -// Implement an actual subject. -class concrete_subject - #define BASES public subject - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Subcontracting. - #undef BASES - -public: - typedef int state; // Some state being observed. - - concrete_subject() : state_() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::constructor(this); - } - - virtual ~concrete_subject() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - void set_state(state const& new_state) { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::public_function(this); - - state_ = new_state; - assert(state_ == test_state); - notify(); // Notify all observers. - } - - state get_state() const { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::public_function(this); - return state_; - } - -private: - state state_; -}; - -// Implement an actual observer. -class concrete_observer - #define BASES public observer - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Subcontracting. - #undef BASES - BOOST_CONTRACT_OVERRIDES(up_to_date_with_subject, update) - -public: - // Create concrete observer. - explicit concrete_observer(concrete_subject const& subj) : - subject_(subj), observed_state_() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::constructor(this); - } - - virtual ~concrete_observer() { - // Could have omitted contracts here (nothing to check). - boost::contract::check c = boost::contract::destructor(this); - } - - // Implement base virtual functions. - - bool up_to_date_with_subject(boost::contract::virtual_* v = 0) - const /* override */ { - bool result; - boost::contract::check c = boost::contract::public_function< - override_up_to_date_with_subject - >(v, result, &concrete_observer::up_to_date_with_subject, this); - - return result = true; // For simplicity, assume always up-to-date. - } - - void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::check c = boost::contract::public_function< - override_update>(v, &concrete_observer::update, this); - - observed_state_ = subject_.get_state(); - assert(observed_state_ == test_state); - } - -private: - concrete_subject const& subject_; - concrete_subject::state observed_state_; -}; - -int main() { - concrete_subject subj; - concrete_observer ob(subj); - subj.attach(&ob); - - subj.set_state(test_state = 123); - subj.set_state(test_state = 456); - - return 0; -} -//] - diff --git a/example/mitchell02/simple_queue.cpp b/example/mitchell02/simple_queue.cpp deleted file mode 100644 index 2f15a113..00000000 --- a/example/mitchell02/simple_queue.cpp +++ /dev/null @@ -1,219 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_simple_queue -#include -#include -#include -#include - -template -class simple_queue - #define BASES private boost::contract::constructor_precondition< \ - simple_queue > - : BASES -{ - friend class boost::contract::access; - - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Non-negative count. - } - -public: - /* Creation */ - - // Create empty queue. - explicit simple_queue(int a_capacity) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(a_capacity > 0); // Positive capacity. - }) - { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - // Capacity set. - BOOST_CONTRACT_ASSERT(capacity() == a_capacity); - BOOST_CONTRACT_ASSERT(is_empty()); // Empty. - }) - ; - - items_.reserve(a_capacity); - } - - // Destroy queue. - virtual ~simple_queue() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Basic Queries */ - - // Items in queue (in their order). - // (Somewhat exposes implementation but allows to check more contracts.) - std::vector const& items() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return items_; - } - - // Max number of items queue can hold. - int capacity() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return items_.capacity(); - } - - /* Derived Queries */ - - // Number of items. - int count() const { - int result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Return items count. - BOOST_CONTRACT_ASSERT(result == int(items().size())); - }) - ; - - return result = items_.size(); - } - - // Item at head. - T const& head() const { - boost::optional result; - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty. - }) - .postcondition([&] { - // Return item on top. - BOOST_CONTRACT_ASSERT(*result == items().at(0)); - }) - ; - - return *(result = items_.at(0)); - } - - // If queue contains no item. - bool is_empty() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Consistent with count. - BOOST_CONTRACT_ASSERT(result == (count() == 0)); - }) - ; - - return result = (items_.size() == 0); - } - - // If queue has no room for another item. - bool is_full() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT( // Consistent with size and capacity. - result == (capacity() == int(items().size()))); - }) - ; - - return result = (items_.size() == items_.capacity()); - } - - /* Commands */ - - // Remove head itme and shift all other items. - void remove() { - // Expensive all_equal postcond. and old_items copy might be skipped. - boost::contract::old_ptr > old_items; - #ifdef BOOST_CONTRACT_AUDIITS - = BOOST_CONTRACT_OLDOF(items()) - #endif // Else, leave old pointer null... - ; - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count - 1); // Count dec. - // ...following skipped #ifndef AUDITS. - if(old_items) all_equal(items(), *old_items, /* shifted = */ 1); - }) - ; - - items_.erase(items_.begin()); - } - - // Add item to tail. - void put(T const& item) { - // Expensive all_equal postcond. and old_items copy might be skipped. - boost::contract::old_ptr > old_items; - #ifdef BOOST_CONTRACT_AUDITS - = BOOST_CONTRACT_OLDOF(items()) - #endif // Else, leave old pointer null... - ; - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count() < capacity()); // Room for add. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc. - // Second to last item. - BOOST_CONTRACT_ASSERT(items().at(count() - 1) == item); - // ...following skipped #ifndef AUDITS. - if(old_items) all_equal(items(), *old_items); - }) - ; - - items_.push_back(item); - } - -private: - // Contract helper. - static bool all_equal(std::vector const& left, - std::vector const& right, unsigned offset = 0) { - boost::contract::check c = boost::contract::function() - .precondition([&] { - // Correct offset. - BOOST_CONTRACT_ASSERT(right.size() == left.size() + offset); - }) - ; - - for(unsigned i = offset; i < right.size(); ++i) { - if(left.at(i - offset) != right.at(i)) return false; - } - return true; - } - - std::vector items_; -}; - -int main() { - simple_queue q(10); - q.put(123); - q.put(456); - - assert(q.capacity() == 10); - assert(q.head() == 123); - - assert(!q.is_empty()); - assert(!q.is_full()); - - std::vector const& items = q.items(); - assert(items.at(0) == 123); - assert(items.at(1) == 456); - - q.remove(); - assert(q.count() == 1); - - return 0; -} -//] - diff --git a/example/mitchell02/stack.cpp b/example/mitchell02/stack.cpp deleted file mode 100644 index 13e3d081..00000000 --- a/example/mitchell02/stack.cpp +++ /dev/null @@ -1,138 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[mitchell02_stack -#include -#include -#include -#include - -template -class stack { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(count() >= 0); // Non-negative count. - } - -public: - /* Creation */ - - // Create empty stack. - stack() { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == 0); // Empty. - }) - ; - } - - // Destroy stack. - virtual ~stack() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - /* Basic Queries */ - - // Number of items. - int count() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return items_.size(); - } - - // Item at index in [1, count()] (as in Eiffel). - T const& item_at(int index) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index > 0); // Positive index. - BOOST_CONTRACT_ASSERT(index <= count()); // Index within count. - }) - ; - - return items_[index - 1]; - } - - /* Derived Queries */ - - // If no items. - bool is_empty() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - // Consistent with count. - BOOST_CONTRACT_ASSERT(result == (count() == 0)); - }) - ; - - return result = (count() == 0); - } - - // Top item. - T const& item() const { - boost::optional result; // Avoid extra construction of T. - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count() > 0); // Not empty. - }) - .postcondition([&] { - // Item on top. - BOOST_CONTRACT_ASSERT(*result == item_at(count())); - }) - ; - - return *(result = item_at(count())); - } - - /* Commands */ - - // Push item to the top. - void put(T const& new_item) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc. - BOOST_CONTRACT_ASSERT(item() == new_item); // Item set. - }) - ; - - items_.push_back(new_item); - } - - // Pop top item. - void remove() { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count() > 0); // Not empty. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(count() == *old_count - 1); // Count dec. - }) - ; - - items_.pop_back(); - } - -private: - std::vector items_; -}; - -int main() { - stack s; - assert(s.count() == 0); - - s.put(123); - assert(s.item() == 123); - - s.remove(); - assert(s.is_empty()); - - return 0; -} -//] - diff --git a/example/n1962/circle.cpp b/example/n1962/circle.cpp deleted file mode 100644 index de5d6b59..00000000 --- a/example/n1962/circle.cpp +++ /dev/null @@ -1,78 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_circle -#include -#include - -class shape { -public: - virtual ~shape() {} - - virtual unsigned compute_area(boost::contract::virtual_* v = 0) const = 0; -}; - -unsigned shape::compute_area(boost::contract::virtual_* v) const { - unsigned result; - boost::contract::check c = boost::contract::public_function(v, result, this) - .postcondition([&] (int const& result) { - BOOST_CONTRACT_ASSERT(result > 0); - }) - ; - assert(false); - return result; -} - -class circle - #define BASES public shape - : BASES -{ - friend class boost::contract::access; - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - BOOST_CONTRACT_OVERRIDE(compute_area); - -public: - static int const pi = 3; // Truncated to int from 3.14... - - explicit circle(unsigned a_radius) : radius_(a_radius) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(radius() == a_radius); - }) - ; - } - - virtual unsigned compute_area(boost::contract::virtual_* v = 0) const - /* override */ { - unsigned result; - boost::contract::check c = boost::contract::public_function< - override_compute_area>(v, result, &circle::compute_area, this) - .postcondition([&] (unsigned const& result) { - BOOST_CONTRACT_ASSERT(result == pi * radius() * radius()); - }) - ; - - return result = pi * radius() * radius(); - } - - unsigned radius() const { - boost::contract::check c = boost::contract::public_function(this); - return radius_; - } - -private: - unsigned radius_; -}; - -int main() { - circle c(2); - assert(c.radius() == 2); - assert(c.compute_area() == 12); - return 0; -} -//] - diff --git a/example/n1962/equal.cpp b/example/n1962/equal.cpp deleted file mode 100644 index 388aad8b..00000000 --- a/example/n1962/equal.cpp +++ /dev/null @@ -1,51 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_equal -#include -#include - -// Forward declaration because == and != contracts use one another's function. -template -bool operator==(T const& left, T const& right); - -template -bool operator!=(T const& left, T const& right) { - bool result; - boost::contract::check c = boost::contract::function() - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == !(left == right)); - }) - ; - - return result = (left.value != right.value); -} - -template -bool operator==(T const& left, T const& right) { - bool result; - boost::contract::check c = boost::contract::function() - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == !(left != right)); - }) - ; - - return result = (left.value == right.value); -} - -struct number { int value; }; - -int main() { - number n; - n.value = 123; - - assert((n == n) == true); // Explicitly call operator==. - assert((n != n) == false); // Explicitly call operator!=. - - return 0; -} -//] - diff --git a/example/n1962/factorial.cpp b/example/n1962/factorial.cpp deleted file mode 100644 index 652d428b..00000000 --- a/example/n1962/factorial.cpp +++ /dev/null @@ -1,39 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_factorial -#include -#include - -int factorial(int n) { - int result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative natural number. - BOOST_CONTRACT_ASSERT(n <= 12); // Max function input. - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result >= 1); - if(n < 2) { // Select assertion. - BOOST_CONTRACT_ASSERT(result == 1); - } else { - // Assertions automatically disabled in other assertions. - // Therefore, this postcondition can recursively call the - // function without causing infinite recursion. - BOOST_CONTRACT_ASSERT_AUDIT(n * factorial(n - 1)); - } - }) - ; - - return n < 2 ? (result = 1) : (result = n * factorial(n - 1)); -} - -int main() { - assert(factorial(4) == 24); - return 0; -} -//] - diff --git a/example/n1962/sqrt.cpp b/example/n1962/sqrt.cpp deleted file mode 100644 index 81c75fae..00000000 --- a/example/n1962/sqrt.cpp +++ /dev/null @@ -1,32 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_sqrt -#include -#include -#include - -double mysqrt(double x, double precision = 1e-6) { - double result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(x >= 0.0); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(fabs(result * result - x) <= precision); - }) - ; - - return result = sqrt(x); -} - -int main() { - double const precision = 1e-6; - assert(fabs(mysqrt(4.0, precision) - 2.0) <= precision); - return 0; -} -//] - diff --git a/example/n1962/sqrt.d b/example/n1962/sqrt.d deleted file mode 100644 index 8ddacf74..00000000 --- a/example/n1962/sqrt.d +++ /dev/null @@ -1,32 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_sqrt_d -// Extra spaces, newlines, etc. for visual alignment with this library code. - - - -real mysqrt(real x) - in { - assert(x >= 0.0); - } - out(result) { - assert(std.math.fabs(result * result - x) <= 1e-6); - } -body { - return std.math.sqrt(x); -} - - - - - - - - -// End. -//] - diff --git a/example/n1962/sum.cpp b/example/n1962/sum.cpp deleted file mode 100644 index 5e0e7b95..00000000 --- a/example/n1962/sum.cpp +++ /dev/null @@ -1,30 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_sum -#include -#include - -int sum(int count, int* array) { - int result; - boost::contract::check c = boost::contract::function() - .precondition([&] { - BOOST_CONTRACT_ASSERT(count % 4 == 0); - }) - ; - - result = 0; - for(int i = 0; i < count; ++i) result += array[i]; - return result; -} - -int main() { - int a[4] = {1, 2, 3, 4}; - assert(sum(4, a) == 10); - return 0; -} -//] - diff --git a/example/n1962/vector.cpp b/example/n1962/vector.cpp deleted file mode 100644 index bdc1429d..00000000 --- a/example/n1962/vector.cpp +++ /dev/null @@ -1,725 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_vector -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Could be programmed at call site with C++14 generic lambdas. -struct all_of_equal_to { - typedef bool result_type; - - template - result_type operator()(InputIter first, InputIter last, T const& value) { - return boost::algorithm::all_of_equal(first, last, value); - } - - template - result_type operator()(InputIter first, InputIter last, InputIter where) { - for(InputIter i = first, j = where; i != last; ++i, ++j) { - if(*i != *j) return false; - } - return true; - } -}; - -template -bool valid(Iter first, Iter last); // Cannot implement in C++ (for axiom only). - -template -bool contained(Iter first1, Iter last1, Iter first2, Iter last2); // For axiom. - -// STL vector requires T copyable but not equality comparable. -template > -class vector { - friend class boost::contract::access; - - void invariant() const { - BOOST_CONTRACT_ASSERT(empty() == (size() == 0)); - BOOST_CONTRACT_ASSERT(std::distance(begin(), end()) == int(size())); - BOOST_CONTRACT_ASSERT(std::distance(rbegin(), rend()) == int(size())); - BOOST_CONTRACT_ASSERT(size() <= capacity()); - BOOST_CONTRACT_ASSERT(capacity() <= max_size()); - } - -public: - typedef typename std::vector::allocator_type allocator_type; - typedef typename std::vector::pointer pointer; - typedef typename std::vector::const_pointer const_pointer; - typedef typename std::vector::reference reference; - typedef typename std::vector::const_reference const_reference; - typedef typename std::vector::value_type value_type; - typedef typename std::vector::iterator iterator; - typedef typename std::vector::const_iterator const_iterator; - typedef typename std::vector::size_type size_type; - typedef typename std::vector::difference_type difference_type; - typedef typename std::vector::reverse_iterator - reverse_iterator; - typedef typename std::vector::const_reverse_iterator - const_reverse_iterator; - - vector() : vect_() { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - }) - ; - } - - explicit vector(Allocator const& alloc) : vect_(alloc) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - BOOST_CONTRACT_ASSERT(get_allocator() == alloc); - }) - ; - } - - explicit vector(size_type count) : vect_(count) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), begin(), end(), T()) - ) - ); - }) - ; - } - - vector(size_type count, T const& value) : vect_(count, value) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), begin(), end(), - boost::cref(value)) - ) - ); - }) - ; - } - - vector(size_type count, T const& value, Allocator const& alloc) : - vect_(count, value, alloc) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), begin(), end(), - boost::cref(value)) - ) - ); - BOOST_CONTRACT_ASSERT(get_allocator() == alloc); - }) - ; - } - - template - vector(InputIter first, InputIter last) : vect_(first, last) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(std::distance(first, last) == - int(size())); - }) - ; - } - - template - vector(InputIter first, InputIter last, Allocator const& alloc) : - vect_(first, last, alloc) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(std::distance(first, last) == - int(size())); - BOOST_CONTRACT_ASSERT(get_allocator() == alloc); - }) - ; - } - - /* implicit */ vector(vector const& other) : vect_(other.vect_) { - boost::contract::check c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to >(), - boost::cref(*this), boost::cref(other)) - ) - ); - }) - ; - } - - vector& operator=(vector const& other) { - boost::optional result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to >(), - boost::cref(*this), boost::cref(other)) - ) - ); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to >(), - boost::cref(*result), boost::cref(*this)) - ) - ); - }) - ; - - if(this != &other) vect_ = other.vect_; - return *(result = *this); - } - - virtual ~vector() { - // Check invariants. - boost::contract::check c = boost::contract::destructor(this); - } - - void reserve(size_type count) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(capacity() >= count); - }) - ; - - vect_.reserve(count); - } - - size_type capacity() const { - size_type result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result >= size()); - }) - ; - - return result = vect_.capacity(); - } - - iterator begin() { - iterator result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(empty()) BOOST_CONTRACT_ASSERT(result == end()); - }) - ; - - return result = vect_.begin(); - } - - const_iterator begin() const { - const_iterator result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(empty()) BOOST_CONTRACT_ASSERT(result == end()); - }) - ; - - return result = vect_.begin(); - } - - iterator end() { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.end(); - } - - const_iterator end() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.end(); - } - - reverse_iterator rbegin() { - iterator result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(empty()) BOOST_CONTRACT_ASSERT(result == rend()); - }) - ; - - return result = vect_.rbegin(); - } - - const_reverse_iterator rbegin() const { - const_reverse_iterator result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - if(empty()) BOOST_CONTRACT_ASSERT(result == rend()); - }) - ; - - return result = vect_.rbegin(); - } - - reverse_iterator rend() { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.rend(); - } - - const_reverse_iterator rend() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.rend(); - } - - void resize(size_type count, T const& value = T()) { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == count); - if(count > *old_size) { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), begin() + *old_size, - end(), boost::cref(value)) - ) - ); - } - }) - ; - - vect_.resize(count, value); - } - - size_type size() const { - size_type result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result <= capacity()); - }) - ; - - return result = vect_.size(); - } - - size_type max_size() const { - size_type result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result >= capacity()); - }) - ; - - return result = vect_.max_size(); - } - - bool empty() const { - bool result; - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == (size() == 0)); - }) - ; - - return vect_.empty(); - } - - Allocator get_allocator() const { - // Check invariants. - boost::contract::check c = boost::contract::public_function(this); - return vect_.get_allocator(); - } - - reference at(size_type index) { - // Check invariants, no pre (throw out_of_range for invalid index). - boost::contract::check c = boost::contract::public_function(this); - return vect_.at(index); - } - - const_reference at(size_type index) const { - // Check invariants, no pre (throw out_of_range for invalid index). - boost::contract::check c = boost::contract::public_function(this); - return vect_.at(index); - } - - reference operator[](size_type index) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index < size()); - }) - ; - - return vect_[index]; - } - - const_reference operator[](size_type index) const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(index < size()); - }) - ; - - return vect_[index]; - } - - reference front() { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - - return vect_.front(); - } - - const_reference front() const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - - return vect_.front(); - } - - reference back() { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - - return vect_.back(); - } - - const_reference back() const { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - ; - - return vect_.back(); - } - - void push_back(T const& value) { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(capacity()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to(), boost::cref(back()), - boost::cref(value)) - ) - ); - }) - ; - - vect_.push_back(value); - } - - void pop_back() { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size - 1); - }) - ; - - vect_.pop_back(); - } - - template - void assign(InputIter first, InputIter last) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT_AXIOM( - !contained(begin(), end(), first, last)); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(std::distance(first, last) == - int(size())); - }) - ; - - vect_.assign(first, last); - } - - void assign(size_type count, T const& value) { - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(count <= max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), begin(), end(), - boost::cref(value)) - ) - ); - }) - ; - - vect_.assign(count, value); - } - - iterator insert(iterator where, T const& value) { - iterator result; - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(capacity()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + 1); - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(std::equal_to(), boost::cref(*result), - boost::cref(value)) - ) - ); - if(capacity() > *old_capacity) { - BOOST_CONTRACT_ASSERT_AXIOM(!valid(begin(), end())); - } else { - BOOST_CONTRACT_ASSERT_AXIOM(!valid(where, end())); - } - }) - ; - - return result = vect_.insert(where, value); - } - - void insert(iterator where, size_type count, T const& value) { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(capacity()); - boost::contract::old_ptr old_where = - BOOST_CONTRACT_OLDOF(where); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() + count < max_size()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size + count); - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - if(capacity() == *old_capacity) { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), - boost::prior(*old_where), - boost::prior(*old_where) + count, - boost::cref(value) - ) - ) - ); - BOOST_CONTRACT_ASSERT_AXIOM(!valid(where, end())); - } else BOOST_CONTRACT_ASSERT_AXIOM(!valid(begin(), end())); - }) - ; - - vect_.insert(where, count, value); - } - - template - void insert(iterator where, InputIter first, InputIter last) { - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(capacity()); - boost::contract::old_ptr old_where = - BOOST_CONTRACT_OLDOF(where); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() + std::distance(first, last) < - max_size()); - BOOST_CONTRACT_ASSERT_AXIOM( - !contained(first, last, begin(), end())); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size() + - std::distance(first, last)); - BOOST_CONTRACT_ASSERT(capacity() >= *old_capacity); - if(capacity() == *old_capacity) { - BOOST_CONTRACT_ASSERT( - boost::contract::condition_if >( - boost::bind(all_of_equal_to(), first, last, - *old_where) - ) - ); - BOOST_CONTRACT_ASSERT_AXIOM(!valid(where, end())); - } else BOOST_CONTRACT_ASSERT_AXIOM(!valid(begin(), end())); - }) - ; - - vect_.insert(where, first, last); - } - - iterator erase(iterator where) { - iterator result; - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(!empty()); - BOOST_CONTRACT_ASSERT(where != end()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size - 1); - if(empty()) BOOST_CONTRACT_ASSERT(result == end()); - BOOST_CONTRACT_ASSERT_AXIOM(!valid(where, end())); - }) - ; - - return result = vect_.erase(where); - } - - iterator erase(iterator first, iterator last) { - iterator result; - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(size()); - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(size() >= std::distance(first, last)); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == *old_size - - std::distance(first, last)); - if(empty()) BOOST_CONTRACT_ASSERT(result == end()); - BOOST_CONTRACT_ASSERT_AXIOM(!valid(first, last)); - }) - ; - - return result = vect_.erase(first, last); - } - - void clear() { - boost::contract::check c = boost::contract::public_function(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - }) - ; - - vect_.clear(); - } - - void swap(vector& other) { - boost::contract::old_ptr old_me, old_other; - #ifdef BOOST_CONTRACT_AUDITS - old_me = BOOST_CONTRACT_OLDOF(*this); - old_other = BOOST_CONTRACT_OLDOF(other); - #endif - boost::contract::check c = boost::contract::public_function(this) - .precondition([&] { - BOOST_CONTRACT_ASSERT(get_allocator() == other.get_allocator()); - }) - .postcondition([&] { - BOOST_CONTRACT_ASSERT_AUDIT( - boost::contract::condition_if > >( - boost::bind(std::equal_to >(), - boost::cref(*this), boost::cref(*old_other)) - ) - ); - BOOST_CONTRACT_ASSERT_AUDIT( - boost::contract::condition_if > >( - boost::bind(std::equal_to >(), - boost::cref(other), boost::cref(*old_me)) - ) - ); - }) - ; - - vect_.swap(other); - } - - friend bool operator==(vector const& left, vector const& right) { - // Check class invariants for left and right objects. - boost::contract::check left_inv = - boost::contract::public_function(&left); - boost::contract::check right_inv = - boost::contract::public_function(&right); - return left.vect_ == right.vect_; - } - -private: - std::vector vect_; -}; - -int main() { - // char type has operator==. - - vector v(3); - assert(v.size() == 3); - assert(boost::algorithm::all_of_equal(v, '\0')); - - vector const& cv = v; - assert(cv == v); - - vector w(v); - assert(w == v); - - typename vector::iterator i = v.begin(); - assert(*i == '\0'); - - typename vector::const_iterator ci = cv.begin(); - assert(*ci == '\0'); - - v.insert(i, 2, 'a'); - assert(v[0] == 'a'); - assert(v[1] == 'a'); - - v.push_back('b'); - assert(v.back() == 'b'); - - struct x {}; // x type doest not have operator==. - - vector y(3); - assert(y.size() == 3); - - vector const& cy = y; - vector z(y); - - typename vector::iterator j = y.begin(); - assert(j != y.end()); - typename vector::const_iterator cj = cy.begin(); - assert(cj != cy.end()); - - y.insert(j, 2, x()); - y.push_back(x()); - - return 0; -} -//] - diff --git a/example/n1962/vector_n1962.hpp b/example/n1962/vector_n1962.hpp deleted file mode 100644 index 596e1b79..00000000 --- a/example/n1962/vector_n1962.hpp +++ /dev/null @@ -1,725 +0,0 @@ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -//[n1962_vector_n1962 -// Extra spaces, newlines, etc. for visual alignment with this library code. - -#include -#include -#include -#include -#include -#include - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -template< class T, class Allocator = std::allocator > -class vector { - - - invariant { - empty() == (size() == 0); - std::distance(begin(), end()) == int(size()); - std::distance(rbegin(), rend()) == int(size()); - size() <= capacity(); - capacity() <= max_size(); - } - -public: - typedef typename std::vector::allocator_type allocator_type; - typedef typename std::vector::pointer pointer; - typedef typename std::vector::const_pointer const_pointer; - typedef typename std::vector::reference reference; - typedef typename std::vector::const_reference const_reference; - typedef typename std::vector::value_type value_type; - typedef typename std::vector::iterator iterator; - typedef typename std::vector::const_iterator const_iterator; - typedef typename std::vector::size_type size_type; - typedef typename std::vector::difference_type difference_type; - typedef typename std::vector::reverse_iterator - reverse_iterator; - typedef typename std::vector::const_reverse_iterator - const_reverse_iterator; - - vector() - postcondition { - empty(); - } - : vect_() - {} - - - explicit vector(Allocator const& alloc) - postcondition { - empty(); - get_allocator() == alloc; - } - : vect_(alloc) - {} - - - explicit vector(size_type count) - postcondition { - size() == count; - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(begin(), end(), T()); - } - } - : vect_(count) - {} - - - - - vector(size_type count, T const& value) - postcondition { - size() == count; - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(begin(), end(), value); - } - } - : vect_(count, value) - {} - - - - - - vector(size_type count, T const& value, Allocator const& alloc) - postcondition { - size() == count; - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(begin(), end(), value); - } - get_allocator() == alloc; - } - : vect_(count, value, alloc) - {} - - - - - - - template - vector(InputIter first, InputIter last) - postcondition { - std::distance(first, last) == int(size()); - } - : vect_(first, last) - {} - - - - template - vector(InputIter first, InputIter last, Allocator const& alloc) - postcondition { - std::distance(first, last) == int(size()); - get_allocator() == alloc; - } - : vect_(first, last, alloc) - {} - - - - - /* implicit */ vector(vector const& other) - postcondition { - if constexpr(boost::has_equal_to::value) { - *this == other; - } - } - : vect_(other.vect_) - {} - - - - - - vector& operator=(vector const& other) - postcondition(result) { - if constexpr(boost::has_equal_to::value) { - *this == other; - result == *this; - } - } - { - if(this != &other) vect_ = other.vect_; - return *this; - } - - - - - - - - - - - - - virtual ~vector() {} - - - - - void reserve(size_type count) - precondition { - count < max_size(); - } - postcondition { - capacity() >= count; - } - { - vect_.reserve(count); - } - - - - size_type capacity() const - postcondition(result) { - result >= size(); - } - { - return vect_.capacity(); - } - - - - - iterator begin() - postcondition { - if(empty()) result == end(); - } - { - return vect_.begin(); - } - - - - - const_iterator begin() const - postcondition(result) { - if(empty()) result == end(); - } - { - return vect_.begin(); - } - - - - - iterator end() { - return vect_.end(); - } - - - - const_iterator end() const { - return vect_.end(); - } - - - - reverse_iterator rbegin() - postcondition(result) { - if(empty()) result == rend(); - } - { - return vect_.rbegin(); - } - - - - - const_reverse_iterator rbegin() const - postcondition(result) { - if(empty()) result == rend(); - } - { - return vect_.rbegin(); - } - - - - - reverse_iterator rend() { - return vect_.rend(); - } - - - - const_reverse_iterator rend() const { - return vect_.rend(); - } - - - - void resize(size_type count, T const& value = T()) - postcondition { - size() == count; - if constexpr(boost::has_equal_to::value) { - if(count > oldof(size())) { - boost::algorithm::all_of_equal(begin() + oldof(size()), - end(), value); - } - } - } - { - vect_.resize(count, value); - } - - - - - - - - size_type size() const - postcondition(result) { - result <= capacity(); - } - { - return vect_.size(); - } - - - - - size_type max_size() const - postcondition(result) { - result >= capacity(); - } - { - return vect_.max_size(); - } - - - - - bool empty() const - postcondition(result) { - result == (size() == 0); - } - { - return vect_.empty(); - } - - - - - Alloctor get_allocator() const { - return vect_.get_allocator(); - } - - - - reference at(size_type index) { - // No precondition (throw out_of_range for invalid index). - return vect_.at(index); - } - - - const_reference at(size_type index) const { - // No precondition (throw out_of_range for invalid index). - return vect_.at(index); - } - - - reference operator[](size_type index) - precondition { - index < size(); - } - { - return vect_[index]; - } - - - - const_reference operator[](size_type index) const - precondition { - index < size(); - } - { - return vect_[index]; - } - - - - reference front() - precondition { - !empty(); - } - { - return vect_.front(); - } - - - - const_reference front() const - precondition { - !empty(); - } - { - return vect_.front(); - } - - - - reference back() - precondition { - !empty(); - } - { - return vect_.back(); - } - - - - const_reference back() const - precondition { - !empty(); - } - { - return vect_.back(); - } - - - - void push_back(T const& value) - precondition { - size() < max_size(); - } - postcondition { - size() == oldof(size()) + 1; - capacity() >= oldof(capacity()) - if constexpr(boost::has_equal_to::value) { - back() == value; - } - } - { - vect_.push_back(value); - } - - - - - - - - - - - void pop_back() - precondition { - !empty(); - } - postcondition { - size() == oldof(size()) - 1; - } - { - vect_.pop_back(); - } - - - - - - template - void assign(InputIter first, InputIter last) - // Precondition: [begin(), end()) does not contain [first, last). - postcondition { - std::distance(first, last) == int(size()); - } - { - vect_.assign(first, last); - } - - - - - - - - void assign(size_type count, T const& vallue) - precondition { - count <= max_size(); - } - postcondition { - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(begin(), end(), value); - } - } - { - vect_.assign(count, value); - } - - - - - - - iterator insert(iterator where, T const& value) - precondition { - size() < max_size(); - } - postcondition(result) { - size() == oldof(size()) + 1; - capacity() >= oldof(capacity()); - if constexpr(boost::has_equal_to::value) { - *result == value; - } - // if(capacity() > oldof(capacity())) - // [begin(), end()) is invalid - // else - // [where, end()) is invalid - } - { - return vect_.insert(where, value); - } - - - - - - - - - - - - - void insert(iterator where, size_type count, T const& value) - precondition { - size() + count < max_size(); - } - postcondition { - size() == oldof(size()) + count; - capacity() >= oldof(capacity()); - if(capacity() == oldof(capacity())) { - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(boost::prior(oldof(where)), - boost::prior(oldof(where)) + count, value); - } - // [where, end()) is invalid - } - // else [begin(), end()) is invalid - } - { - vect_.insert(where, count, value); - } - - - - - - - - - - - - - - template - void insert(iterator where, Iterator first, Iterator last) - precondition { - size() + std::distance(first, last) < max_size(); - // [first, last) is not contained in [begin(), end()) - } - postcondition { - size() == oldof(size()) + std::distance(first, last); - capacity() >= oldof(capacity()); - if(capacity() == oldof(capacity())) { - if constexpr(boost::has_equal_to::value) { - boost::algorithm::all_of_equal(first, last, oldof(where)); - } - // [where, end()) is invalid - } - // else [begin(), end()) is invalid - } - { - vect_.insert(where, first, last); - } - - - - - - - - - - - - - - - iterator erase(iterator where) - precondition { - !empty(); - where != end(); - } - postcondition(result) { - size() == oldod size() - 1; - if(empty()) result == end(); - // [where, end()) is invalid - } - { - return vect_.erase(where); - } - - - - - - - iterator erase(iterator first, iterator last) - precondition { - size() >= std::distance(first, lasst); - } - postcondition(result) { - size() == oldof(size()) - std::distance(first, last); - if(empty()) result == end(); - // [first, last) is invalid - } - { - return vect_.erase(first, last); - } - - - - - - - - void clear() - postcondition { - empty(); - } - { - vect_.clear(); - } - - - - void swap(vector& other) - precondition { - get_allocator() == other.get_allocator(); - } - postcondition { - if constexpr(boost::has_equal_to::value) { - *this == oldof(other); - other == oldof(*this); - } - } - { - vect_.swap(other); - } - - - - - - - - - - - - - - - - - - - friend bool operator==(vector const& left, vector const& right) { - // Cannot check class invariants for left and right objects. - return left.vect_ == right.vect_; - } - - - - - -private: - std::vector vect_; -}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// End. -//] - diff --git a/include/boost/contract.hpp b/include/boost/contract.hpp deleted file mode 100644 index 8ee511a6..00000000 --- a/include/boost/contract.hpp +++ /dev/null @@ -1,44 +0,0 @@ - -#ifndef BOOST_CONTRACT_HPP_ -#define BOOST_CONTRACT_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Include all header files required by this library at once (for convenience). - -All header files boost/contract/\*.hpp are independent from one another -and can be included one-by-one to reduce the amount of code to compile from this -library in user code (but this was measured to not make an appreciable -difference in compile-time so boost/contract.hpp can be included directly -in most cases). -Instead the headers boost/contract/core/\*.hpp are not independent from -other library headers and they are automatically included by the -boost/contract/\*.hpp headers (so the boost/contract/core/\*.hpp -headers are usually not directly included by programmers). - -All files under the boost/contract/detail/ directory, names within the -@c boost::contract::detail namespace, names prefixed with -@c boost_contract_detail... and @c BOOST_CONTRACT_DETAIL... (in any namesapce, -including user's code) are reserved for internal use of this library and should -never be used directly by programmers. - -@see @RefSect{getting_started, Getting Started} -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif // #include guard - diff --git a/include/boost/contract/assert.hpp b/include/boost/contract/assert.hpp deleted file mode 100644 index 4cc6e8b4..00000000 --- a/include/boost/contract/assert.hpp +++ /dev/null @@ -1,131 +0,0 @@ - -#ifndef BOOST_CONTRACT_ASSERT_HPP_ -#define BOOST_CONTRACT_ASSERT_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Assert contract conditions. -*/ - -#include -#include - -#ifndef BOOST_CONTRACT_NO_ALL - #include - #define BOOST_CONTRACT_ASSERT(cond) \ - BOOST_CONTRACT_DETAIL_ASSERT(cond) /* no `;` here */ -#else - /** - Preferred way to assert contract conditions. - - Any exception thrown from within a contract (preconditions, postconditions, - exception guarantees, old value copies at body, class invariants, etc.) is - interpreted by this library as a contract failure. - Therefore, users can program contract assertions manually throwing an - exception when an asserted condition is checked to be @c false (this - library will then call the appropriate contract failure handler - @RefFunc{boost::contract::precondition_failure}, etc.). - However, it is preferred to use this macro because it expands to - code that throws @RefClass{boost::contract::assertion_failure} with the - correct assertion file name (using __FILE__), line number (using - __LINE__), and asserted condition code so to produce informative - error messages. - - @RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT} and - @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels - predefined by this library. - - @see @RefSect{tutorial.preconditions, Preconditions}, - @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{tutorial.exception_guarantees, Exceptions Guarantees}, - @RefSect{tutorial.class_invariants, Class Invariants} - - @param cond Boolean contract condition to check. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_ASSERT((cond)) will always work.) - */ - // This must be an expression (a trivial one so the compiler can optimize it - // away). It cannot an empty code block `{}`, etc. otherwise code like - // `if(...) ASSERT(...); else ASSERT(...);` won't work when NO_ALL. - #define BOOST_CONTRACT_ASSERT(cond) \ - BOOST_CONTRACT_DETAIL_NOOP -#endif - -#ifdef BOOST_CONTRACT_AUDITS - /** - Preferred way to assert contract conditions that are computationally - expensive, at least compared to the cost of executing the function body. - - The asserted condition will always be compiled and validated syntactically, - but it will not be evaluated at run-time unless - @RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default). - - This macro is defined by code equivalent to: - - @code - #ifdef BOOST_CONTRACT_AUDITS - #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \ - BOOST_CONTRACT_ASSERT(cond) - #else - #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \ - BOOST_CONTRACT_ASSERT(true || cond) - #endif - @endcode - - @RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT} and - @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels - predefined by this library. - If there is a need, programmers are free to implement their own assertion - levels defining macros similar to the one above. - - @see @RefSect{extras.assertion_levels, Assertions Levels} - - @param cond Boolean contract condition to check. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_ASSERT_AUDIT((cond)) will always work.) - */ - #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \ - BOOST_CONTRACT_ASSERT(cond) -#else - #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \ - BOOST_CONTRACT_DETAIL_NOEVAL(cond) -#endif - -/** -Preferred way to assert contract conditions that are computationally -prohibitive, at least compared to the cost of executing the function body. - -The asserted condition will always be compiled and validated syntactically, but -it will never be evaluated at run-time. - -This macro is defined by code equivalent to: - -@code - #define BOOST_CONTRACT_ASSERT_AXIOM(cond) \ - BOOST_CONTRACT_ASSERT(true || cond) -@endcode - -@RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT} and -@RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels predefined -by this library. -If there is a need, programmers are free to implement their own assertion levels -defining macros similar to the one above. - -@see @RefSect{extras.assertion_levels, Assertion Levels} - -@param cond Boolean contract condition to check. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_ASSERT_AXIOM((cond)) will always work.) -*/ -#define BOOST_CONTRACT_ASSERT_AXIOM(cond) \ - BOOST_CONTRACT_DETAIL_NOEVAL(cond) - -#endif // #include guard - diff --git a/include/boost/contract/base_types.hpp b/include/boost/contract/base_types.hpp deleted file mode 100644 index 4c801e66..00000000 --- a/include/boost/contract/base_types.hpp +++ /dev/null @@ -1,180 +0,0 @@ - -#ifndef BOOST_CONTRACT_BASE_TYPES_HPP_ -#define BOOST_CONTRACT_BASE_TYPES_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Specify inheritance form base classes (for subcontracting). -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#include -#if !BOOST_PP_VARIADICS - -#define BOOST_CONTRACT_BASE_TYPES \ -BOOST_CONTRACT_ERROR_macro_BASE_TYPES_requires_variadic_macros_otherwise_manually_program_base_types - -#elif !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // For HEAD, TAIL, etc. -#include -#include -#include -#include -#include -#include - -/* PRIVATE */ - -#define BOOST_CONTRACT_BASE_TYPES_REMOVE_VIRTUAL_(base) \ - BOOST_PP_EXPAND( \ - BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_VIRTUAL(base), \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_VIRTUAL \ - , \ - BOOST_PP_TUPLE_REM(1) \ - )(base) \ - ) - -#define BOOST_CONTRACT_BASE_TYPES_PUSH_BACK_IF_(is_public, types_nilseq, base) \ - ( \ - is_public, \ - BOOST_PP_IIF(is_public, \ - BOOST_PP_SEQ_PUSH_BACK \ - , \ - types_nilseq BOOST_PP_TUPLE_EAT(2) \ - )(types_nilseq, base) \ - ) - -#define BOOST_CONTRACT_BASE_TYPES_SKIP_NOT_PUBLIC_(is_public, types_nilseq, \ - base) \ - (0, types_nilseq) - -// Precondition: base = `public [virtual] ...`. -#define BOOST_CONTRACT_BASE_TYPES_PUSH_BACK_PUBLIC_(is_public, types_nilseq, \ - base) \ - ( \ - 1, \ - BOOST_PP_SEQ_PUSH_BACK(types_nilseq, \ - BOOST_CONTRACT_BASE_TYPES_REMOVE_VIRTUAL_( \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_PUBLIC(base)) \ - ) \ - ) - -#define BOOST_CONTRACT_BASE_TYPES_ACCESS_(is_public, types_nilseq, base) \ - BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PUBLIC(base), \ - BOOST_CONTRACT_BASE_TYPES_PUSH_BACK_PUBLIC_ \ - , BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PROTECTED(base), \ - BOOST_CONTRACT_BASE_TYPES_SKIP_NOT_PUBLIC_ \ - , BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PRIVATE(base), \ - BOOST_CONTRACT_BASE_TYPES_SKIP_NOT_PUBLIC_ \ - , \ - BOOST_CONTRACT_BASE_TYPES_PUSH_BACK_IF_ \ - )))(is_public, types_nilseq, base) - -#define BOOST_CONTRACT_BASE_TYPES_(s, public_types, base) \ - BOOST_CONTRACT_BASE_TYPES_ACCESS_( \ - BOOST_PP_TUPLE_ELEM(2, 0, public_types), \ - BOOST_PP_TUPLE_ELEM(2, 1, public_types), \ - BOOST_CONTRACT_BASE_TYPES_REMOVE_VIRTUAL_(base) \ - ) - -#define BOOST_CONTRACT_BASE_TYPES_RETURN_YES_(types_nilseq) \ - BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_TAIL(types_nilseq)) - -#define BOOST_CONTRACT_BASE_TYPES_RETURN_(types_nilseq) \ - BOOST_PP_IIF(BOOST_PP_EQUAL(BOOST_PP_SEQ_SIZE(types_nilseq), 1), \ - BOOST_PP_TUPLE_EAT(1) \ - , \ - BOOST_CONTRACT_BASE_TYPES_RETURN_YES_ \ - )(types_nilseq) - -#define BOOST_CONTRACT_BASE_TYPES_OK_(base_tuple, bases_seq) \ - boost::mpl::vector< \ - BOOST_CONTRACT_BASE_TYPES_RETURN_(BOOST_PP_TUPLE_ELEM(2, 1, \ - BOOST_PP_SEQ_FOLD_LEFT( \ - BOOST_CONTRACT_BASE_TYPES_, \ - (0, (BOOST_PP_NIL)), \ - bases_seq \ - ) \ - )) \ - > - -#define BOOST_CONTRACT_BASE_TYPES_ERR_(bases_tuple, bases_seq) \ - BOOST_CONTRACT_ERROR_all_bases_must_explicitly_specify_public_protected_or_private base_tuple - -#define BOOST_CONTRACT_BASE_TYPES_IS_ACCESS_(base) \ - BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PUBLIC(base), \ - 1 \ - , BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PROTECTED(base), \ - 1 \ - , BOOST_PP_IIF(BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PRIVATE(base), \ - 1 \ - , \ - 0 \ - ))) - -// Cannot check that all base types have access specifiers (unless users have to -// specify bases using pp-seq, because user specified base list can have -// unwrapped commas between bases but also within a given base type, when base -// types are templates), but at least check the very first base type explicitly -// specifies access `[virtual] public | protected | private [virtual] ...`. -#define BOOST_CONTRACT_BASE_TYPES_CHECK_(bases_tuple, bases_seq) \ - BOOST_PP_IIF(BOOST_CONTRACT_BASE_TYPES_IS_ACCESS_( \ - BOOST_CONTRACT_BASE_TYPES_REMOVE_VIRTUAL_(BOOST_PP_SEQ_HEAD( \ - bases_seq))), \ - BOOST_CONTRACT_BASE_TYPES_OK_ \ - , \ - BOOST_CONTRACT_BASE_TYPES_ERR_ \ - )(bases_tuple, bases_seq) - -/* PUBLIC */ - -#define BOOST_CONTRACT_BASE_TYPES(...) \ - BOOST_CONTRACT_BASE_TYPES_CHECK_((__VA_ARGS__), \ - BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) - -#else - -/** -Used to program a @c typedef listing the bases of a derived class. - -In order to support subcontracting, a derived class that specifies contracts for -one or more overriding public function must declare a @c typedef named -@RefMacro{BOOST_CONTRACT_BASES_TYPEDEF} using this macro. -This @c typedef must be @c public unless @RefClass{boost::contract::access} is -used. - -@see @RefSect{tutorial.base_classes__subcontracting_, Base Classes} - -@param ... Comma separated list of base classes. - Each base must explicitly specify its access specifier @c public, - @c protected, or @c private, and also @c virtual when present - (this not always required in C++ instead). - There is a limit of about 20 maximum bases that can be listed - (because of similar limits in Boost.MPL internally used by this - library). - This is a variadic macro parameter, on compilers that do not support - variadic macros, the @c typedef for base classes can be programmed - manually without using this macro. -*/ -#define BOOST_CONTRACT_BASE_TYPES(...) void /* dummy type for typedef */ - -#endif - -#endif // #include guard - diff --git a/include/boost/contract/call_if.hpp b/include/boost/contract/call_if.hpp deleted file mode 100644 index 8520a4ef..00000000 --- a/include/boost/contract/call_if.hpp +++ /dev/null @@ -1,615 +0,0 @@ - -#ifndef BOOST_CONTRACT_CALL_IF_HPP_ -#define BOOST_CONTRACT_CALL_IF_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Statically disable compilation and execution of functor calls. - -@note This facility allows to emulate C++17 if constexpr statements - when used together with functor templates (or C++14 generic lambdas). -*/ - -#include -#include -#include -#include -#include - -/* PRIVATE */ - -/** @cond */ - -// Boost.ResultOf not always able to deduce lambda result type (on MSVC). -#ifndef BOOST_NO_CXX11_DECL_TYPE - #include - #define BOOST_CONTRACT_CALL_IF_RESULT_OF_(F) \ - decltype(boost::declval()()) -#else - #include - #define BOOST_CONTRACT_CALL_IF_RESULT_OF_(F) \ - typename boost::result_of::type -#endif - -/** @endcond */ - -/* CODE */ - -namespace boost { namespace contract { - -/** -Select compilation and execution of functor template calls using a static -boolean predicate. - -This class template has no member because it is never used directly, it is only -used via its specializations. -Usually this class template is instantiated only via the return value of -@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}. - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@tparam Pred Static boolean predicate that selects which functor template - call to compile and execute. -@tparam Then Type of the functor template to call if the static predicate is - @c true. -@tparam ThenResult Return type of then-branch functor template call (this is - usually automatically deduced by this library so it is never explicitly - specified by the user, and that is why it is often marked as - @c internal_type in this documentation). -*/ -template -struct call_if_statement {}; // Empty so cannot be used (but copyable). - -/** -Dispatch between then-branch functor template calls that return void and the -ones that return non-void. - -The base class is a call-if statement so the else and else-if statements can be -specified if needed. -Usually this class template is instantiated only via the return value of -@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}. - -@note The result_of::type expression should be evaluated only - when the static predicate is already checked to be @c true (because - @c Then() is required to compile only in that case). - Thus, this template specialization introduces an extra level of - indirection necessary for the proper lazy evaluation of this result-of - expression. - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@tparam Then Type of functor template to call when the static predicate is - @c true (as it is for this template specialization). -*/ -template -struct call_if_statement : - call_if_statement::type - #endif - > -{ // Copyable (as its base). - /** - Construct this object with the then-branch functor template. - - @param f Then-branch nullary functor template. - The functor template call @c f() is compiled and called in this - case (because the if-statement static predicate is @c true for - this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the return type of all other functor template - calls specified for this call-if object. - */ - explicit call_if_statement(Then f) : call_if_statement(f) {} -}; - -/** -Handle static predicates that are @c true for then-branch functor template calls -that do not return void. - -Usually this class template is instantiated only via the return value of -@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}. - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@tparam Then Type of functor template to call when the static predicate is - @c true (as it is for this template specialization). -@tparam ThenResult Non-void return type of the then-branch functor template - call. -*/ -template -struct call_if_statement { // Copyable (as *). - /** - Construct this object with the then-branch functor template. - - @param f Then-branch nullary functor template. - The functor template call @c f() is actually compiled and - executed in this case (because the if-statement static - predicate is @c true for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the @p ThenResult type. - */ - explicit call_if_statement(Then f) : - r_(boost::make_shared(f())) {} - - /** - This implicit type conversion returns a copy of the value returned by the - call to the then-branch functor template. - */ - operator ThenResult() const { return *r_; } - - /** - Specify the else-branch functor template. - - @param f Else-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the @p ThenResult type. - - @return A copy of the value returned by the call to the then-branch functor - template (because the else-branch functor template call is not - executed in this case). - */ - template - ThenResult else_(Else const& f) const { return *r_; } - - /** - Specify an else-if-branch functor template (using a static boolean - predicate). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the @p ThenResult type. - - @tparam ElseIfPred Static boolean predicate selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, it will be the return value of the then-branch functor - template call in this case (because the if-statement static - predicate is @c true for this template specialization). - */ - template - call_if_statement else_if_c(ElseIfThen const& f) - const { return *this; } - - /** - Specify an else-if-branch functor template (using a nullary boolean - meta-function). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the @p ThenResult type. - - @tparam ElseIfPred Nullary boolean meta-function selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, it will be the return value of the then-branch functor - template call in this case (because the if-statement static - predicate is @c true for this template specialization). - */ - template - call_if_statement else_if(ElseIfThen const& f) - const { return *this; } - -private: - boost::shared_ptr r_; -}; - -/** -Handle static predicates that are @c true for then-branch functor template calls -that return void. - -Usually this class template is instantiated only via the return value of -@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}. - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@tparam Then Type of functor template to call when the static predicate if - @c true (as it is for this template specialization). -*/ -template -struct call_if_statement { // Copyable (no data). - /** - Construct this object with the then-branch functor template. - - @param f Then-branch nullary functor template. - The functor template call @c f() is actually compiled and - executed in this case (because the if-statement static predicate - is @c true for this template specialization). - The return type of @c f() must be @c void in this case (because - the then-branch functor template calls return void for this - template specialization). - */ - explicit call_if_statement(Then f) { f(); } - - // Cannot provide `operator ThenResult()` here, because ThenResult is void. - - /** - Specify the else-branch functor template. - - @param f Else-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be @c void in this case (because - the then-branch functor template calls return void for this - template specialization). - */ - template - void else_(Else const& f) const {} - - /** - Specify an else-if-branch functor template (using a static boolean - predicate). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be @c void in this case (because - the then-branch functor template calls return void for this - template specialization). - - @tparam ElseIfPred Static boolean predicate selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, it will return void in this case (because the - then-branch functor template calls return void for this template - specialization). - */ - template - call_if_statement else_if_c(ElseIfThen const& f) const { - return *this; - } - - /** - Specify an else-if-branch functor template (using a nullary boolean - meta-function). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c true for this template specialization). - The return type of @c f() must be @c void in this case (because - the then-branch functor template calls return void for this - template specialization). - - @tparam ElseIfPred Nullary boolean meta-function selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, it will return void in this case (because the - then-branch functor template calls return void for this template - specialization). - */ - template - call_if_statement else_if(ElseIfThen const& f) const { - return *this; - } -}; - -/** -Handle static predicates that are @c false. - -This single specialization handles all else-branch functor template calls -(whether they return void or not). -Usually this class template is instantiated only via the return value of -@RefFunc{boost::contract::call_if} and @RefFunc{boost::contract::call_if_c}. - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@tparam Then Type of functor template to call when the static predicate is - @c true (never the case for this template specialization). -*/ -template // Copyable (no data). -struct call_if_statement { - /** - Construct this object with the then-branch functor template. - - @param f Then-branch nullary functor template. - The functor template call @c f() is never compiled and executed - in this case (because the if-statement static predicate is - @c false for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the return type of all other functor template - calls specified for this call-if object. - */ - explicit call_if_statement(Then const& f) {} - - // Do not provide `operator result_type()` here, require else_ instead. - - /** - Specify the else-branch functor template. - - @note The result_of::type expression should be evaluated - only when the static predicate is already checked to be @c false - (because @c Else() is required to compile only in that case). - Thus, this result-of expression is evaluated lazily only in - instantiations of this template specialization. - - @param f Else-branch nullary functor template. - The functor template call @c f() is actually compiled and - executed in this case (because the if-statement static predicate - is @c false for this template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the return type of all other functor template - calls specified for this call-if object. - - @return A copy of the value returned by the call to the else-branch functor - template @c f(). - */ - template - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CALL_IF_RESULT_OF_(Else) - #else - typename result_of::type - #endif - else_(Else f) const { return f(); } - - /** - Specify an else-if-branch functor template (using a static boolean - predicate). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is actually compiled and - executed if and only if @c ElseIfPred is @c true (because the - if-statement static predicate is already @c false for this - template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the return type of all other functor template - calls specified for this call-if object. - - @tparam ElseIfPred Static boolean predicate selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, this will be the return value of the functor template - call being compiled and executed. - */ - template - call_if_statement else_if_c(ElseIfThen f) const { - return call_if_statement(f); - } - - /** - Specify an else-if-branch functor template (using a nullary boolen - meta-function). - - @param f Else-if-branch nullary functor template. - The functor template call @c f() is actually compiled and - executed if and only if @c ElseIfPred::value is @c true (because - the if-statement static predicate is already @c false for this - template specialization). - The return type of @c f() must be the same as (or implicitly - convertible to) the return type of all other functor template - calls specified for this call-if object. - - @tparam ElseIfPred Nullary boolean meta-function selecting which functor - template call to compile and execute. - - @return A call-if statement so the else statement and additional else-if - statements can be specified if needed. - Eventually, this will be the return value of the functor template - call being compiled and executed. - */ - template - call_if_statement else_if(ElseIfThen f) - const { - return call_if_statement(f); - } -}; - -/** -Select compilation and execution of functor template calls using a static -boolean predicate. - -Create a call-if object with the specified then-branch functor template. -Optional functor templates for else-if-branches and the else-branch can be -specified as needed. -For example: - -@code -boost::contract::call_if( - then_functor_template1 -).template else_if( // Optional. - then_functor_template2 -) -... // Optionally, other `else_if`. -.else_( // Optional for `void` functors, - else_functor_template // but required for non `void`. -) -@endcode - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@param f Then-branch nullary functor template. - The functor template call @c f() is compiled and executed if and - only if @c Pred is @c true. - The return type of other functor template calls specified for this - call-if statement (else-branches, else-if-branches, etc.) must be - the same as (or implicitly convertible to) the return type of - then-branch functor call @c f(). - -@tparam Pred Static boolean predicate selecting which functor template call - to compile and execute. - -@return A call-if statement so else and else-if statements can be specified if - needed. - Eventually, this will be the return value of the functor template call - being compiled and executed (which can also be @c void). -*/ -template -call_if_statement call_if_c(Then f) { - return call_if_statement(f); -} - -/** -Select compilation and execution of functor template calls using a nullary -boolean meta-function. - -Create a call-if object with the specified then-branch functor template. -This is equivalent to boost::contract::call_if_c(f). -Optional functor templates for else-if-branches and the else-branch can be -specified as needed. -For example: - -@code -boost::contract::call_if( - then_functor_template1 -).template else_if( // Optional. - then_functor_template2 -) -... // Optionally, other `else_if`. -.else_( // Optional for `void` functors, - else_functor_template // but required for non `void`. -) -@endcode - - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@param f Then-branch nullary functor template. - The functor template call @c f() is compiled and executed if and - only if @c Pred::value is @c true. - The return type of other functor template calls specified for this - call-if statement (else-branches, else-if-branches, etc.) must be - the same as (or implicitly convertible to) the return type of - then-branch functor template call @c f(). - -@tparam Pred Nullary boolean meta-function selecting which functor template - call to compile and execute. - -@return A call-if statement so else and else-if statements can be specified if - needed. - Eventually, this will be the return value of the functor template call - being compiled and executed (which can also be @c void). -*/ -template -call_if_statement call_if(Then f) { - return call_if_statement(f); -} - -/** -Select compilation and execution of a boolean functor template condition using a -static boolean predicate. - -Compile and execute the nullary boolean functor template call @c f() if and only -if the specified static boolean predicate @p Pred is @c true, otherwise -trivially return @p else_ (@c true by default) at run-time. -A call to boost::contract::condition_if_c(f, b) is logically -equivalent to boost::contract::call_if_c(f, [b] { return b; }) (but -its implementation is optimized with respsect to the @c call_if_c equivalent). - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@param f Nullary boolean functor template. - The functor template call @c f() is compiled and executed if and - only if @c Pred is @c true. - -@tparam Pred Static boolean predicate selecting when the functor template - call @c f() should be compiled and executed. -@param else_ Boolean value to return when @c Pred is @c false (instead of - compiling and executing the functor template call @c f()). - -@return Boolean value returned by @c f() if the static predicate @c Pred is - @c true. Otherwise, trivially return @p else_. -*/ -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - template - bool condition_if_c(Then f, bool else_ = true); -#else - // NOTE: condition_if is a very simple special case of call_if so it can be - // trivially implemented using enable_if instead of call_if as done below. - - template - typename boost::enable_if_c::type - condition_if_c(Then f, bool else_ = true) { return f(); } - - template - typename boost::disable_if_c::type - condition_if_c(Then f, bool else_ = true) { return else_; } -#endif - -/** -Select compilation and execution of a boolean functor template condition using a -nullary boolean meta-function. - -Compile and execute the nullary boolean functor template call @c f() if and only -if the specified nullary boolean meta-function @p Pred is @c true, otherwise -trivially return @p else_ (@c true by default) at run-time. -This is equivalent to -boost::contract::condition_if_c(f, else_). - -@see @RefSect{extras.assertion_requirements__templates_, - Assertion Requirements} - -@param f Nullary boolean functor template. - The functor template call @c f() is compiled and executed if and - only if @c Pred::value is @c true. -@param else_ Boolean value to return when @c Pred::value is @c false (instead - of compiling and executing the functor template call @c f()). - -@tparam Pred Nullary boolean meta-function selecting when the functor - template call @c f() should be compiled and executed. - -@return Boolean value returned by @c f() if the static predicate @c Pred is - @c true. Otherwise, trivially return @p else_. -*/ -template -bool condition_if(Then f, bool else_ = true) { - return condition_if_c(f, else_); -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/check.hpp b/include/boost/contract/check.hpp deleted file mode 100644 index 9eaed806..00000000 --- a/include/boost/contract/check.hpp +++ /dev/null @@ -1,300 +0,0 @@ - -#ifndef BOOST_CONTRACT_CHECK_HPP_ -#define BOOST_CONTRACT_CHECK_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -RAII object that checks contracts. -*/ - -#include -#include -#include -#include // For set_... (if always in code). -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include - #include - #include -#endif -#include -#include - -/* PRIVATE */ - -/** @cond */ - -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #define BOOST_CONTRACT_CHECK_CTOR_DEF_(contract_type) \ - : cond_(const_cast(contract).cond_.release()) \ - { \ - BOOST_CONTRACT_DETAIL_DEBUG(cond_); \ - cond_->initialize(); \ - } -#else - #define BOOST_CONTRACT_CHECK_CTOR_DEF_(contract_type) {} -#endif - -/** @endcond */ - -/* CODE */ - -namespace boost { namespace contract { - -/** -RAII object that checks the contracts. - -In general, when this object is constructed it checks class invariants at entry, -preconditions, and makes old value copies at body. -When it is destructed, it checks class invariants at exist, postconditions, and -exception guarantees. -This object enforces the following (see also -@RefSect{contract_programming_overview, Contract Programming Overview}): - -@li Postconditions are checked only if the body does not throw an exception. -@li Exceptions guarantees are checked only if the body throws an exception. -@li Constructor entry never checks class invariants. -@li Destructor exit checks class invariants only if the body throws an -exception. -@li Static invariants are always checked at entry and exit (and regardless of -the body throwing exceptions or not). - -This object is usually constructed initializing it to the return value of one -of the contract functions @RefFunc{boost::contract::function}, -@RefFunc{boost::contract::constructor}, @RefFunc{boost::contract::destructor}, -or @RefFunc{boost::contract::public_function}. -In addition, this object can be constructed from a nullary functor that is used -to program implementation checks. - -@see @RefSect{tutorial, Tutorial}, - @RefSect{advanced.implementation_checks, Implementation Checks} -*/ -class check { // Copy ctor only (as move via ptr release). -public: - // f must be a valid callable object (not null func ptr, empty ftor, etc. - /** - Construct this object for implementation checks. - - This can be used to program checks within implementation code (body, etc.). - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param f Nullary functor that asserts implementation checks. @c f() will - be called as soon as this object is constructed at the point it - is declared within the implementation code. - */ - template // Cannot check `if(f) ...` as f can be a lambda. - /* implicit */ check(F const& f) { BOOST_CONTRACT_DETAIL_CHECK({ f(); }) } - - /** - Construct this object copying it from the specified one. - - This object will check the contract, the copied-from object will not (i.e., - contract check ownership is transferred from the copied object to the new - object being created by this constructor). - - @param other Copied-from object. - */ - check(check const& other) // Copy ctor moves cond_ pointer to dest. - #if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - : cond_(const_cast(other).cond_.release()) - #endif - {} - - /** - Construct this object to check the specified contract. - - This checks class invariants at entry (if they apply to the specified - contract). - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param contract Contract to be checked. - - @tparam VirtualResult Return type of the enclosing function declaring the - contract if that is either a virtual or an - overriding public function. - Otherwise, this is always @c void. - */ - template - /* implicit */ check(specify_precondition_old_postcondition_except< - VirtualResult> const& contract) - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_( - specify_precondition_old_postcondition_except) - #else - ; - #endif - - /** - Construct this object to check the specified contract. - - This checks class invariants at entry (if they apply to the specified - contract) and preconditions. - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param contract Contract to be checked. - - @tparam VirtualResult Return type of the enclosing function declaring the - contract if that is either a virtual or an - overriding public function. - Otherwise, this is always @c void. - */ - template - /* implicit */ check(specify_old_postcondition_except const& - contract) - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_( - specify_old_postcondition_except) - #else - ; - #endif - - /** - Construct this object to check the specified contract. - - This checks class invariants at entry (if they apply to the specified - contract) and preconditions, then it makes old value copies at body. - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param contract Contract to be checked. - - @tparam VirtualResult Return type of the enclosing function declaring the - contract if that is either a virtual or an - overriding public function. - Otherwise, this is always @c void. - */ - template - /* implicit */ check(specify_postcondition_except const& - contract) - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_( - specify_postcondition_except) - #else - ; - #endif - - /** - Construct this object to check the specified contract. - - This checks class invariants at entry (if they apply to the specified - contract) and preconditions, then it makes old value copies at body. - (plus the destructor of this object will check postconditions in this case). - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param contract Contract to be checked. - - @tparam VirtualResult Return type of the enclosing function declaring the - contract if that is either a virtual or an - overriding public function. - Otherwise, this is always @c void. - */ - /* implicit */ check(specify_except const& contract) - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_(specify_except) - #else - ; - #endif - - /** - Construct this object to check the specified contract. - - This checks class invariants at entry (if they apply to the specified - contract) and preconditions, then it makes old value copies at body. - (plus the destructor of this object will check postconditions and - exception guarantees in this case). - This constructor is not declared @c explicit so initializations can use - operator @c = syntax. - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - - @param contract Contract to be checked. - - @tparam VirtualResult Return type of the enclosing function declaring the - contract if that is either a virtual or an - overriding public function. - Otherwise, this is always @c void. - */ - /* implicit */ check(specify_nothing const& contract) - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_(specify_nothing) - #else - ; - #endif - - /** - Destruct this object. - - This checks class invariants at exit and either postconditions when the - enclosing function body did not throw an exception, or exception guarantees - when the function body threw an exception (that is if class invariants, - postconditions, and exception guarantees respectively apply to the object - specified when constructing this object). - - @b Throws: This can throw (it is declared @c noexcept(false)) in case - programmers specify contract failure handlers that throw - exceptions instead of terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~check() BOOST_NOEXCEPT_IF(false) {} // Allow auto_ptr dtor to throw. - -/** @cond */ -private: - check& operator=(check const&); // Cannot copy outside of `check c = ...`. - - #if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - boost::contract::detail::auto_ptr - cond_; - #endif -/** @endcond */ -}; - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/constructor.hpp b/include/boost/contract/constructor.hpp deleted file mode 100644 index b92e43ce..00000000 --- a/include/boost/contract/constructor.hpp +++ /dev/null @@ -1,73 +0,0 @@ - -#ifndef BOOST_CONTRACT_CONSTRUCTOR_HPP_ -#define BOOST_CONTRACT_CONSTRUCTOR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Program contracts for constructors. -*/ - -#include -#include -#include -#include -#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include -#endif - -namespace boost { namespace contract { - -/** -Program contracts for constructors. - -This is used to specify postconditions, exception guarantees, old value copies -at body, and check class invariants for constructors (see -@RefClass{boost::contract::constructor_precondition} to specify preconditions -for constructors instead). - -For optimization, this can be omitted for constructors that do not have -postconditions and exception guarantees, within classes that have no invariants. - -@see @RefSect{tutorial.constructors, Constructors} - -@param obj The object @c this from the scope of the enclosing constructor - declaring the contract. - (Constructors check all class invariants, including static and - volatile invariants, see also @RefSect{tutorial.class_invariants, - Class Invariants} and - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - -@tparam Class The type of the class containing the constructor declaring the - contract. - (Usually this template parameter is automatically deduced by C++ - and it does not need to be explicitly specified by programmers.) - -@return The result of this function must be explicitly assigned to a variable of - type @RefClass{boost::contract::check} declared locally just before the - code of the constructor body (otherwise this library will generate a - run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). -*/ -template -specify_old_postcondition_except<> constructor(Class* obj) { - // Must #if also on ..._PRECONDITIONS here because specify_... is generic. - #if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - return specify_old_postcondition_except<>( - new boost::contract::detail::constructor(obj)); - #else - return specify_old_postcondition_except<>(); - #endif -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/core/access.hpp b/include/boost/contract/core/access.hpp deleted file mode 100644 index 1e8a5aa1..00000000 --- a/include/boost/contract/core/access.hpp +++ /dev/null @@ -1,166 +0,0 @@ - -#ifndef BOOST_CONTRACT_ACCESS_HPP_ -#define BOOST_CONTRACT_ACCESS_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Allow to declare invariants, base types, etc all as private members. -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include - #include -#endif -#ifndef BOOST_CONTRACT_NO_INVARIANTS - #include - #include - #include -#endif - -namespace boost { namespace contract { - -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - class virtual_; - - namespace detail { - BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1, - /* is_friend = */ 0, OO, RR, FF, CC, AArgs); - } -#endif -#ifndef BOOST_CONTRACT_NO_INVARIANTS - namespace detail { - template - class cond_inv; - } -#endif - -/** -Friend this class to declare invariants and base types as private members. - -Declare this class a friend of the user-defined class specifying the contracts -in order to declare the invariant functions and the base types @c typedef as -non-public members. -In real code, programmers will likely chose to declare this class as friend so -to fully control public interfaces of their user-defined classes. - -This class is not intended to be directly used by programmers a part from -declaring it @c friend (and that is why this class does not have any public -member and it is not copyable). - -@warning Not declaring this class friend of user-defined classes will cause - compiler errors on some compilers (e.g., MSVC) because the private - members needed to check the contracts will not be accessible. - On other compilers (e.g., GCC and CLang), the private access will - instead fail SFINAE and no compiler error will be reported while - invariants and subcontracting will be silently skipped at run-time. - Therefore, programmers must make sure to either declare this class - as friend (preferred) or to always declare invariant functions and - base types @c typedef as public members. - -@see @RefSect{advanced.access_specifiers, Access Specifiers} -*/ -class access { // Non-copyable (see below). -/** @cond */ -private: // No public APIs (so users cannot use it directly by mistake). - - access(); // Should never be constructed (not even internally). - ~access(); - - // No boost::noncopyable to avoid its overhead when contracts disabled. - access(access&); - access& operator=(access&); - - #if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - BOOST_CONTRACT_DETAIL_MIRROR_HAS_TYPE(has_base_types, - BOOST_CONTRACT_BASES_TYPEDEF) - - template - struct base_types_of { - typedef typename C::BOOST_CONTRACT_BASES_TYPEDEF type; - }; - #endif - - #ifndef BOOST_CONTRACT_NO_INVARIANTS - BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( - has_static_invariant_f, BOOST_CONTRACT_STATIC_INVARIANT_FUNC) - - BOOST_CONTRACT_DETAIL_MIRROR_HAS_STATIC_MEMBER_FUNCTION( - has_static_invariant_s, BOOST_CONTRACT_STATIC_INVARIANT_FUNC) - - template - struct has_static_invariant : has_static_invariant_s > {}; - - template - static void static_invariant() { - C::BOOST_CONTRACT_STATIC_INVARIANT_FUNC(); - } - - template - class static_invariant_addr { // Class so to pass it as tparam. - typedef void (*func_ptr)(); - public: - static func_ptr apply() { - return &C::BOOST_CONTRACT_STATIC_INVARIANT_FUNC; - } - }; - - BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( - has_invariant_f, BOOST_CONTRACT_INVARIANT_FUNC) - - BOOST_CONTRACT_DETAIL_MIRROR_HAS_STATIC_MEMBER_FUNCTION( - has_invariant_s, BOOST_CONTRACT_INVARIANT_FUNC) - - template - struct has_cv_invariant : has_invariant_f, - boost::function_types::cv_qualified> {}; - - template - struct has_const_invariant : has_invariant_f, boost::function_types::const_qualified> {}; - - template - static void cv_invariant(C const volatile* obj) { - BOOST_CONTRACT_DETAIL_DEBUG(obj); - obj->BOOST_CONTRACT_INVARIANT_FUNC(); - } - - template - static void const_invariant(C const* obj) { - BOOST_CONTRACT_DETAIL_DEBUG(obj); - obj->BOOST_CONTRACT_INVARIANT_FUNC(); - } - #endif - - // Friends (used to limit library's public API). - // NOTE: Using friends here and in all other places in this library - // does not increase compilation times (I experimented replacing all - // friends with public and got the same compilation times). - #if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1, - /* is_friend = */ 1, OO, RR, FF, CC, AArgs); - - BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(1, - OO, RR, FF, CC, AArgs, vv, rr, ff, oobj, aargs) - #endif - #ifndef BOOST_CONTRACT_NO_INVARIANTS - template - friend class boost::contract::detail::cond_inv; - #endif -/** @endcond */ -}; - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/core/check_macro.hpp b/include/boost/contract/core/check_macro.hpp deleted file mode 100644 index ca242266..00000000 --- a/include/boost/contract/core/check_macro.hpp +++ /dev/null @@ -1,123 +0,0 @@ - -#ifndef BOOST_CONTRACT_CHECK_MACRO_HPP_ -#define BOOST_CONTRACT_CHECK_MACRO_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Macro for implementation checks. -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#include - -#ifndef BOOST_CONTRACT_NO_CHECKS - #include - #include - - #define BOOST_CONTRACT_CHECK(cond) \ - BOOST_CONTRACT_DETAIL_CHECK(BOOST_CONTRACT_DETAIL_ASSERT(cond)) -#else - /** - Preferred way to assert implementation check conditions. - - It is preferred to use this macro instead of programming implementation - checks in a nullary functor passed to @RefClass{boost::contract::check} - constructor because this macro will completely remove implementation checks - from the code when @RefMacro{BOOST_CONTRACT_NO_CHECKS} is defined. - - @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and - @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels - predefined by this library. - - @see @RefSect{advanced.implementation_checks, Implementation Checks} - - @param cond Boolean condition to check within implementation code (function - body, etc.). - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_CHECK((cond)) will always work.) - */ - #define BOOST_CONTRACT_CHECK(cond) /* nothing */ -#endif - -#ifdef BOOST_CONTRACT_AUDITS - /** - Preferred way to assert implementation check conditions that are - computationally expensive, at least compared to the cost of executing the - function body. - - The specified condition will always be compiled and validated - syntactically, but it will not be evaluated at run-time unless - @RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default). - - This macro is defined by code equivalent to: - - @code - #ifdef BOOST_CONTRACT_AUDITS - #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ - BOOST_CONTRACT_CHECK(cond) - #else - #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ - BOOST_CONTRACT_CHECK(true || cond) - #endif - @endcode - - @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and - @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels - predefined by this library. - If there is a need, programmers are free to implement their own assertion - levels defining macros similar to the one above. - - @see @RefSect{extras.assertion_levels, Assertion Levels} - - @param cond Boolean condition to check within implementation code (function - body, etc.). - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_CHECK((cond)) will always work.) - */ - #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ - BOOST_CONTRACT_CHECK(cond) -#else - #define BOOST_CONTRACT_CHECK_AUDIT(cond) \ - BOOST_CONTRACT_DETAIL_NOEVAL(cond) -#endif - -/** -Preferred way to assert implementation check conditions that are computationally -prohibitive, at least compared to the cost of executing the function body. - -The specified condition will always be compiled and validated -syntactically, but it will never be evaluated at run-time. - -This macro is defined by code equivalent to: - -@code -#define BOOST_CONTRACT_CHECK_AXIOM(cond) \ - BOOST_CONTRACT_CHECK(true || cond) -@endcode - -@RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and -@RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels predefined -by this library. -If there is a need, programmers are free to implement their own assertion levels -defining macros similar to the one above. - -@see @RefSect{extras.assertion_levels, Assertion Levels} - -@param cond Boolean condition to check within implementation code (function - body, etc.). - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - @c BOOST_CONTRACT_CHECK((cond)) will always work.) -*/ -#define BOOST_CONTRACT_CHECK_AXIOM(cond) \ - BOOST_CONTRACT_DETAIL_NOEVAL(cond) - -#endif // #include guard - diff --git a/include/boost/contract/core/config.hpp b/include/boost/contract/core/config.hpp deleted file mode 100644 index 7d0d96f6..00000000 --- a/include/boost/contract/core/config.hpp +++ /dev/null @@ -1,714 +0,0 @@ - -#ifndef BOOST_CONTRACT_CONFIG_HPP_ -#define BOOST_CONTRACT_CONFIG_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Configure this library compile-time and run-time behaviours. -*/ - -// IMPORTANT: This header MUST NOT #include any other header of this lib. -// That way users can #include this header and not #include any of this lib -// headers after that depending on the contract 0/1 macros below ensuring no -// compilation overhead. - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to compile this library as a static (instead of shared) - library (undefined by default). - - If this macro is defined, this library is compiled so it can be linked - statically to user code (and not as a shared library as by default). - - @warning This library is not guaranteed to always work correctly at - run-time when this macro is defined. - However, this macro can be defined and this library can be - safely used as a static library for user code that checks - contracts in a single program unit (e.g., a single program with - only statically linked libraries that check contracts). - - @see @RefSect{getting_started.install_and_compile, Install and Compile} - */ - #define BOOST_CONTRACT_STATIC_LINK -#elif defined(BOOST_CONTRACT_STATIC_LINK) && \ - ( \ - defined(BOOST_CONTRACT_HEADER_ONLY) || \ - defined(BOOST_ALL_DYN_LINK) \ - ) - #error "STATIC_LINK defined with HEADER_ONLY and/or ALL_DYN_LINK" -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to use this library as a header-only library (undefined by - default). - - If this macro is defined, this library does not have to be compiled - separately from user code. - This library headers are simply included and compiled as part of the user - program. - - @warning This library is not guaranteed to always work correctly at - run-time when this macro is defined. - However, this macro can be defined and this library can be - safely used as a header-only library for user code that checks - contracts in a single program unit (e.g., a single program with - only statically linked libraries that check contracts). - - @see @RefSect{getting_started.install_and_compile, Install and Compile} - */ - #define BOOST_CONTRACT_HEADER_ONLY -#elif defined(BOOST_CONTRACT_HEADER_ONLY) && \ - ( \ - defined(BOOST_CONTRACT_STATIC_LINK) || \ - defined(BOOST_ALL_DYN_LINK) \ - ) - #error "HEADER_ONLY defined with STATIC_LINK and/or ALL_DYN_LINK" -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to not lock internal library data for thread safety - (undefined by default). - - Defining this macro will make the library implementation code not thread - safe so this macro should not be defined unless the library is being used by - single-threaded applications only. - - However, when this macro is left undefined this library needs to internally - use some sort of "global" lock (to ensure contract checking is globally - disabled when other contracts are being checked and also to safely access - failure handler functors). - That could introduce an undesired amount of synchronization in some - multi-threaded applications. - - @see @RefSect{contract_programming_overview.assertions, Assertions} - */ - #define BOOST_CONTRACT_DISABLE_THREADS -#endif - -#ifndef BOOST_CONTRACT_MAX_ARGS - /** - Maximum number of function arguments on compilers that do not support - variadic macros (default to @c 10). - - On compilers that support variadic macros, this macro has no effect. - On compilers that do not support variadic macros, this macro can be defined - to the maximum number of arguments that public function overrides can - have and pass to @RefFunc{boost::contract::public_function}. - - @note Regardless of the value of this macro and of compiler support for - variadic macros, there is an intrinsic limit of about 18 arguments - for public function overrides (because of similar limits in - Boost.MPL and Boost.FunctionTypes internally used by this library). - - @see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - */ - #define BOOST_CONTRACT_MAX_ARGS 10 -#endif - -#ifndef BOOST_CONTRACT_BASES_TYPEDEF - /** - Define the name of the base type @c typedef (@c base_types by default). - - This macro expands to the name of the @c typedef that lists the base - classes for subcontracting via @RefMacro{BOOST_CONTRACT_BASE_TYPES}. - This macro can be defined if the @c typedef must have a name different from - @c base_types (because of name clashes in user code, etc.). - - @see @RefSect{tutorial.base_classes__subcontracting_, Base Classes} - */ - #define BOOST_CONTRACT_BASES_TYPEDEF base_types -#endif - -#ifndef BOOST_CONTRACT_INVARIANT_FUNC - /** - Define the name of the class invariant member function (@c invariant by - default). - - This macro expands to the name of the @c const and const volatile - member functions that check class invariants and volatile class invariants - respectively. - This macro can be defined if these invariant functions must have a name - different from @c invariant (because of name clashes in user code, etc.). - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} - */ - #define BOOST_CONTRACT_INVARIANT_FUNC invariant -#endif - -#ifndef BOOST_CONTRACT_STATIC_INVARIANT_FUNC - /** - Define the name of the static invariant member function (@c static_invariant - by default). - - This macro expands to the name of the @c static member function that checks - static class invariants. - This macro can be defined if this static invariant function must have a name - different from @c static_invariant (because of name clashes in suer code, - etc.). - - @note C++ does not allow to overload member functions based on the - @c static classifier, so this macro must always be defined to be - different than the function name defined for - @RefMacro{BOOST_CONTRACT_INVARIANT_FUNC}. - - @see @RefSect{tutorial.class_invariants, Class Invariants} - */ - #define BOOST_CONTRACT_STATIC_INVARIANT_FUNC static_invariant -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Disable some compile-time errors generated by this library (undefined by - default). - - Defining this macro disables a number of static checks and related - compile-time errors, for example: - - @li The static invariant member @c BOOST_CONTRACT_STATIC_INVARIANT_FUNC - function must be declared @c static. - @li Non-static invariant member functions @c BOOST_CONTRACT_INVARIANT_FUNC - must be declared either @c const, const volatile, or - volatile const. - @li Derived classes that program contracts for one or more public function - overrides via @RefFunc{boost::contract::public_function} must also - define the @RefMacro{BOOST_CONTRACT_BASE_TYPES} @c typedef. - - In general, it is not recommended to define this macro because these - compile-time checks can guard against missuses of this library. - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{tutorial.base_classes__subcontracting_, Base Classes} - */ - #define BOOST_CONTRACT_PERMISSIVE -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Code block to execute if contracts are not assigned to a - @RefClass{boost::contract::check} variable (undefined by default and - executes @c assert(false)). - - In general, there is a logic error in the program when contracts are not - assigned to a local variable of type @RefClass{boost::contract::check}. - Therefore, by default (i.e., when this macro is not defined) this library - calls assert(false) in those cases. - If this macro is defined, this library will execute the code expanded by the - macro instead of calling @c assert(false) (if programmers prefer to throw an - exception, etc.). - - This macro can be defined to be any block of code (including @c {} to - generate no error), for example (on GCC): - @code - -DBOOST_CONTRACT_ON_MISSING_CHECK_DECL='{ throw std::logic_error("missing contract check declaration"); }' - @endcode - - @see @RefSect{tutorial.non_member_functions, Non-Member Functions} - */ - #define BOOST_CONTRACT_ON_MISSING_CHECK_DECL -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to not disable other assertions while checking - preconditions (undefined by default). - - Not disabling other assertions while checking preconditions can lead to - infinite recursion in user code so by default this macro is not defined. - - However, the @RefSect{bibliography, [1962]} proposal does not disable any - assertion while checking preconditions because arguments can reach the - function body unchecked if assertions are disabled while checking - preconditions (e.g., when these same functions bodies are called to check - the preconditions in question). - This macro can be defined to obtain the behaviour specified in - @RefSect{bibliography, [1962]} (at the risk of infinite recursion). - - @see @RefSect{contract_programming_overview.feature_summary, - Feature Summary} - */ - #define BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to not disable any assertions while checking any other - assertion (undefined by default). - - Not disabling assertions while checking other assertions can lead to - infinite recursion in user code so by default this macro is not defined. - (Defining this macro automatically implies that other assertion checking is - disabled while checking preconditions as if - @RefMacro{BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION} was also - defined.) - - @see @RefSect{contract_programming_overview.feature_summary, - Feature Summary} - */ - #define BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Define this macro to evaluate and check audit assertions at run-time - (undefined by default). - - Audit assertions and implementation checks programmed via - @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT} and - @RefMacro{BOOST_CONTRACT_CHECK_AUDIT} are always compiled and validated - syntactically. - However, they are not evaluated and checked at run-time unless - this macro is defined (because these conditions can be computationally - expensive, at least compared to the cost of executing the function body). - - @see @RefSect{extras.assertion_levels, Assertion Levels} - */ - #define BOOST_CONTRACT_AUDITS -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - If defined, this library does not perform implementation checks (undefined - by default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - implementation checks. - Use @RefMacro{BOOST_CONTRACT_CHECK} to completely disable compilation of - implementation checks when @RefMacro{BOOST_CONTRACT_NO_CHECKS} is defined. - - @see @RefSect{advanced.implementation_checks, - Implementation Checks}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_CHECKS -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - If defined, this library does not check preconditions (undefined by - default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking preconditions. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of preconditions or use the macros - defined in @c boost/contract_macro.hpp (recommended only for applications - where it is truly necessary to completely remove contract code compilation - from production code). - - @see @RefSect{tutorial.preconditions, Preconditions}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_PRECONDITIONS -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - If defined, this library does not check postconditions (undefined by - default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking postconditions. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of postconditions or use the macros - defined in @c boost/contract_macro.hpp (recommended only for applications - where it is truly necessary to completely remove contract code compilation - from production code). - - @see @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_POSTCONDITIONS -#endif - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - If defined, this library does not check exception guarantees (undefined by - default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking exception guarantees. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of exception guarantees or use the - macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - @see @RefSect{tutorial.exception_guarantees, Exception Guarantees}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_EXCEPTS -#endif - -#if defined(BOOST_CONTRACT_DETAIL_DOXYGEN) || \ - ( \ - !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_INVARIANTS) \ - ) - /** - If defined, this library does not check class invariants at entry (undefined - by default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking class invariants at entry. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of entry class invariants or use the - macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - This macro is automatically defined when - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined. - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_ENTRY_INVARIANTS -#endif - -#if defined(BOOST_CONTRACT_DETAIL_DOXYGEN) || \ - ( \ - !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_INVARIANTS) \ - ) - /** - If defined, this library does not check class invariants at exit (undefined - by default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking class invariants at exit. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of exit class invariants or use the - macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - This macro is automatically defined when - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined. - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_EXIT_INVARIANTS -#endif - -#if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) - /** - If defined, this library does not check class invariants (undefined by - default). - - If this macro is defined, this library internal code is also optimized to - reduce compile-time (not just run-time) overhead associated with - checking class invariants. - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of class invariants or use the - macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - Defining this macro is equivalent to defining both - @RefMacro{BOOST_CONTRACT_NO_ENTRY_INVARIANTS} and - @RefMacro{BOOST_CONTRACT_NO_EXIT_INVARIANTS}. - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.disable_contract_checking, - Disable Contract Checking}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_INVARIANTS -#endif - -// Following are NOT configuration macros. - -#ifdef BOOST_CONTRACT_NO_OLDS - #error "define NO_POSTCONDITIONS and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when old value copies are not to be - performed. - - This library will define this macro when users define both - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} and - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of old value copies or use the - macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - @see @RefSect{tutorial.old_values, Old Values}, - @RefSect{advanced.old_copies_at_body, Old Values at Body}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_OLDS -#endif - -// Ctor pre checked separately and outside RAII so not part of this #define. -#ifdef BOOST_CONTRACT_NO_CONSTRUCTORS - #error "define NO_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when contracts are not checked for - constructors. - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of contracts for constructors or use - the macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - @note Constructor preconditions are checked separately by - @RefClass{boost::contract::constructor_precondition} so they are - disabled by @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS} instead. - - @see @RefSect{tutorial.constructors, Constructors}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_CONSTRUCTORS -#endif - -#ifdef BOOST_CONTRACT_NO_DESTRUCTORS - #error "define NO_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when contracts are not checked for - destructors. - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of contracts for destructors or use - the macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - @see @RefSect{tutorial.destructors, Destructors}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_DESTRUCTORS -#endif - -#ifdef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #error "define NO_INVARIANTS, NO_PRECONDITIONS, NO_POSTCONDITIONS, and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when contracts are not checked for - public functions. - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS}, - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of contracts for public functions or - use the macros defined in @c boost/contract_macro.hpp (recommended only for - applications where it is truly necessary to completely remove contract code - compilation from production code). - - @see @RefSect{tutorial.public_functions, Public Functions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS -#endif - -#ifdef BOOST_CONTRACT_NO_FUNCTIONS - #error "define NO_PRECONDITIONS, NO_POSTCONDITIONS, and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when contracts are not checked for - non-member, private and protected functions. - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, and - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of contracts for non-member, - private and protected functions, or use the macros defined in - @c boost/contract_macro.hpp (recommended only for applications where it is - truly necessary to completely remove contract code compilation from - production code). - - This macro is also used when contracts are not checked for private and - protected functions, lambda functions, code blocks, loops, etc. - - @see @RefSect{tutorial.non_member_functions, Non-Member Functions}, - @RefSect{advanced.private_and_protected_functions, - Private and Protected Functions}, - @RefSect{advanced.lambdas__loops__code_blocks__and__constexpr__, - Lambdas\, Loops\, Code Blocks}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_FUNCTIONS -#endif - -#ifdef BOOST_CONTRACT_NO_CONDITIONS - #error "define NO_INVARIANTS, NO_PRECONDITIONS, NO_POSTCONDITIONS, and NO_EXCEPTS instead" -#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) - /** - Automatically defined by this library when contracts are not checked for - preconditions, postconditions, exceptions guarantees, and class invariants - (excluding implementation checks). - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS}, and - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Users can manually program @c \#ifndef statements in their code using this - macro to completely disable compilation of contracts within specifications - or use the macros defined in @c boost/contract_macro.hpp (recommended only - for applications where it is truly necessary to completely remove contract - code compilation from production code). - - @see @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_CONDITIONS -#endif - -#ifdef BOOST_CONTRACT_NO_ALL - #error "define NO_INVARIANTS, NO_PRECONDITIONS, NO_POSTCONDITIONS, NO_EXCEPTS, and NO_CHECKS instead" -#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \ - defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - defined(BOOST_CONTRACT_NO_EXCEPTS) && \ - defined(BOOST_CONTRACT_NO_CHECKS) - /** - Automatically defined by this library when contracts are not checked at all. - - This library will define this macro when users define all - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS}, - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}, - @RefMacro{BOOST_CONTRACT_NO_EXCEPTS}, and - @RefMacro{BOOST_CONTRACT_NO_CHECKS} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - For example, users can manually program @c \#ifndef statements in their code - using this macro to avoid including the @c boost/contract.hpp header all - together: - - @code - #include - #ifndef BOOST_CONTRACT_NO_ALL - #include - #endif - @endcode - - Or, use the @c boost/contract_macro.hpp header and related macros instead - (because the @c boost/contract/_macro.hpp header is already optimized to not - include other headers from this library when contracts are not checked, but - recommended only for applications where it is truly necessary to completely - remove contract code compilation from production code). - - @see @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_NO_ALL -#endif - -#ifdef BOOST_CONTRACT_DYN_LINK - #error "define STATIC_LINK or HEADER_ONLY instead" -#elif defined(BOOST_CONTRACT_DETAIL_DOXYGEN) || \ - defined(BOOST_ALL_DYN_LINK) || \ - ( \ - !defined(BOOST_CONTRACT_STATIC_LINK) && \ - !defined(BOOST_CONTRACT_HEADER_ONLY) \ - ) - /** - Automatically defined when this library is being compiled as a shared - library (defined by default). - - This library will define this macro unless users define - @RefMacro{BOOST_CONTRACT_STATIC_LINK} or - @RefMacro{BOOST_CONTRACT_HEADER_ONLY} (this macro is not a configuration - macro and this library will generate a compile-time error if users try to - define it directly). - Programmers should rarely, if ever, need to use this macro directly. - - @warning In general this library will correctly check contracts at - run-time only when compiled as a shared library (i.e., this - macro will be automatically defined by default), unless user - code checks contracts in a single program unit (e.g., a single - program with only statically linked libraries that check - contracts). - - @see @RefSect{getting_started.install_and_compile, Install and Compile} - */ - #define BOOST_CONTRACT_DYN_LINK -#endif - -#endif // #include guard - diff --git a/include/boost/contract/core/constructor_precondition.hpp b/include/boost/contract/core/constructor_precondition.hpp deleted file mode 100644 index 44703063..00000000 --- a/include/boost/contract/core/constructor_precondition.hpp +++ /dev/null @@ -1,97 +0,0 @@ - -#ifndef BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION_HPP_ -#define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Program preconditions for constructors. -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #include - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - #include - #endif -#endif - -namespace boost { namespace contract { - -/** -Program preconditions for constructors. - -This class must be the very first base of the class declaring the -constructor for which preconditions are programmed (that way constructor -arguments can be checked by preconditions even before they are used to -initialize other base classes). -User-defined classes should inherit privately from this class (to not alter the -public interface of user-defined classes). -In addition, this class should never be declared as a virtual base (because -virtual bases are initialized only once across the entire inheritance hierarchy -preventing preconditions of other base classes from being checked). - -Unions cannot have base classes in C++ so this class can be used to declare a -local object within the constructor definition just before -@RefFunc{boost::contract::constructor} is used (see -@RefSect{extras.unions, Unions}). - -@see @RefSect{tutorial.constructors, Constructors} - -@tparam Class The class type of the constructor for which preconditions are - being programmed. -*/ -template -class constructor_precondition { // Copyable (has no data). -public: - /** - Construct this object without specifying constructor preconditions. - - This is implicitly called for those constructors of the contracted class - that do not specify preconditions. - - @note Calling this default constructor should amount to negligible - compile-time and run-time overheads (likely to be optimized away - completely by most compilers). - */ - constructor_precondition() {} - - /** - Construct this object specifying constructor preconditions. - - @param f Nullary functor called by this library to check constructor - preconditions @c f(). - Assertions within this functor call are usually programmed - using @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown - by a call to this functor indicates a contract failure (and will - result in this library calling - @RefFunc{boost::contract::precondition_failure}). - This functor should capture variables by (constant) value, or - better by (constant) reference to avoid extra copies. - */ - template - explicit constructor_precondition(F const& f) { - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - try { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(boost::contract::detail::checking::already()) return; - #ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION - boost::contract::detail::checking k; - #endif - #endif - f(); - } catch(...) { precondition_failure(from_constructor); } - #endif - } - - // Default copy operations (so user's derived classes can be copied, etc.). -}; - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/core/exception.hpp b/include/boost/contract/core/exception.hpp deleted file mode 100644 index 7fd355e3..00000000 --- a/include/boost/contract/core/exception.hpp +++ /dev/null @@ -1,966 +0,0 @@ - -#ifndef BOOST_CONTRACT_EXCEPTION_HPP_ -#define BOOST_CONTRACT_EXCEPTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Handle contract assertion failures. -*/ - -// IMPORTANT: Included by contract_macro.hpp so trivial headers only. -#include // No compile-time overhead. -#include -#include -#include -#include - -// NOTE: This code should not change (not even its impl) based on the -// CONTRACT_NO_... macros. For example, preconditions_failure() should still -// all the set precondition failure handler even when NO_PRECONDITIONS is -// #defined, because user code might explicitly call precondition_failure() -// (for whatever reason...). Otherwise, the public API of this lib will change. - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN -// Needed for `std::` prefix to show (but removed via `EXCLUDE_SYMBOLS=std`). -namespace std { - class exception {}; - class bad_cast {}; -} -#endif - -namespace boost { namespace contract { - -/** -Public base class for all exceptions directly thrown by this library. - -This class does not inherit from @c std::exception because exceptions deriving -from this class will (inheriting from @c std::exception, @c std::bad_cast, -etc.). - -@see @RefClass{boost::contract::assertion_failure}, - @RefClass{boost::contract::bad_virtual_result_cast}, - etc. -*/ -class BOOST_CONTRACT_DETAIL_DECLSPEC exception { -public: - /** - Destruct this object. - @b Throws: @c noexcept (or @c throw() if no C++11). - */ - virtual ~exception() /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; -}; - -#ifdef BOOST_MSVC - #pragma warning(push) - #pragma warning(disable: 4275) // Bases w/o DLL spec (bad_cast, etc). - #pragma warning(disable: 4251) // Members w/o DLL spec (string for what_). -#endif - -/** -Exception thrown when inconsistent return values are passed to overridden -virtual public functions. - -This exception is internally thrown by this library when programmers specify -return values for public function overrides in derived classes that are not -consistent with the return types of the virtual public functions being -overridden in the base classes. -This allows this library to give more descriptive error messages in such cases. - -@see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} -*/ -class BOOST_CONTRACT_DETAIL_DECLSPEC bad_virtual_result_cast : // Copy (as str). - public std::bad_cast, public boost::contract::exception { -public: - /** - Construct this object with the name of the from- and to- result types. - @param from_type_name Name of the from-type (source of the cast). - @param to_type_name Name of the to-type (destination of the cast). - */ - explicit bad_virtual_result_cast(char const* from_type_name, - char const* to_type_name); - - /** - Destruct this object. - @b Throws: @c noexcept (or @c throw() if no C++11). - */ - virtual ~bad_virtual_result_cast() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; - - /** - Description for this error (containing both from- and to- type names). - @b Throws: @c noexcept (or @c throw() if no C++11). - */ - virtual char const* what() const - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; - -/** @cond */ -private: - std::string what_; -/** @endcond */ -}; - -/** -Exception typically used to report a contract assertion failure. - -This exception is thrown by code expanded by @RefMacro{BOOST_CONTRACT_ASSERT} -(but it can also be thrown by user code programmed manually without that macro). -This exception is typically used to report contract assertion failures because -it contains detailed information about the file name, line number, and source -code of the asserted condition (so it can be used by this library to provide -detailed error messages). -However, any other exception can be used to report a contract assertion failure -(including user-defined exceptions). - -This library will call the appropriate contract failure handler function -(@RefFunc{boost::contract::precondition_failure}, etc.) when this or any other -exception is thrown while checking contracts (by default, these failure handler -functions print an error message to @c std::cerr and terminate the program, but -they can be customized to take any other action). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} -*/ -class BOOST_CONTRACT_DETAIL_DECLSPEC assertion_failure : // Copy (as str, etc.). - public std::exception, public boost::contract::exception { -public: - /** - Construct this object with file name, line number, and source code text of - an assertion condition (all optional). - - This constructor can also be used to specify no information (default - constructor), or to specify only file name and line number but not source - code text (because of the parameter default values). - - @param file Name of the file containing the assertion (usually set using - __FILE__). - @param line Number of the line containing the assertion (usually set using - __LINE__). - @param code Text listing the source code of the assertion condition. - */ - explicit assertion_failure(char const* file = "", unsigned long line = 0, - char const* code = ""); - - /** - Construct this object only with the source code text of the assertion - condition. - @param code Text listing the source code of the assertion condition. - */ - explicit assertion_failure(char const* code); - - /** - Destruct this object. - @b Throws: @c noexcept (or @c throw() if no C++11). - */ - virtual ~assertion_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; - - /** - String describing the failed assertion. - @b Throws: @c noexcept (or @c throw() if no C++11). - @return A string formatted similarly to the following: - assertion "`code()`" failed: file "`file()`", line \`line()\`. - File, line, and code will be omitted from this string if they were - not specified when constructing this object. - */ - virtual char const* what() const - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; - - /** - Name of the file containing the assertion. - @return File name as specified at construction (or @c "" if no file was - specified). - */ - char const* file() const; - - /** - Number of the line containing the assertion. - @return Line number as specified at construction (or @c 0 if no line number - was specified). - */ - unsigned long line() const; - - /** - Text listing the source code of the assertion condition. - @return Assertion condition source code as specified at construction (or - @c "" if no source code text was specified). - */ - char const* code() const; - -/** @cond */ -private: - void init(); - - char const* file_; - unsigned long line_; - char const* code_; - std::string what_; -/** @endcond */ -}; - -#ifdef BOOST_MSVC - #pragma warning(pop) -#endif - -/** -Indicate the kind of operation where the contract assertion failed. - -This is passed as a parameter to the assertion failure handler functions. -For example, it might be necessary to know in which operation an assertion -failed to make sure exceptions are never thrown from destructors, not even -when contract failure handlers are programmed by users to throw exceptions -instead of terminating the program. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure} -*/ -enum from { - /** Assertion failed when checking contracts for constructors. */ - from_constructor, - - /** Assertion failed when checking contracts for destructors . */ - from_destructor, - - /** - Assertion failed when checking contracts for functions (members or not). - */ - from_function -}; - -/** -Type of assertion failure handler functions (with @c from parameter). - -Assertion failure handler functions specified by this type must be functors -returning @c void and taking a single parameter of type -@RefEnum{boost::contract::from}. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure} -*/ -typedef boost::function from_failure_handler; - -/** -Type of assertion failure handler functions (without @c from parameter). - -Assertion failure handler functions specified by this type must be nullary -functors returning @c void. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure} -*/ -typedef boost::function failure_handler; - -/** @cond */ -namespace exception_ { - // Check failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - failure_handler const& - set_check_failure_unlocked(failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - failure_handler const& - set_check_failure_locked(failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC failure_handler get_check_failure_unlocked() - BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC failure_handler get_check_failure_locked() - BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void check_failure_unlocked() - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void check_failure_locked() - /* can throw */; - - // Precondition failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_pre_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_pre_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_pre_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_pre_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void pre_failure_unlocked(from where) - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void pre_failure_locked(from where) - /* can throw */; - - // Postcondition failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_post_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_post_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_post_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_post_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void - post_failure_unlocked(from where) - /* can throw */; - void BOOST_CONTRACT_DETAIL_DECLSPEC post_failure_locked(from where) - /* can throw */; - - // Except failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_except_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_except_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_except_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_except_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void except_failure_unlocked(from where) - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void except_failure_locked(from where) - /* can throw */; - - // Old-copy failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_old_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_old_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_old_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_old_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void old_failure_unlocked(from where) - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void old_failure_locked(from where) - /* can throw */; - - // Entry invariant failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_entry_inv_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_entry_inv_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_entry_inv_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_entry_inv_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void entry_inv_failure_unlocked(from where) - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void entry_inv_failure_locked(from where) - /* can throw */; - - // Exit invariant failure. - - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_exit_inv_failure_unlocked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - BOOST_CONTRACT_DETAIL_DECLSPEC - from_failure_handler const& - set_exit_inv_failure_locked(from_failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW - ; - - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_exit_inv_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW; - BOOST_CONTRACT_DETAIL_DECLSPEC from_failure_handler - get_exit_inv_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW; - - BOOST_CONTRACT_DETAIL_DECLSPEC void exit_inv_failure_unlocked(from where) - /* can throw */; - BOOST_CONTRACT_DETAIL_DECLSPEC void exit_inv_failure_locked(from where) - /* can throw */; - -} -/** @endcond */ - -} } // namespace - -/** @cond */ -#if BOOST_CONTRACT_HEADER_ONLY - // NOTE: This header must be included in the middle of this file (because - // its impl depends on both from and assert_failure types). This is not - // ideal, but it is better than splitting this file into multiple - // independent ones because all content in this file is logically related - // from the user prospective. - #include -#endif -/** @endcond */ - -namespace boost { namespace contract { - -// Following must be inline for static linkage (no DYN_LINK and no HEADER_ONLY). - -/** -Set failure handler for implementation checks. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.implementation_checks, Implementation Checks} -*/ -inline failure_handler const& set_check_failure(failure_handler const& f) - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_check_failure_locked(f); - #else - return exception_::set_check_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for implementation checks. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.implementation_checks, Implementation Checks} -*/ -inline failure_handler get_check_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_check_failure_locked(); - #else - return exception_::get_check_failure_unlocked(); - #endif -} - -/** -Call failure handler for implementation checks. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.implementation_checks, Implementation Checks} -*/ -inline void check_failure() /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::check_failure_locked(); - #else - exception_::check_failure_unlocked(); - #endif -} - -/** -Set failure handler for preconditions. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.preconditions, Preconditions} -*/ -inline from_failure_handler const& set_precondition_failure(from_failure_handler - const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_pre_failure_locked(f); - #else - return exception_::set_pre_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for preconditions. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.preconditions, Preconditions} -*/ -inline from_failure_handler get_precondition_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_pre_failure_locked(); - #else - return exception_::get_pre_failure_unlocked(); - #endif -} - -/** -Call failure handler for preconditions. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@param where Operation that failed the contract assertion (when called by - this library, this parameter will never be @c from_destructor - because destructors never have preconditions). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.preconditions, Preconditions} -*/ -inline void precondition_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::pre_failure_locked(where); - #else - exception_::pre_failure_unlocked(where); - #endif -} - -/** -Set failure handler for postconditions. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., fr - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.postconditions, Postconditions} -*/ -inline from_failure_handler const& set_postcondition_failure( - from_failure_handler const& f -) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_post_failure_locked(f); - #else - return exception_::set_post_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for postconditions. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.postconditions, Postconditions} -*/ -inline from_failure_handler get_postcondition_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_post_failure_locked(); - #else - return exception_::get_post_failure_unlocked(); - #endif -} - -/** -Call failure handler for postconditions. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@param where Operation that failed the contract assertion (e.g., this might - be useful to program failure handler functors that never throw - from destructors, not even when they are programmed by users to - throw exceptions instead of terminating the program). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.postconditions, Postconditions} -*/ -inline void postcondition_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::post_failure_locked(where); - #else - exception_::post_failure_unlocked(where); - #endif -} - -/** -Set failure handler for exception guarantees. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} -*/ -inline from_failure_handler const& set_except_failure(from_failure_handler - const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_except_failure_locked(f); - #else - return exception_::set_except_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for exception guarantees. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} -*/ -inline from_failure_handler get_except_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_except_failure_locked(); - #else - return exception_::get_except_failure_unlocked(); - #endif -} - -/** -Call failure handler for exception guarantees. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default), - however: - -@warning When this failure handler is called there is already an active - exception (the one that caused the exception guarantees to be - checked in the first place). - Therefore, programming this failure handler to throw yet another - exception will force C++ to always terminate the program. - -@param where Operation that failed the contract assertion. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} -*/ -inline void except_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::except_failure_locked(where); - #else - exception_::except_failure_unlocked(where); - #endif -} - -/** -Set failure handler for old value copies at body. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.old_copies_at_body, Old Values at Body} -*/ -inline from_failure_handler const& set_old_failure(from_failure_handler const& - f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_old_failure_locked(f); - #else - return exception_::set_old_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for old value copies at body. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.old_copies_at_body, Old Values at Body} -*/ -inline from_failure_handler get_old_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_old_failure_locked(); - #else - return exception_::get_old_failure_unlocked(); - #endif -} - -/** -Call failure handler for old value copies at body. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@param where Operation that failed the old value copy (e.g., this might - be useful to program failure handler functors that never throw - from destructors, not even when they are programmed by users to - throw exceptions instead of terminating the program). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{advanced.old_copies_at_body, Old Values at Body} -*/ -inline void old_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::old_failure_locked(where); - #else - exception_::old_failure_unlocked(where); - #endif -} - -/** -Set failure handler for class invariants at entry. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline from_failure_handler const& set_entry_invariant_failure( - from_failure_handler const& f -)/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_entry_inv_failure_locked(f); - #else - return exception_::set_entry_inv_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for class invariants at entry. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline from_failure_handler get_entry_invariant_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_entry_inv_failure_locked(); - #else - return exception_::get_entry_inv_failure_unlocked(); - #endif -} - -/** -Call failure handler for class invariants at entry. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@param where Operation that failed the contract assertion (e.g., this might - be useful to program failure handler functors that never throw - from destructors, not even when they are programmed by users to - throw exceptions instead of terminating the program). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline void entry_invariant_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::entry_inv_failure_locked(where); - #else - return exception_::entry_inv_failure_unlocked(where); - #endif -} - -/** -Set failure handler for class invariants at exit. - -Set a new failure handler and returns it. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline from_failure_handler const& set_exit_invariant_failure( - from_failure_handler const& f -) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::set_exit_inv_failure_locked(f); - #else - return exception_::set_exit_inv_failure_unlocked(f); - #endif -} - -/** -Return failure handler currently set for class invariants at exit. - -This is often called only internally by this library. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@return A copy of the failure handler currently set. - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline from_failure_handler get_exit_invariant_failure() - /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return exception_::get_exit_inv_failure_locked(); - #else - return exception_::get_exit_inv_failure_unlocked(); - #endif -} - -/** -Call failure handler for class invariants at exit. - -This is often called only internally by this library. - -@b Throws: This can throw in case programmers specify a failure handler that - throws exceptions on contract assertion failures (not the default). - -@param where Operation that failed the contract assertion (e.g., this might - be useful to program failure handler functors that never throw - from destructors, not even when they are programmed by users to - throw exceptions instead of terminating the program). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline void exit_invariant_failure(from where) /* can throw */ { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - exception_::exit_inv_failure_locked(where); - #else - exception_::exit_inv_failure_unlocked(where); - #endif -} - - -/** -Set failure handler for class invariants (at both entry and exit). - -This is provided for convenience and it is equivalent to call both -@RefFunc{boost::contract::set_entry_invariant_failure} and -@RefFunc{boost::contract::set_exit_invariant_failure} with the same functor -parameter @p f. - -@b Throws: @c noexcept (or @c throw() if no C++11). - -@param f New failure handler functor to set for both entry and exit invariants. - -@return Same failure handler functor @p f passed as parameter (e.g., for - concatenating function calls). - -@see @RefSect{advanced.throw_on_failure__and__noexcept__, Throw on Failure}, - @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.volatile_public_functions, - Volatile Public Functions} -*/ -inline from_failure_handler const& set_invariant_failure(from_failure_handler - const& f) /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */ { - // This must be impl here for header-only linkage (HEADER_ONLY defined). - set_entry_invariant_failure(f); - set_exit_invariant_failure(f); - return f; -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/core/specify.hpp b/include/boost/contract/core/specify.hpp deleted file mode 100644 index f12d77ad..00000000 --- a/include/boost/contract/core/specify.hpp +++ /dev/null @@ -1,632 +0,0 @@ - -#ifndef BOOST_CONTRACT_SPECIFY_HPP_ -#define BOOST_CONTRACT_SPECIFY_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Specify preconditions, old value copies at body, postconditions, and exception -guarantees - -Preconditions, old value copies at body, postconditions, and exception -guarantees are all optionals but, when they are specified, they need to be -specified in that order. -*/ - -#include -#include -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include - #include - #include - #include -#endif -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include -#endif -#include - -// NOTE: No inheritance for faster run-times (macros to avoid duplicated code). - -/* PRIVATE */ - -/* @cond */ - -#if !defined(BOOST_CONTRACT_NO_CONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #define BOOST_CONTRACT_SPECIFY_CLASS_IMPL_(class_type, cond_type) \ - /* data member */ \ - boost::contract::detail::auto_ptr cond_; \ - /* constructor */ \ - explicit class_type(cond_type* cond) : cond_(cond) {} \ - /* copy operations (private to force `auto c = ...` error) */ \ - class_type(class_type const& other) : cond_(other.cond_) {} \ - class_type& operator=(class_type const& other) { \ - cond_ = other.cond_; \ - return *this; \ - } - - #define BOOST_CONTRACT_SPECIFY_COND_RELEASE_ cond_.release() -#else - #define BOOST_CONTRACT_SPECIFY_CLASS_IMPL_(class_type, cond_type) \ - /* (default) constructor */ \ - class_type() {} \ - /* copy operations (decl. private to force `auto c = ...` error) */ \ - class_type(class_type const&) {} \ - class_type& operator=(class_type const&) {} - - #define BOOST_CONTRACT_SPECIFY_COND_RELEASE_ /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #define BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ \ - BOOST_CONTRACT_DETAIL_DEBUG(cond_); \ - cond_->set_pre(f); \ - return specify_old_postcondition_except( \ - BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#else - #define BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ \ - return specify_old_postcondition_except( \ - BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#endif - -#ifndef BOOST_CONTRACT_NO_OLDS - #define BOOST_CONTRACT_SPECIFY_OLD_IMPL_ \ - BOOST_CONTRACT_DETAIL_DEBUG(cond_); \ - cond_->set_old(f); \ - return specify_postcondition_except( \ - BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#else - #define BOOST_CONTRACT_SPECIFY_OLD_IMPL_ \ - return specify_postcondition_except( \ - BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#endif - -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ \ - BOOST_CONTRACT_DETAIL_DEBUG(cond_); \ - cond_->set_post(f); \ - return specify_except(BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#else - #define BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ \ - return specify_except(BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#endif - -#ifndef BOOST_CONTRACT_NO_EXCEPTS - #define BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ \ - BOOST_CONTRACT_DETAIL_DEBUG(cond_); \ - cond_->set_except(f); \ - return specify_nothing(BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#else - #define BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ \ - return specify_nothing(BOOST_CONTRACT_SPECIFY_COND_RELEASE_); -#endif - -/* @endcond */ - -/* CODE */ - -namespace boost { - namespace contract { - class virtual_; - - template - class specify_precondition_old_postcondition_except; - - template - class specify_old_postcondition_except; - - template - class specify_postcondition_except; - - class specify_except; - } -} - -namespace boost { namespace contract { - -/** -Used to prevent setting other contract conditions after exception guarantees. - -This class has no member function so it is used to prevent specifying additional -functors to check any other contract. - -@see @RefSect{tutorial, Tutorial} -*/ -class specify_nothing { // Privately copyable (as *). -public: - /** - Destruct this object. - - @b Throws: This can throw (i.e., @c noexcept(false)) in case programmers - specify failure handlers that throw exceptions instead of - terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~specify_nothing() BOOST_NOEXCEPT_IF(false) {} - - // No set member function here. - -/** @cond */ -private: - BOOST_CONTRACT_SPECIFY_CLASS_IMPL_(specify_nothing, - boost::contract::detail::cond_base) - - // Friends (used to limit library's public API). - - friend class check; - - template - friend class specify_precondition_old_postcondition_except; - - template - friend class specify_old_postcondition_except; - - template - friend class specify_postcondition_except; - - friend class specify_except; -/** @endcond */ -}; - -/** -Allow to specify exception guarantees. - -Allow to specify the functor this library will call to check exception -guarantees. - -@see @RefSect{tutorial.exception_guarantees, Exception Guarantees} -*/ -class specify_except { // Privately copyable (as *). -public: - /** - Destruct this object. - - @b Throws: This can throw (i.e., @c noexcept(false)) in case programmers - specify failure handlers that throw exceptions instead of - terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~specify_except() BOOST_NOEXCEPT_IF(false) {} - - /** - Allow to specify exception guarantees. - - @param f Nullary functor called by this library to check exception - guarantees @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::except_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - - @return After exception guarantees have been specified, this return object - does not allow to specify any additional contract. - */ - template - specify_nothing except(F const& f) { - BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ - } - -/** @cond */ -private: - BOOST_CONTRACT_SPECIFY_CLASS_IMPL_(specify_except, - boost::contract::detail::cond_base) - - // Friends (used to limit library's public API). - - friend class check; - - template - friend class specify_precondition_old_postcondition_except; - - template - friend class specify_old_postcondition_except; - - template - friend class specify_postcondition_except; -/** @endcond */ -}; - -/** -Allow to specify postconditions or exception guarantees. - -Allow to specify functors this library will call to check postconditions or -exception guarantees. - -@see @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} - -@tparam VirtualResult Return type of the enclosing function declaring the - contract if that function is either a virtual public - function or a public function override. - Otherwise, this type is always @c void. -*/ -template -class specify_postcondition_except { // Privately copyable (as *). -public: - /** - Destruct this object. - - @b Throws: This can throw (i.e., @c noexcept(false)) in case programmers - specify failure handlers that throw exceptions instead of - terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~specify_postcondition_except() BOOST_NOEXCEPT_IF(false) {} - - /** - Allow to specify postconditions. - - @param f Functor called by this library to check postconditions - @c f(...). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::postcondition_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - This functor must be a nullary functor if @c VirtualResult is - @c void, otherwise it must be a unary functor accepting the - return value as a parameter of type VirtualResult const& - (to avoid extra copies of the return value, or of type - @c VirtualResult or VirtualResult const if extra copies - of the return value are irrelevant). - - @return After postconditions have been specified, this return object allows - to optionally specify exception guarantees. - */ - template - specify_except postcondition(F const& f) { - BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ - } - - /** - Allow to specify exception guarantees. - - @param f Nullary functor called by this library to check exception - guarantees @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::except_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - - @return After exception guarantees have been specified, this return object - does not allow to specify any additional contract. - */ - template - specify_nothing except(F const& f) { - BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ - } - -/** @cond */ -private: - BOOST_CONTRACT_SPECIFY_CLASS_IMPL_( - specify_postcondition_except, - boost::contract::detail::cond_post::type> - ) - - // Friends (used to limit library's public API). - - friend class check; - friend class specify_precondition_old_postcondition_except; - friend class specify_old_postcondition_except; -/** @endcond */ -}; - -/** -Allow to specify old copies at body, postconditions, or exception guarantees. - -Allow to specify functors this library will call to copy old value at body, -check postconditions, or check exception guarantees. - -@see @RefSect{advanced.old_copies_at_body, Old Copies at Body}, - @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} - -@tparam VirtualResult Return type of the enclosing function declaring the - contract if that function is either a virtual public - function or a public function override. - Otherwise, this type is always @c void. -*/ -template -class specify_old_postcondition_except { // Privately copyable (as *). -public: - /** - Destruct this object. - - @b Throws: This can throw (i.e., @c noexcept(false)) in case programmers - specify failure handlers that throw exceptions instead of - terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~specify_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {} - - /** - Allow to specify old copies at body. - - It should often be sufficient to initialize old value pointers as soon as - they are declared, without using this function (see - @RefSect{advanced.old_copies_at_body, Old Copies at Body}). - - @param f Nullary functor called by this library @c f() to assign old - value copies just before the body is executed but after entry - invariants (when they apply) and preconditions are checked. - Old value pointers within this functor call are usually assigned - using @RefMacro{BOOST_CONTRACT_OLDOF}. - Any exception thrown by a call to this functor will result in - this library calling @RefFunc{boost::contract::old_failure} - (because old values could not be copied to check postconditions - and exception guarantees). - This functor should capture old value pointers by references so - they can be assigned (all other variables needed to evaluate old - value expressions can be captured by (constant) value, or better - by (constant) reference to avoid extra copies). - - @return After old value copies at body have been specified, this return - object allows to optionally specify postconditions and exception - guarantees. - */ - template - specify_postcondition_except old(F const& f) { - BOOST_CONTRACT_SPECIFY_OLD_IMPL_ - } - - /** - Allow to specify postconditions. - - @param f Functor called by this library to check postconditions - @c f(...). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::postcondition_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - This functor must be a nullary functor if @c VirtualResult is - @c void, otherwise it must be a unary functor accepting the - return value as a parameter of type VirtualResult const& - (to avoid extra copies of the return value, or of type - @c VirtualResult or VirtualResult const if extra copies - of the return value are irrelevant). - - @return After postconditions have been specified, this return object allows - to optionally specify exception guarantees. - */ - template - specify_except postcondition(F const& f) { - BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ - } - - /** - Allow to specify exception guarantees. - - @param f Nullary functor called by this library to check exception - guarantees @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::except_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - - @return After exception guarantees have been specified, this return object - does not allow to specify any additional contract. - */ - template - specify_nothing except(F const& f) { - BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ - } - -/** @cond */ -private: - BOOST_CONTRACT_SPECIFY_CLASS_IMPL_( - specify_old_postcondition_except, - boost::contract::detail::cond_post::type> - ) - - // Friends (used to limit library's public API). - - friend class check; - friend class specify_precondition_old_postcondition_except; - - template - friend specify_old_postcondition_except<> constructor(C*); - - template - friend specify_old_postcondition_except<> destructor(C*); -/** @endcond */ -}; - -/** -Allow to specify preconditions, old copies at body, postconditions, and -exception guarantees. - -Allow to specify functors this library will call to check preconditions, copy -old values at body, check postconditions, and check exception guarantees. - -@see @RefSect{tutorial.preconditions, Preconditions}, - @RefSect{advanced.old_copies_at_body, Old Copies at Body}, - @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{tutorial.exception_guarantees, Exception Guarantees} - -@tparam VirtualResult Return type of the enclosing function declaring the - contract if that function is either a virtual public - function or a public function override. - Otherwise, this type is always @c void. -*/ -template< - typename VirtualResult /* = void (already in fwd decl from decl.hpp) */ - #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - = void - #endif -> -class specify_precondition_old_postcondition_except { // Priv. copyable (as *). -public: - /** - Destruct this object. - - @b Throws: This can throw (i.e., @c noexcept(false)) in case programmers - specify failure handlers that throw exceptions instead of - terminating the program (see - @RefSect{advanced.throw_on_failure__and__noexcept__, - Throw on Failure}). - */ - ~specify_precondition_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {} - - /** - Allow to specify preconditions. - - @param f Nullary functor called by this library to check preconditions - @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::precondition_failure}). - This functor should capture variables by (constant) value, or - better by (constant) reference (to avoid extra copies). - - @return After preconditions have been specified, this return object allows - to optionally specify old value copies at body, postconditions, and - exception guarantees. - */ - template - specify_old_postcondition_except precondition(F const& f) { - BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ - } - - /** - Allow to specify old copies at body. - - It should often be sufficient to initialize old value pointers as soon as - they are declared, without using this function (see - @RefSect{advanced.old_copies_at_body, Old Copies at Body}). - - @param f Nullary functor called by this library @c f() to assign old - value copies just before the body is executed but after entry - invariants (when they apply) and preconditions are checked. - Old value pointers within this functor call are usually assigned - using @RefMacro{BOOST_CONTRACT_OLDOF}. - Any exception thrown by a call to this functor will result in - this library calling @RefFunc{boost::contract::old_failure} - (because old values could not be copied to check postconditions - and exception guarantees). - This functor should capture old value pointers by references so - they can be assigned (all other variables needed to evaluate old - value expressions can be captured by (constant) value, or better - by (constant) reference to avoid extra copies). - - @return After old value copies at body have been specified, this return - object allows to optionally specify postconditions and exception - guarantees. - */ - template - specify_postcondition_except old(F const& f) { - BOOST_CONTRACT_SPECIFY_OLD_IMPL_ - } - - /** - Allow to specify postconditions. - - @param f Functor called by this library to check postconditions - @c f(...). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::postcondition_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - This functor must be a nullary functor if @c VirtualResult is - @c void, otherwise it must be a unary functor accepting the - return value as a parameter of type VirtualResult const& - (to avoid extra copies of the return value, or of type - @c VirtualResult or VirtualResult const if extra copies - of the return value are irrelevant). - - @return After postconditions have been specified, this return object allows - to optionally specify exception guarantees. - */ - template - specify_except postcondition(F const& f) { - BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ - } - - /** - Allow to specify exception guarantees. - - @param f Nullary functor called by this library to check exception - guarantees @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a - call to this functor indicates a contract assertion failure (and - will result in this library calling - @RefFunc{boost::contract::except_failure}). - This functor should capture variables by (constant) references - (to access the values they will have at function exit). - - @return After exception guarantees have been specified, this return object - does not allow to specify any additional contract. - */ - template - specify_nothing except(F const& f) { - BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ - } - -/** @cond */ -private: - BOOST_CONTRACT_SPECIFY_CLASS_IMPL_( - specify_precondition_old_postcondition_except, - boost::contract::detail::cond_post::type> - ) - - // Friends (used to limit library's public API). - - friend class check; - friend specify_precondition_old_postcondition_except<> function(); - - template - friend specify_precondition_old_postcondition_except<> public_function(); - - template - friend specify_precondition_old_postcondition_except<> public_function(C*); - - template - friend specify_precondition_old_postcondition_except<> public_function( - virtual_*, C*); - - template - friend specify_precondition_old_postcondition_except public_function( - virtual_*, VR&, C*); - - BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(1, - O, VR, F, C, Args, v, r, f, obj, args) -/** @endcond */ -}; - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/core/virtual.hpp b/include/boost/contract/core/virtual.hpp deleted file mode 100644 index 19e85c7a..00000000 --- a/include/boost/contract/core/virtual.hpp +++ /dev/null @@ -1,161 +0,0 @@ - -#ifndef BOOST_CONTRACT_VIRTUAL_HPP_ -#define BOOST_CONTRACT_VIRTUAL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Handle virtual public functions with contracts (for subcontracting). -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#ifndef BOOST_CONTRACT_NO_CONDITIONS - #include -#endif -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #include -#endif -#ifndef BOOST_CONTRACT_NO_OLDS - #include - #include -#endif - -namespace boost { namespace contract { - -#ifndef BOOST_CONTRACT_NO_CONDITIONS - namespace detail { - BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1, - /* is_friend = */ 0, OO, RR, FF, CC, AArgs); - } -#endif - -/** -Type of extra function parameter to handle contracts for virtual public -functions (for subcontracting). - -Virtual public functions (and therefore also public function overrides) -declaring contracts using this library must specify an extra function parameter -at the very end of the parameter list. -This parameter must be a pointer to this class and it must have default value -@c 0 (i.e., @c nullptr). -(This extra parameter is often named @c v in this documentation, but any name -can be used.) - -In practice this extra parameter does not alter the calling interface of the -enclosing function declaring the contract because it is always the very last -parameter and it has a default value (so it can always be omitted when users -call the function). -This extra parameter must be passed to -@RefFunc{boost::contract::public_function}, @RefMacro{BOOST_CONTRACT_OLDOF}, and -all other operations of this library that accept a pointer to -@RefClass{boost::contract::virtual_}. -A part from that, this class is not intended to be directly used by programmers -(and that is why this class does not have any public member and it is not -copyable). - -@see @RefSect{tutorial.virtual_public_functions, Virtual Public Functions}, - @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} -*/ -class virtual_ { // Non-copyable (see below) to avoid copy queue, stack, etc. -/** @cond */ -private: // No public API (so users cannot use it directly by mistake). - - // No boost::noncopyable to avoid its overhead when contracts disabled. - virtual_(virtual_&); - virtual_& operator=(virtual_&); - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - enum action_enum { - // virtual_ always held/passed as ptr so nullptr used for user call. - no_action, - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - check_entry_inv, - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - check_pre, - #endif - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - check_exit_inv, - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - // For outside .old(...). - push_old_init_copy, - // pop_old_init_copy as static function below. - // For inside .old(...). - call_old_ftor, - push_old_ftor_copy, - pop_old_ftor_copy, - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - check_post, - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - check_except, - #endif - }; - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - // Not just an enum value because the logical combination of two values. - inline static bool pop_old_init_copy(action_enum a) { - return - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - a == check_post - #endif - #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - || - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - a == check_except - #endif - ; - } - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - explicit virtual_(action_enum a) : - action_(a) - , failed_(false) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - , result_type_name_() - , result_optional_() - #endif - {} - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - action_enum action_; - bool failed_; - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - std::queue > old_init_copies_; - std::queue > old_ftor_copies_; - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::any result_ptr_; // Result for virtual and overriding functions. - char const* result_type_name_; - bool result_optional_; - #endif - - // Friends (used to limit library's public API). - #ifndef BOOST_CONTRACT_NO_OLDS - friend bool copy_old(virtual_*); - friend class old_pointer; - #endif - #ifndef BOOST_CONTRACT_NO_CONDITIONS - BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1, - /* is_friend = */ 1, OO, RR, FF, CC, AArgs); - #endif -/** @endcond */ -}; - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/destructor.hpp b/include/boost/contract/destructor.hpp deleted file mode 100644 index 99afdf43..00000000 --- a/include/boost/contract/destructor.hpp +++ /dev/null @@ -1,72 +0,0 @@ - -#ifndef BOOST_CONTRACT_DESTRUCTOR_HPP_ -#define BOOST_CONTRACT_DESTRUCTOR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Program contracts for destructors. -*/ - -#include -#include -#include -#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include -#endif - -namespace boost { namespace contract { - -/** -Program contracts for destructors. - -This is used to specify postconditions, exception guarantees, old value copies -at body, and check class invariants for destructors (destructors cannot not have -preconditions, see -@RefSect{contract_programming_overview, Contract Programming Overview}). - -For optimization, this can be omitted for destructors that do not have -postconditions and exception guarantees, within classes that have no invariants. - -@see @RefSect{tutorial.destructors, Destructors} - -@param obj The object @c this from the scope of the enclosing destructor - declaring the contract. - (Destructors check all class invariants, including static and - volatile invariants, see also @RefSect{tutorial.class_invariants, - Class Invariants} and - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - -@tparam Class The type of the class containing the destructor declaring the - contract. - (Usually this template parameter is automatically deduced by C++ - and it does not need to be explicitly specified by programmers.) - -@return The result of this function must be explicitly assigned to a variable of - type @RefClass{boost::contract::check} declared locally just before the - code of the destructor body (otherwise this library will generate a - run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). -*/ -template -specify_old_postcondition_except<> destructor(Class* obj) { - // Must #if also on ..._PRECONDITIONS here because specify_... is generic. - #if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - return specify_old_postcondition_except<>( - new boost::contract::detail::destructor(obj)); - #else - return specify_old_postcondition_except<>(); - #endif -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/assert.hpp b/include/boost/contract/detail/assert.hpp deleted file mode 100644 index 673ce530..00000000 --- a/include/boost/contract/detail/assert.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_ASSERT_HPP_ -#define BOOST_CONTRACT_DETAIL_ASSERT_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -// In detail because used by both ASSERT and CHECK. -// Use ternary operator `?:` and no trailing `;` here to allow `if(...) ASSERT( -// ...); else ...` (won't compile if expands using an if statement instead even -// if wrapped by {}, and else won't compile if expands trailing `;`). -#define BOOST_CONTRACT_DETAIL_ASSERT(condition) \ - /* no if-statement here */ \ - ((condition) ? \ - BOOST_CONTRACT_DETAIL_NOOP \ - : \ - throw boost::contract::assertion_failure( \ - __FILE__, __LINE__, BOOST_PP_STRINGIZE(condition)) \ - ) /* no ; here */ - -#endif // #include guard - diff --git a/include/boost/contract/detail/auto_ptr.hpp b/include/boost/contract/detail/auto_ptr.hpp deleted file mode 100644 index aac3bad7..00000000 --- a/include/boost/contract/detail/auto_ptr.hpp +++ /dev/null @@ -1,53 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_ -#define BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -namespace boost { namespace contract { namespace detail { - -// Using this instead of std::auto_ptr because std::auto_ptr will be removed in -// C++17 (this library always uses release() to avoid ownership issues). -template -class auto_ptr { // Copyable (using default copy operations). -public: - explicit auto_ptr(T* ptr = 0) : ptr_(ptr) {} - - ~auto_ptr() BOOST_NOEXCEPT_IF(false) { delete ptr_; } - - T* release() { - T* ptr = ptr_; - ptr_ = 0; - return ptr; - } - - T& operator*() { - BOOST_CONTRACT_DETAIL_DEBUG(ptr_); - return *ptr_; - } - - T const& operator*() const { - BOOST_CONTRACT_DETAIL_DEBUG(ptr_); - return *ptr_; - } - - T* operator->() { return ptr_; } - T const* operator->() const { return ptr_; } - - BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(auto_ptr, !!ptr_) - -private: - T* ptr_; -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/check.hpp b/include/boost/contract/detail/check.hpp deleted file mode 100644 index 0dcb826c..00000000 --- a/include/boost/contract/detail/check.hpp +++ /dev/null @@ -1,48 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_CHECK_HPP_ -#define BOOST_CONTRACT_DETAIL_CHECK_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#ifndef BOOST_CONTRACT_NO_CHECKS - #include - - /* PRIVATE */ - - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - #include - #include - - #define BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ \ - if(!boost::contract::detail::checking::already()) - #define BOOST_CONTRACT_CHECK_CHECKING_VAR_(guard) \ - /* this name somewhat unique to min var shadow warnings */ \ - boost::contract::detail::checking BOOST_CONTRACT_DETAIL_NAME2( \ - guard, __LINE__); - #else - #define BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ /* nothing */ - #define BOOST_CONTRACT_CHECK_CHECKING_VAR_(guard) /* nothing */ - #endif - - /* PUBLIC */ - - #define BOOST_CONTRACT_DETAIL_CHECK(assertion) \ - { \ - try { \ - BOOST_CONTRACT_CHECK_IF_NOT_CHECKING_ALREADY_ \ - { \ - BOOST_CONTRACT_CHECK_CHECKING_VAR_(k) \ - { assertion; } \ - } \ - } catch(...) { boost::contract::check_failure(); } \ - } -#else - #define BOOST_CONTRACT_DETAIL_CHECK(assertion) {} -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/checking.hpp b/include/boost/contract/detail/checking.hpp deleted file mode 100644 index c436505f..00000000 --- a/include/boost/contract/detail/checking.hpp +++ /dev/null @@ -1,76 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_CHECKING_HPP_ -#define BOOST_CONTRACT_DETAIL_CHECKING_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include - -namespace boost { namespace contract { namespace detail { - -#ifdef BOOST_MSVC - #pragma warning(push) - #pragma warning(disable: 4251) // Member w/o DLL spec (mutex_ type). -#endif - -// RAII facility to disable assertions while checking other assertions. -class BOOST_CONTRACT_DETAIL_DECLSPEC checking : - private boost::noncopyable // Non-copyable resource (might use mutex, etc.). -{ -public: - explicit checking() { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - init_locked(); - #else - init_unlocked(); - #endif - } - - ~checking() { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - done_locked(); - #else - done_unlocked(); - #endif - } - - static bool already() { - #ifndef BOOST_CONTRACT_DISABLE_THREADS - return already_locked(); - #else - return already_unlocked(); - #endif - } - -private: - void init_unlocked(); - void init_locked(); - - void done_unlocked(); - void done_locked(); - - static bool already_unlocked(); - static bool already_locked(); - - static boost::mutex mutex_; - static bool checking_; -}; - -#ifdef BOOST_MSVC - #pragma warning(pop) -#endif - -} } } // namespace - -#if BOOST_CONTRACT_HEADER_ONLY - #include -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/condition/cond_base.hpp b/include/boost/contract/detail/condition/cond_base.hpp deleted file mode 100644 index b55afb95..00000000 --- a/include/boost/contract/detail/condition/cond_base.hpp +++ /dev/null @@ -1,153 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_COND_BASE_HPP_ -#define BOOST_CONTRACT_DETAIL_COND_BASE_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// NOTE: It seemed not possible to implement this library without inheritance -// here because some sort of base type needs to be used to hold contract objects -// in instances of boost::contract::check while polymorphically calling -// init and destructor functions to check contracts at entry and exit. This -// could be possible without inheritance only if boost::contract::check was made -// a template type but that would complicate user code. In any case, early -// experimentation with removing this base class and its virtual methods did not -// seem to reduce compilation and/or run time. - -#include -#include -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_OLDS) || \ - !defined(BOOST_CONTRACT_NO_EXEPTS) - #include -#endif -#include -#include -#ifndef BOOST_CONTRACT_ON_MISSING_CHECK_DECL - #include -#endif - -namespace boost { namespace contract { namespace detail { - -class cond_base : // Base to hold all contract objects for RAII. - private boost::noncopyable // Avoid copying possible user's ftor captures. -{ -public: - explicit cond_base(boost::contract::from from) : - BOOST_CONTRACT_ERROR_missing_check_object_declaration(false) - , init_asserted_(false) - #ifndef BOOST_CONTRACT_NO_CONDITIONS - , from_(from) - , failed_(false) - #endif - {} - - // Can override for checking on exit, but should call assert_initialized(). - virtual ~cond_base() BOOST_NOEXCEPT_IF(false) { - // Catch error (but later) even if overrides miss assert_initialized(). - if(!init_asserted_) assert_initialized(); - } - - void initialize() { // Must be called by owner ctor (i.e., check class). - BOOST_CONTRACT_ERROR_missing_check_object_declaration = true; - this->init(); // So all inits (pre, old, post) done after owner decl. - } - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - template - void set_pre(F const& f) { pre_ = f; } - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - template - void set_old(F const& f) { old_ = f; } - #endif - - #ifndef BOOST_CONTRACT_NO_EXCEPTS - template - void set_except(F const& f) { except_ = f; } - #endif - -protected: - void assert_initialized() { // Derived dtors must assert this at entry. - init_asserted_ = true; - #ifdef BOOST_CONTRACT_ON_MISSING_CHECK_DECL - if(!BOOST_CONTRACT_ERROR_missing_check_object_declaration) { - BOOST_CONTRACT_ON_MISSING_CHECK_DECL; - } - #else - // Cannot use a macro instead of this ERROR_... directly here - // because assert will not expand it in the error message. - assert(BOOST_CONTRACT_ERROR_missing_check_object_declaration); - #endif - } - - virtual void init() {} // Override for checking on entry. - - // Return true if actually checked calling user ftor. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - bool check_pre(bool throw_on_failure = false) { - if(failed()) return true; - try { if(pre_) pre_(); else return false; } - catch(...) { - // Subcontracted pre must throw on failure (instead of - // calling failure handler) so to be checked in logic-or. - if(throw_on_failure) throw; - fail(&boost::contract::precondition_failure); - } - return true; - } - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - void copy_old() { - if(failed()) return; - try { if(old_) old_(); } - catch(...) { fail(&boost::contract::old_failure); } - } - #endif - - #ifndef BOOST_CONTRACT_NO_EXCEPTS - void check_except() { - if(failed()) return; - try { if(except_) except_(); } - catch(...) { fail(&boost::contract::except_failure); } - } - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - void fail(void (*h)(boost::contract::from)) { - failed(true); - if(h) h(from_); - } - - // Virtual so overriding pub func can use virtual_::failed_ instead. - virtual bool failed() const { return failed_; } - virtual void failed(bool value) { failed_ = value; } - #endif - -private: - bool BOOST_CONTRACT_ERROR_missing_check_object_declaration; - bool init_asserted_; // Avoid throwing twice from dtors (undef behavior). - #ifndef BOOST_CONTRACT_NO_CONDITIONS - boost::contract::from from_; - bool failed_; - #endif - // Following use Boost.Function to handle also lambdas, binds, etc. - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - boost::function pre_; - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - boost::function old_; - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - boost::function except_; - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/condition/cond_inv.hpp b/include/boost/contract/detail/condition/cond_inv.hpp deleted file mode 100644 index c22b4bfd..00000000 --- a/include/boost/contract/detail/condition/cond_inv.hpp +++ /dev/null @@ -1,232 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_COND_INV_HPP_ -#define BOOST_CONTRACT_DETAIL_COND_INV_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#ifndef BOOST_CONTRACT_NO_INVARIANTS - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #ifndef BOOST_CONTRACT_PERMISSIVE - #include - #include - #endif -#endif - -namespace boost { namespace contract { namespace detail { - -template -class cond_inv : public cond_post { // Non-copyable base. - #if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \ - !defined(BOOST_CONTRACT_PERMISSIVE) - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f< - C, void, boost::mpl:: vector<> - >::value, - "static invariant member function cannot be mutable " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f< - C, void, boost::mpl::vector<>, - boost::function_types::const_non_volatile - >::value, - "static invariant member function cannot be const qualified " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f< - C, void, boost::mpl::vector<>, - boost::function_types::volatile_non_const - >::value, - "static invariant member function cannot be volatile qualified " - "(it must be static instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_static_invariant_f< - C, void, boost::mpl::vector<>, - boost::function_types::cv_qualified - >::value, - "static invariant member function cannot be const volatile " - "qualified (it must be static instead)" - ); - - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_s< - C, void, boost::mpl::vector<> - >::value, - "non-static invariant member function cannot be static " - "(it must be either const or const volatile qualified instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_f< - C, void, boost::mpl::vector<>, - boost::function_types::non_cv - >::value, - "non-static invariant member function cannot be mutable " - "(it must be either const or const volatile qualified instead)" - ); - BOOST_STATIC_ASSERT_MSG( - !boost::contract::access::has_invariant_f< - C, void, boost::mpl::vector<>, - boost::function_types::volatile_non_const - >::value, - "non-static invariant member function cannot be volatile qualified " - "(it must be const or const volatile qualified instead)" - ); - #endif - -public: - // obj can be 0 for static member functions. - explicit cond_inv(boost::contract::from from, C* obj) : - cond_post(from) - #ifndef BOOST_CONTRACT_NO_CONDITIONS - , obj_(obj) - #endif - {} - -protected: - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - void check_entry_inv() { check_inv(true, false, false); } - void check_entry_static_inv() { check_inv(true, true, false); } - void check_entry_all_inv() { check_inv(true, false, true); } - #endif - - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - void check_exit_inv() { check_inv(false, false, false); } - void check_exit_static_inv() { check_inv(false, true, false); } - void check_exit_all_inv() { check_inv(false, false, true); } - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - C* object() { return obj_; } - #endif - -private: - #ifndef BOOST_CONTRACT_NO_INVARIANTS - // Static, cv, and const inv in that order as strongest qualifier first. - void check_inv(bool on_entry, bool static_only, bool const_and_cv) { - if(this->failed()) return; - try { - // Static members only check static inv. - check_static_inv(); - if(!static_only) { - if(const_and_cv) { - check_cv_inv(); - check_const_inv(); - } else if(boost::is_volatile::value) { - check_cv_inv(); - } else { - check_const_inv(); - } - } - } catch(...) { - if(on_entry) { - this->fail(&boost::contract::entry_invariant_failure); - } else this->fail(&boost::contract::exit_invariant_failure); - } - } - - template - typename boost::disable_if< - boost::contract::access::has_const_invariant >::type - check_const_inv() {} - - template - typename boost::enable_if< - boost::contract::access::has_const_invariant >::type - check_const_inv() { boost::contract::access::const_invariant(obj_); } - - template - typename boost::disable_if< - boost::contract::access::has_cv_invariant >::type - check_cv_inv() {} - - template - typename boost::enable_if< - boost::contract::access::has_cv_invariant >::type - check_cv_inv() { boost::contract::access::cv_invariant(obj_); } - - template - typename boost::disable_if< - boost::contract::access::has_static_invariant >::type - check_static_inv() {} - - template - typename boost::enable_if< - boost::contract::access::has_static_invariant >::type - check_static_inv() { - // SFINAE HAS_STATIC_... returns true even when member is inherited - // so extra run-time check here (not the same for non static). - if(!inherited::apply()) { - boost::contract::access::static_invariant(); - } - } - - // Check if class's func is inherited from its base types or not. - template class HasFunc, template class FuncAddr> - struct inherited { - static bool apply() { - try { - boost::mpl::for_each< - // For now, no reason to deeply search inheritance tree - // (SFINAE HAS_STATIC_... already fails in that case). - typename boost::mpl::transform< - typename boost::mpl::copy_if< - typename boost::mpl::eval_if, - typename boost::contract::access:: - base_types_of - , - boost::mpl::vector<> - >::type, - HasFunc - >::type, - boost::add_pointer - >::type - >(compare_func_addr()); - } catch(signal_equal const&) { return true; } - return false; - } - - private: - class signal_equal {}; // Except. to stop for_each as soon as found. - - struct compare_func_addr { - template - void operator()(B*) { - // Inherited func has same addr as in its base. - if(FuncAddr::apply() == FuncAddr::apply()) { - throw signal_equal(); - } - } - }; - }; - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - C* obj_; - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/condition/cond_post.hpp b/include/boost/contract/detail/condition/cond_post.hpp deleted file mode 100644 index b8364c42..00000000 --- a/include/boost/contract/detail/condition/cond_post.hpp +++ /dev/null @@ -1,88 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_COND_POST_HPP_ -#define BOOST_CONTRACT_DETAIL_COND_POST_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #include - #include - #include - #include - #include -#endif - -/* PRIVATE */ - -#define BOOST_CONTRACT_DETAIL_COND_POST_DEF_( \ - result_type, result_param, ftor_type, ftor_var, ftor_call) \ - public: \ - template \ - void set_post(F const& f) { ftor_var = f; } \ - \ - protected: \ - void check_post(result_type const& result_param) { \ - if(failed()) return; \ - try { if(ftor_var) { ftor_call; } } \ - catch(...) { fail(&boost::contract::postcondition_failure); } \ - } \ - \ - private: \ - boost::function ftor_var; /* Boost.Func for lambdas, etc. */ - -/* CODE */ - -namespace boost { namespace contract { namespace detail { - -template -class cond_post : public cond_base { // Non-copyable base. -public: - explicit cond_post(boost::contract::from from) : cond_base(from) {} - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - private: typedef typename boost::mpl::if_, - boost::optional::type>::type const&> const& - , - VR const& - >::type r_type; - - BOOST_CONTRACT_DETAIL_COND_POST_DEF_( - r_type, - r, - void (r_type), - // Won't raise this error if NO_POST (for optimization). - BOOST_CONTRACT_ERROR_postcondition_result_parameter_required, - BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r) - ) - #endif -}; - -template<> -class cond_post : public cond_base { // Non-copyable base. -public: - explicit cond_post(boost::contract::from from) : cond_base(from) {} - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - BOOST_CONTRACT_DETAIL_COND_POST_DEF_( - none, - unused, - void (), - // Won't raise this error if NO_POST (for optimization). - BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed, - BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed() - ) - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/condition/cond_subcontracting.hpp b/include/boost/contract/detail/condition/cond_subcontracting.hpp deleted file mode 100644 index 14200538..00000000 --- a/include/boost/contract/detail/condition/cond_subcontracting.hpp +++ /dev/null @@ -1,472 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_COND_SUBCONTRACTING_HPP_ -#define BOOST_CONTRACT_DETAIL_COND_SUBCONTRACTING_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include -#endif -#include -#include -#include -#ifndef BOOST_CONTRACT_NO_CONDITIONS - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #ifndef BOOST_CONTRACT_PERMISSIVE - #include - #include - #include - #include - #endif - #include - #include -#endif -#include -#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include -#endif -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #include - #include -#endif -#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOSOT_CONTRACT_NO_EXCEPTS) - #include - #include - #include - #include - #include -#endif - -namespace boost { namespace contract { namespace detail { - -namespace cond_subcontracting_ { - // Exception signals (must not inherit). - class signal_no_error {}; - class signal_not_checked {}; -} - -// O, VR, F, and Args-i can be none types (but C cannot). -BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z(1, - /* is_friend = */ 0, O, VR, F, C, Args) : public cond_inv -{ // Non-copyable base. - #ifndef BOOST_CONTRACT_NO_CONDITIONS - template > - class overridden_bases_of { - struct search_bases { - typedef typename boost::mpl::fold< - typename boost::contract::access::base_types_of:: - type, - Result, - // Fold: _1 = result, _2 = current base from base_types. - boost::mpl::eval_if >, - boost::mpl::_1 // Base in result, do not add it again. - , - boost::mpl::eval_if< - typename O::template BOOST_CONTRACT_DETAIL_NAME1( - has_member_function)< - boost::mpl::_2, - typename member_function_types:: - result_type, - typename member_function_types:: - virtual_argument_types, - typename member_function_types:: - property_tag - > - , - boost::mpl::push_back< - overridden_bases_of, - // Bases as * since for_each constructs them. - boost::add_pointer - > - , - overridden_bases_of - > - > - >::type type; - }; - public: - typedef typename boost::mpl::eval_if< - boost::contract::access::has_base_types, - search_bases - , - boost::mpl::identity // Return result (stop recursion). - >::type type; - }; - - typedef typename boost::mpl::eval_if, - boost::mpl::vector<> - , - overridden_bases_of - >::type overridden_bases; - - #ifndef BOOST_CONTRACT_PERMISSIVE - BOOST_STATIC_ASSERT_MSG( - boost::mpl::or_< - boost::is_same, - boost::mpl::not_ > - >::value, - "subcontracting function specified as 'override' but does not " - "override any contracted member function" - ); - #endif - #else - typedef boost::mpl::vector<> overridden_bases; - #endif - -public: - explicit cond_subcontracting( - boost::contract::from from, - boost::contract::virtual_* v, - C* obj, - VR& r - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1, - BOOST_CONTRACT_MAX_ARGS, Args, &, args) - ) : - cond_inv(from, obj) - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - , r_(r) - #endif - #ifndef BOOST_CONTRACT_NO_CONDITIONS - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(1, - BOOST_CONTRACT_MAX_ARGS, args_, args) - #endif - { - #ifndef BOOST_CONTRACT_NO_CONDITIONS - if(v) { - base_call_ = true; - v_ = v; // Invariant: v_ never null if base_call_. - BOOST_CONTRACT_DETAIL_DEBUG(v_); - } else { - base_call_ = false; - if(!boost::mpl::empty::value) { - v_ = new boost::contract::virtual_( - boost::contract::virtual_::no_action); - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - v_->result_ptr_ = &r_; - v_->result_type_name_ = typeid(VR).name(); - v_->result_optional_ = is_optional::value; - #endif - } else v_ = 0; - } - #endif - } - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - virtual ~cond_subcontracting() BOOST_NOEXCEPT_IF(false) { - if(!base_call_) delete v_; - } - #endif - -protected: - #ifndef BOOST_CONTRACT_NO_OLDS - void init_subcontracted_old() { - // Old values of overloaded func on stack (so no `f` param here). - exec_and(boost::contract::virtual_::push_old_init_copy); - } - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - void check_subcontracted_entry_inv() { - exec_and(boost::contract::virtual_::check_entry_inv, - &cond_subcontracting::check_entry_inv); - } - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - void check_subcontracted_pre() { - exec_or( - boost::contract::virtual_::check_pre, - &cond_subcontracting::check_pre, - &boost::contract::precondition_failure - ); - } - #endif - - #ifndef BOOST_CONTRACT_NO_OLDS - void copy_subcontracted_old() { - exec_and(boost::contract::virtual_::call_old_ftor, - &cond_subcontracting::copy_virtual_old); - } - #endif - - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - void check_subcontracted_exit_inv() { - exec_and(boost::contract::virtual_::check_exit_inv, - &cond_subcontracting::check_exit_inv); - } - #endif - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - void check_subcontracted_post() { - exec_and(boost::contract::virtual_::check_post, - &cond_subcontracting::check_virtual_post); - } - #endif - - #ifndef BOOST_CONTRACT_NO_EXCEPTS - void check_subcontracted_except() { - exec_and(boost::contract::virtual_::check_except, - &cond_subcontracting::check_virtual_except); - } - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - bool base_call() const { return base_call_; } - - bool failed() const /* override */ { - if(v_) return v_->failed_; - else return cond_base::failed(); - } - - void failed(bool value) /* override */ { - if(v_) v_->failed_ = value; - else cond_base::failed(value); - } - #endif - -private: - #ifndef BOOST_CONTRACT_NO_OLDS - void copy_virtual_old() { - boost::contract::virtual_::action_enum a; - if(base_call_) { - a = v_->action_; - v_->action_ = boost::contract::virtual_::push_old_ftor_copy; - } - this->copy_old(); - if(base_call_) v_->action_ = a; - } - - void pop_base_old() { - if(base_call_) { - boost::contract::virtual_::action_enum a = v_->action_; - v_->action_ = boost::contract::virtual_::pop_old_ftor_copy; - this->copy_old(); - v_->action_ = a; - } // Else, do nothing (for base calls only). - } - #endif - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - void check_virtual_post() { - pop_base_old(); - typedef typename boost::remove_reference::type>::type r_type; - boost::optional r; // No result copy in this code. - if(!base_call_) r = optional_get(r_); - else if(v_->result_optional_) { - try { - r = **boost::any_cast*>( - v_->result_ptr_); - } catch(boost::bad_any_cast const&) { - try { // Handle optional<...&>. - r = **boost::any_cast*>( - v_->result_ptr_); - } catch(boost::bad_any_cast const&) { - try { - throw boost::contract::bad_virtual_result_cast(v_-> - result_type_name_, typeid(r_type).name()); - } catch(...) { - this->fail(&boost::contract::postcondition_failure); - } - } - } - } else { - try { - r = *boost::any_cast(v_->result_ptr_); - } catch(boost::bad_any_cast const&) { - try { - throw boost::contract::bad_virtual_result_cast( - v_->result_type_name_, typeid(r_type).name()); - } catch(...) { - this->fail(&boost::contract::postcondition_failure); - } - } - } - check_virtual_post_with_result(r); - } - - template - typename boost::enable_if >::type - check_virtual_post_with_result(Result const& r) { - this->check_post(r); - } - - template - typename boost::disable_if >::type - check_virtual_post_with_result(Result const& r) { - BOOST_CONTRACT_DETAIL_DEBUG(r); - this->check_post(*r); - } - #endif - - #ifndef BOOST_CONTRACT_NO_EXCEPTS - void check_virtual_except() { - pop_base_old(); - this->check_except(); - } - #endif - - #if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - void exec_and( // Execute action in short-circuit logic-and with bases. - boost::contract::virtual_::action_enum a, - void (cond_subcontracting::* f)() = 0 - ) { - if(failed()) return; - if(!base_call_ || v_->action_ == a) { - if(!base_call_ && v_) { - v_->action_ = a; - boost::mpl::for_each(call_base(*this)); - } - if(f) (this->*f)(); - if(base_call_) { - throw cond_subcontracting_::signal_no_error(); - } - } - } - #endif - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - void exec_or( // Execute action in short-circuit logic-or with bases. - boost::contract::virtual_::action_enum a, - bool (cond_subcontracting::* f)(bool) = 0, - void (*h)(boost::contract::from) = 0 - ) { - if(failed()) return; - if(!base_call_ || v_->action_ == a) { - if(!base_call_ && v_) { - v_->action_ = a; - try { - exec_or_bases(); - return; // A base checked with no error (done). - } catch(...) { - bool checked = f ? (this->*f)( - /* throw_on_failure = */ false) : false; - if(!checked) { - try { throw; } // Report latest exception found. - catch(...) { this->fail(h); } - } - return; // Checked and no exception (done). - } - } - bool checked = f ? - (this->*f)(/* throw_on_failure = */ base_call_) : false; - if(base_call_) { - if(!checked) { - throw cond_subcontracting_::signal_not_checked(); - } - throw cond_subcontracting_::signal_no_error(); - } - } - } - - template - typename boost::enable_if, bool>::type - exec_or_bases() { return false; } - - template - typename boost::disable_if, bool>::type - exec_or_bases() { - if(boost::mpl::empty::value) return false; - try { - call_base(*this)(typename boost::mpl::front::type()); - } catch(cond_subcontracting_::signal_not_checked const&) { - return exec_or_bases< - typename boost::mpl::pop_front::type>(); - } catch(...) { - bool checked = false; - try { - checked = exec_or_bases< - typename boost::mpl::pop_front::type>(); - } catch(...) { checked = false; } - if(!checked) throw; - } - return true; - } - #endif - - #ifndef BOOST_CONTRACT_NO_CONDITIONS - class call_base { // Copyable (as &). - public: - explicit call_base(cond_subcontracting& me) : me_(me) {} - - template - void operator()(B*) { - BOOST_CONTRACT_DETAIL_DEBUG(me_.object()); - BOOST_CONTRACT_DETAIL_DEBUG(me_.v_); - BOOST_CONTRACT_DETAIL_DEBUG(me_.v_->action_ != - boost::contract::virtual_::no_action); - try { - call(BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF( - Args)); - } catch(cond_subcontracting_::signal_no_error const&) { - // No error (do not throw). - } - } - - private: - template< - class B - // Can't use TVARIADIC_COMMA here. - BOOST_PP_COMMA_IF(BOOST_CONTRACT_DETAIL_TVARIADIC) - BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(I) - > - void call( - BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(I)) { - O::template BOOST_CONTRACT_DETAIL_NAME1(call_base)( - me_.v_, - me_.object() - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA( - BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z(1, - BOOST_CONTRACT_MAX_ARGS, I, me_.args_) - ); - } - - cond_subcontracting& me_; - }; - #endif - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - VR& r_; - #endif - #ifndef BOOST_CONTRACT_NO_CONDITIONS - boost::contract::virtual_* v_; - bool base_call_; - BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z(1, - BOOST_CONTRACT_MAX_ARGS, Args, &, args_) - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/config.hpp b/include/boost/contract/detail/config.hpp deleted file mode 100644 index 31634996..00000000 --- a/include/boost/contract/detail/config.hpp +++ /dev/null @@ -1,29 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_CONFIG_HPP_ -#define BOOST_CONTRACT_DETAIL_CONFIG_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include - -// Export symbols when compiling as shared lib (for internal use only). -// BOOST_CONTRACT_DETAIL_SOURCE - -// Turn off assert(...) in lib's implementation. -// BOOST_CONTRACT_DETAIL_NDEBUG - -#ifndef BOOST_CONTRACT_DETAIL_NAME_INFIX - // Do not use underscore "_" to avoid generating reserved names with "__". - #define BOOST_CONTRACT_DETAIL_NAME_INFIX X -#endif - -#ifndef BOOST_CONTRACT_DETAIL_NAME_PREFIX - #define BOOST_CONTRACT_DETAIL_NAME_PREFIX \ - BOOST_PP_CAT(boost_contract_detail, BOOST_CONTRACT_DETAIL_NAME_INFIX) -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/debug.hpp b/include/boost/contract/detail/debug.hpp deleted file mode 100644 index 62154030..00000000 --- a/include/boost/contract/detail/debug.hpp +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_DEBUG_HPP_ -#define BOOST_CONTRACT_DETAIL_DEBUG_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Usually, never #defined (so "debug" assertions always in code). -#ifdef BOOST_CONTRACT_DETAIL_NDEBUG - #define BOOST_CONTRACT_DETAIL_DEBUG(cond) /* nothing */ -#else - #include - // Extra parenthesis around assert because that is also a macro. - #define BOOST_CONTRACT_DETAIL_DEBUG(cond) (assert(cond)) -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/decl.hpp b/include/boost/contract/detail/decl.hpp deleted file mode 100644 index c918db9c..00000000 --- a/include/boost/contract/detail/decl.hpp +++ /dev/null @@ -1,129 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_DECL_HPP_ -#define BOOST_CONTRACT_DETAIL_DECL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Cannot include core/*.hpp other than config.hpp here (avoid circular incl). -#include -#if !BOOST_CONTRACT_DETAIL_TVARIADIC - #include - #include - #include - #include -#endif -#include -#include -#include - -/* PUBLIC */ - -#define BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \ - arity, is_friend, has_result, \ - O, VR, F, C, Args, \ - v, r, f, obj, args \ -) \ - template< \ - class O \ - BOOST_PP_COMMA_IF(has_result) \ - BOOST_PP_EXPR_IIF(has_result, typename VR) \ - , typename F \ - , class C \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, Args) \ - > \ - BOOST_PP_EXPR_IIF(is_friend, friend) \ - boost::contract::specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_result, VR)> \ - /* no boost::contract:: here for friends (otherwise need fwd decl) */ \ - public_function( \ - boost::contract::virtual_* v \ - BOOST_PP_COMMA_IF(has_result) \ - BOOST_PP_EXPR_IIF(has_result, VR& r) \ - , F f \ - , C* obj \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(z, arity, Args, &, args) \ - ) - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(z, \ - O, VR, F, C, Args, \ - v, r, f, obj, args \ - ) \ - BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \ - ~, /* is_friend = */ 1, /* has_result = */ 0, \ - O, VR, F, C, Args, v, r, f, obj, args \ - ); \ - BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \ - ~, /* is_friend = */ 1, /* has_result = */ 1, \ - O, VR, F, C, Args, v, r, f, obj, args \ - ); -#else - /* PRIVATE */ - #define BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTION_( \ - z, n, result_O_R_F_C_Args_v_r_f_obj_args) \ - BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \ - /* arity = */ n, \ - /* is_friend = */ 1, \ - BOOST_PP_TUPLE_ELEM(11, 0, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 1, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 2, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 3, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 4, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 5, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 6, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 7, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 8, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 9, result_O_R_F_C_Args_v_r_f_obj_args), \ - BOOST_PP_TUPLE_ELEM(11, 10, result_O_R_F_C_Args_v_r_f_obj_args) \ - ); - - /* PUBLIC */ - #define BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(z, \ - O, VR, F, C, Args, \ - v, r, f, obj, args \ - ) \ - BOOST_PP_REPEAT_ ## z( \ - BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \ - BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTION_, \ - (/* has_result = */ 0, O, VR, F, C, Args, v, r, f, obj, args) \ - ) \ - BOOST_PP_REPEAT_ ## z( \ - BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \ - BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTION_, \ - (/* has_result = */ 1, O, VR, F, C, Args, v, r, f, obj, args) \ - ) -#endif - -#define BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_SUBCONTRACTING_Z( \ - z, is_friend, O, VR, F, C, Args) \ - template< \ - class O, typename VR, typename F, class C \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, \ - BOOST_CONTRACT_MAX_ARGS, Args) \ - > \ - BOOST_PP_IIF(is_friend, \ - friend class boost::contract::detail:: \ - , \ - class \ - ) \ - cond_subcontracting - -/* CODE */ - -namespace boost { - namespace contract { - class virtual_; - - template - class specify_precondition_old_postcondition_except; - } -} - -#endif // #include guard - diff --git a/include/boost/contract/detail/declspec.hpp b/include/boost/contract/detail/declspec.hpp deleted file mode 100644 index 9264c4b7..00000000 --- a/include/boost/contract/detail/declspec.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_DECLSPEC_HPP_ -#define BOOST_CONTRACT_DETAIL_DECLSPEC_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// IMPORTANT: Indirectly included by contract_macro.hpp so trivial headers only. -#include // No compile-time overhead. -#include - -/* PUBLIC */ - -// IMPORTANT: In general, this library should always and only be compiled and -// used as a shared library. Otherwise, lib's state won't be shared among -// different user programs and user libraries. -#ifdef BOOST_CONTRACT_DYN_LINK - #ifdef BOOST_CONTRACT_DETAIL_SOURCE - #define BOOST_CONTRACT_DETAIL_DECLSPEC BOOST_SYMBOL_EXPORT - #else - #define BOOST_CONTRACT_DETAIL_DECLSPEC BOOST_SYMBOL_IMPORT - #endif -#else - #define BOOST_CONTRACT_DETAIL_DECLSPEC /* nothing */ -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/inlined.hpp b/include/boost/contract/detail/inlined.hpp deleted file mode 100644 index 1a14733d..00000000 --- a/include/boost/contract/detail/inlined.hpp +++ /dev/null @@ -1,14 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_INLINED_HPP_ -#define BOOST_CONTRACT_DETAIL_INLINED_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -#endif // #include guard - diff --git a/include/boost/contract/detail/inlined/core/exception.hpp b/include/boost/contract/detail/inlined/core/exception.hpp deleted file mode 100644 index b3df0ec7..00000000 --- a/include/boost/contract/detail/inlined/core/exception.hpp +++ /dev/null @@ -1,374 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_INLINED_EXCEPTION_HPP_ -#define BOOST_CONTRACT_DETAIL_INLINED_EXCEPTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// IMPORTANT: Do NOT use config macros BOOST_CONTRACT_... in this file so lib -// .cpp does not need recompiling if config changes (recompile only user code). - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { namespace contract { - -exception::~exception() BOOST_NOEXCEPT_OR_NOTHROW {} - -bad_virtual_result_cast::bad_virtual_result_cast(char const* from_type_name, - char const* to_type_name) { - std::ostringstream text; - text - << "incompatible contracted virtual function result type " - << "conversion from '" << from_type_name << "' to '" - << to_type_name << "'" - ; - what_ = text.str(); -} - -bad_virtual_result_cast::~bad_virtual_result_cast() BOOST_NOEXCEPT_OR_NOTHROW {} - -char const* bad_virtual_result_cast::what() const BOOST_NOEXCEPT_OR_NOTHROW { - return what_.c_str(); -} - -assertion_failure::assertion_failure(char const* const file, - unsigned long const line, char const* const code) : - file_(file), line_(line), code_(code) -{ init(); } - -assertion_failure::assertion_failure(char const* const code) : - file_(""), line_(0), code_(code) -{ init(); } - -assertion_failure::~assertion_failure() BOOST_NOEXCEPT_OR_NOTHROW {} - -char const* assertion_failure::what() const BOOST_NOEXCEPT_OR_NOTHROW { - return what_.c_str(); -} - -char const* assertion_failure::file() const { return file_; } - -unsigned long assertion_failure::line() const { return line_; } - -char const* assertion_failure::code() const { return code_; } - -void assertion_failure::init() { - std::ostringstream text; - text << "assertion"; - if(std::string(code_) != "") text << " \"" << code_ << "\""; - text << " failed"; - if(std::string(file_) != "") { - text << ": file \"" << file_ << "\""; - if(line_ != 0) text << ", line " << line_; - } - what_ = text.str(); -} - -namespace exception_ { - enum failure_key { - check_failure_key, - pre_failure_key, - post_failure_key, - except_failure_key, - old_failure_key, - entry_inv_failure_key, - exit_inv_failure_key - }; - - template - void default_handler() { - std::string k = ""; - switch(Key) { - case check_failure_key: k = "check "; break; - case pre_failure_key: k = "precondition "; break; - case post_failure_key: k = "postcondition "; break; - case except_failure_key: k = "except "; break; - case old_failure_key: k = "old copy "; break; - case entry_inv_failure_key: k = "entry invariant "; break; - case exit_inv_failure_key: k = "exit invariant "; break; - // No default (so compiler warning/error on missing enum case). - } - try { throw; } - catch(boost::contract::assertion_failure const& error) { - // what = "assertion '...' failed: ...". - std::cerr << k << error.what() << std::endl; - } catch(...) { // old_failure_key prints this, not above. - std::cerr << k << "threw following exception:" << std::endl - << boost::current_exception_diagnostic_information(); - } - std::terminate(); // Default handlers log and call terminate. - } - - template - void default_from_handler(from) { default_handler(); } - - // Check failure. - - boost::mutex check_failure_mutex; - failure_handler check_failure_handler = &default_handler; - - failure_handler const& set_check_failure_unlocked(failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW { - check_failure_handler = f; - return f; - } - - failure_handler const& set_check_failure_locked(failure_handler const& f) - BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(check_failure_mutex); - return set_check_failure_unlocked(f); - } - - failure_handler get_check_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW { - return check_failure_handler; - } - - failure_handler get_check_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(check_failure_mutex); - return get_check_failure_unlocked(); - } - - void check_failure_unlocked() /* can throw */ { - check_failure_handler(); - } - - void check_failure_locked() /* can throw */ { - boost::lock_guard lock(check_failure_mutex); - check_failure_unlocked(); - } - - // Precondition failure. - - boost::mutex pre_failure_mutex; - from_failure_handler pre_failure_handler = - &default_from_handler; - - from_failure_handler const& set_pre_failure_unlocked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - pre_failure_handler = f; - return f; - } - - from_failure_handler const& set_pre_failure_locked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(pre_failure_mutex); - return set_pre_failure_unlocked(f); - } - - from_failure_handler get_pre_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW { - return pre_failure_handler; - } - - from_failure_handler get_pre_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(pre_failure_mutex); - return get_pre_failure_unlocked(); - } - - void pre_failure_unlocked(from where) /* can throw */ { - pre_failure_handler(where); - } - - void pre_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(pre_failure_mutex); - pre_failure_unlocked(where); - } - - // Postcondition failure. - - boost::mutex post_failure_mutex; - from_failure_handler post_failure_handler = - &default_from_handler; - - from_failure_handler const& set_post_failure_unlocked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - post_failure_handler = f; - return f; - } - - from_failure_handler const& set_post_failure_locked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(post_failure_mutex); - return set_post_failure_unlocked(f); - } - - from_failure_handler get_post_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW { - return post_failure_handler; - } - - from_failure_handler get_post_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(post_failure_mutex); - return get_post_failure_unlocked(); - } - - void post_failure_unlocked(from where) /* can throw */ { - post_failure_handler(where); - } - - void post_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(post_failure_mutex); - post_failure_unlocked(where); - } - - // Except failure. - - boost::mutex except_failure_mutex; - from_failure_handler except_failure_handler = - &default_from_handler; - - from_failure_handler const& set_except_failure_unlocked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - except_failure_handler = f; - return f; - } - - from_failure_handler const& set_except_failure_locked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(except_failure_mutex); - return set_except_failure_unlocked(f); - } - - from_failure_handler get_except_failure_unlocked() - BOOST_NOEXCEPT_OR_NOTHROW { - return except_failure_handler; - } - - from_failure_handler get_except_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(except_failure_mutex); - return get_except_failure_unlocked(); - } - - void except_failure_unlocked(from where) /* can throw */ { - except_failure_handler(where); - } - - void except_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(except_failure_mutex); - except_failure_unlocked(where); - } - - // Old-copy failure. - - boost::mutex old_failure_mutex; - from_failure_handler old_failure_handler = - &default_from_handler; - - from_failure_handler const& set_old_failure_unlocked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - old_failure_handler = f; - return f; - } - - from_failure_handler const& set_old_failure_locked(from_failure_handler - const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(old_failure_mutex); - return set_old_failure_unlocked(f); - } - - from_failure_handler get_old_failure_unlocked() BOOST_NOEXCEPT_OR_NOTHROW { - return old_failure_handler; - } - - from_failure_handler get_old_failure_locked() BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(old_failure_mutex); - return get_old_failure_unlocked(); - } - - void old_failure_unlocked(from where) /* can throw */ { - old_failure_handler(where); - } - - void old_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(old_failure_mutex); - old_failure_unlocked(where); - } - - // Entry invariant failure. - - boost::mutex entry_inv_failure_mutex; - from_failure_handler entry_inv_failure_handler = - &default_from_handler; - - from_failure_handler const& set_entry_inv_failure_unlocked( - from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { - entry_inv_failure_handler = f; - return f; - } - - from_failure_handler const& set_entry_inv_failure_locked( - from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(entry_inv_failure_mutex); - return set_entry_inv_failure_unlocked(f); - } - - from_failure_handler get_entry_inv_failure_unlocked() - BOOST_NOEXCEPT_OR_NOTHROW { - return entry_inv_failure_handler; - } - - from_failure_handler get_entry_inv_failure_locked() - BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(entry_inv_failure_mutex); - return get_entry_inv_failure_unlocked(); - } - - void entry_inv_failure_unlocked(from where) /* can throw */ { - entry_inv_failure_handler(where); - } - - void entry_inv_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(entry_inv_failure_mutex); - entry_inv_failure_unlocked(where); - } - - // Exit invariant failure. - - boost::mutex exit_inv_failure_mutex; - from_failure_handler exit_inv_failure_handler = - &default_from_handler; - - from_failure_handler const& set_exit_inv_failure_unlocked( - from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { - exit_inv_failure_handler = f; - return f; - } - - from_failure_handler const& set_exit_inv_failure_locked( - from_failure_handler const& f) BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(exit_inv_failure_mutex); - return set_exit_inv_failure_unlocked(f); - } - - from_failure_handler get_exit_inv_failure_unlocked() - BOOST_NOEXCEPT_OR_NOTHROW { - return exit_inv_failure_handler; - } - - from_failure_handler get_exit_inv_failure_locked() - BOOST_NOEXCEPT_OR_NOTHROW { - boost::lock_guard lock(exit_inv_failure_mutex); - return get_exit_inv_failure_unlocked(); - } - - void exit_inv_failure_unlocked(from where) /* can throw */ { - exit_inv_failure_handler(where); - } - - void exit_inv_failure_locked(from where) /* can throw */ { - boost::lock_guard lock(exit_inv_failure_mutex); - exit_inv_failure_unlocked(where); - } -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/inlined/detail/checking.hpp b/include/boost/contract/detail/inlined/detail/checking.hpp deleted file mode 100644 index 83dc688c..00000000 --- a/include/boost/contract/detail/inlined/detail/checking.hpp +++ /dev/null @@ -1,46 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECKING_HPP_ -#define BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECKING_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// IMPORTANT: Do NOT use config macros BOOST_CONTRACT_... in this file so lib -// .cpp does not need recompiling if config changes (recompile only user code). - -#include -#include - -namespace boost { namespace contract { namespace detail { - -void checking::init_unlocked() { checking_ = true; } - -void checking::init_locked() { - boost::lock_guard lock(mutex_); - init_unlocked(); -} - -void checking::done_unlocked() { checking_ = false; } - -void checking::done_locked() { - boost::lock_guard lock(mutex_); - done_unlocked(); -} - -bool checking::already_unlocked() { return checking_; } - -bool checking::already_locked() { - boost::lock_guard lock(mutex_); - return already_unlocked(); -} - -// Shared state (so should be compiled as shared lib). -boost::mutex checking::mutex_; -bool checking::checking_ = false; - -} } } // namespace - -#endif - diff --git a/include/boost/contract/detail/name.hpp b/include/boost/contract/detail/name.hpp deleted file mode 100644 index f6d28441..00000000 --- a/include/boost/contract/detail/name.hpp +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_NAME_HPP_ -#define BOOST_CONTRACT_DETAIL_NAME_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PUBLIC */ - -// NOTE: Explicitly list number of names to concatenate using ..._NAME-n -// (instead of using ..._SEQ_CAT or similar) for optimal speed and reentrancy. - -#define BOOST_CONTRACT_DETAIL_NAME1(name1) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_NAME_PREFIX, name1) - -#define BOOST_CONTRACT_DETAIL_NAME2(name1, name2) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_NAME_PREFIX, BOOST_PP_CAT(name1, \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_NAME_INFIX, name2))) - -#endif // #include guard - diff --git a/include/boost/contract/detail/none.hpp b/include/boost/contract/detail/none.hpp deleted file mode 100644 index aa716bfe..00000000 --- a/include/boost/contract/detail/none.hpp +++ /dev/null @@ -1,26 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_NONE_HPP_ -#define BOOST_CONTRACT_DETAIL_NONE_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -namespace boost { namespace contract { namespace detail { - -// Tag for "no type". -class none { -public: - // Some lib code use this to avoid unused local var warnings on #if, etc. - static none& value() { static none none_value; return none_value; } -}; - -// Transform `void` to `none` type (for convenience, instead of using MPL). -template struct none_if_void { typedef T type; }; -template<> struct none_if_void { typedef none type; }; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/noop.hpp b/include/boost/contract/detail/noop.hpp deleted file mode 100644 index 6646fa3c..00000000 --- a/include/boost/contract/detail/noop.hpp +++ /dev/null @@ -1,19 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_NOOP_HPP_ -#define BOOST_CONTRACT_DETAIL_NOOP_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -// Following must be expressions, not statements (as used with if.., etc.). - -#define BOOST_CONTRACT_DETAIL_NOOP ((void*)0) - -// Following always compiles but never evaluates cond (so check correct syntax). -#define BOOST_CONTRACT_DETAIL_NOEVAL(cond) \ - (true || (cond) ? BOOST_CONTRACT_DETAIL_NOOP : BOOST_CONTRACT_DETAIL_NOOP) - -#endif // #include guard - diff --git a/include/boost/contract/detail/operation/constructor.hpp b/include/boost/contract/detail/operation/constructor.hpp deleted file mode 100644 index 0966dfd1..00000000 --- a/include/boost/contract/detail/operation/constructor.hpp +++ /dev/null @@ -1,95 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_CONSTRUCTOR_HPP_ -#define BOOST_CONTRACT_DETAIL_CONSTRUCTOR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS)) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include - #include -#endif - -namespace boost { namespace contract { namespace detail { - -// Ctor subcontracting impl via C++ obj construction mechanism. -template // Non-copyable base. -class constructor : public cond_inv { -public: - explicit constructor(C* obj) : cond_inv( - boost::contract::from_constructor, obj) {} - -private: - #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_OLDS) - void init() /* override */ { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - checking k; - #endif - this->check_entry_static_inv(); - // No object before ctor body so check only static inv at - // entry. Ctor pre checked by constructor_precondition. - } - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_old(); - #endif - } - #endif - -public: - #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - ~constructor() BOOST_NOEXCEPT_IF(false) { - this->assert_initialized(); - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - checking k; - #endif - - // If ctor body threw, no obj so check only static inv. Otherwise, - // obj constructed so check static inv, non-static inv, and post. - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_exit_static_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_exit_all_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_post(none()); - #endif - } - } - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/operation/destructor.hpp b/include/boost/contract/detail/operation/destructor.hpp deleted file mode 100644 index ddc21f38..00000000 --- a/include/boost/contract/detail/operation/destructor.hpp +++ /dev/null @@ -1,102 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_DESTRUCTOR_HPP_ -#define BOOST_CONTRACT_DETAIL_DESTRUCTOR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS)) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include - #include -#endif - -namespace boost { namespace contract { namespace detail { - -// Dtor subcontracting impl via C++ obj destruction mechanism. -template // Non-copyable base. -class destructor : public cond_inv { -public: - explicit destructor(C* obj) : cond_inv( - boost::contract::from_destructor, obj) {} - -private: - #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_OLDS) - void init() /* override */ { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - checking k; - #endif - // Obj exists (before dtor body), check static and non- inv. - this->check_entry_all_inv(); - // Dtor cannot have pre because it has no parameters. - } - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_old(); - #endif - } - #endif - -public: - #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - ~destructor() BOOST_NOEXCEPT_IF(false) { - this->assert_initialized(); - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - checking k; - #endif - - // If dtor body threw, obj still exists so check subcontracted - // static and non- inv (but no post because of throw). Otherwise, - // obj destructed so check static inv and post (even if there is no - // obj after dtor body, this library allows dtor post, for example - // to check static members for an instance counter class). - // NOTE: In theory C++ destructors should not throw, but the - // language allows for that (even if in C++11 dtors declarations are - // implicitly noexcept(true) unless specified otherwise) so this - // library must handle such a case. - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_exit_all_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_exit_static_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_post(none()); - #endif - } - } - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/operation/function.hpp b/include/boost/contract/detail/operation/function.hpp deleted file mode 100644 index 1d342cab..00000000 --- a/include/boost/contract/detail/operation/function.hpp +++ /dev/null @@ -1,82 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_FUNCTION_HPP_ -#define BOOST_CONTRACT_DETAIL_FUNCTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS)) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include - #include -#endif - -namespace boost { namespace contract { namespace detail { - -// Used for free function, private and protected member functions. -class function : public cond_post { // Non-copyable base. -public: - explicit function() : cond_post( - boost::contract::from_function) {} - -private: - #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_OLDS) - void init() /* override */ { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - { - #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && \ - !defined( \ - BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION) - checking k; - #endif - this->check_pre(); - } - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_old(); - #endif - } - #endif - -public: - #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - ~function() BOOST_NOEXCEPT_IF(false) { - this->assert_initialized(); - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - checking k; - #endif - - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_post(none()); - #endif - } - } - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/operation/public_function.hpp b/include/boost/contract/detail/operation/public_function.hpp deleted file mode 100644 index 1cc11b40..00000000 --- a/include/boost/contract/detail/operation/public_function.hpp +++ /dev/null @@ -1,161 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PUBLIC_FUNCTION_HPP_ -#define BOOST_CONTRACT_DETAIL_PUBLIC_FUNCTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include -#include -#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS)) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include -#endif - -namespace boost { namespace contract { namespace detail { - -template< - class O, typename VR, typename F, class C - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args) -> -class public_function : // Non-copyable base. - public cond_subcontracting< - O, VR, F, C - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args) - > -{ -public: - explicit public_function( - boost::contract::virtual_* v, C* obj, VR& r - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1, - BOOST_CONTRACT_MAX_ARGS, Args, &, args) - ) : - cond_subcontracting< - O, VR, F, C - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1, - BOOST_CONTRACT_MAX_ARGS, Args) - >( - boost::contract::from_function, v, obj, r - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1, - BOOST_CONTRACT_MAX_ARGS, args) - ) - {} - -private: - #if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - void init() /* override */ { - #if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - this->init_subcontracted_old(); - #endif - if(!this->base_call()) { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - #endif - { // Acquire checking guard. - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - checking k; - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - this->check_subcontracted_entry_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #ifndef \ - BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION - this->check_subcontracted_pre(); - } // Release checking guard (after pre check). - #else - } // Release checking guard (before pre check). - this->check_subcontracted_pre(); - #endif - #else - } // Release checking guard. - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_subcontracted_old(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - this->check_subcontracted_entry_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - this->check_subcontracted_pre(); - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_subcontracted_old(); - #endif - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_subcontracted_exit_inv(); - #endif - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_subcontracted_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_subcontracted_post(); - #endif - } - } - } - #endif - -public: - #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - ~public_function() BOOST_NOEXCEPT_IF(false) { - this->assert_initialized(); - if(!this->base_call()) { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - checking k; - #endif - - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_subcontracted_exit_inv(); - #endif - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_subcontracted_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_subcontracted_post(); - #endif - } - } - } - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/operation/static_public_function.hpp b/include/boost/contract/detail/operation/static_public_function.hpp deleted file mode 100644 index c70806db..00000000 --- a/include/boost/contract/detail/operation/static_public_function.hpp +++ /dev/null @@ -1,103 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_FUNCTION_HPP_ -#define BOOST_CONTRACT_DETAIL_STATIC_PUBLIC_FUNCTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS)) - #include -#endif -#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - #include - #include -#endif - -namespace boost { namespace contract { namespace detail { - -// No subcontracting because static so no obj and no substitution principle. -template // Non-copyable base. -class static_public_function : public cond_inv { -public: - explicit static_public_function() : cond_inv( - boost::contract::from_function, /* obj = */ 0) {} - -private: - #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_OLDS) - void init() /* override */ { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - #endif - #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_PRECONDITIONS) - { // Acquire checking guard. - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - checking k; - #endif - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - this->check_entry_static_inv(); - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #ifndef \ - BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION - this->check_pre(); - } // Release checking guard (after pre check). - #else - } // Release checking guard (before pre check). - this->check_pre(); - #endif - #else - } // Release checking guard - #endif - #endif - #ifndef BOOST_CONTRACT_NO_OLDS - this->copy_old(); - #endif - } - #endif - -public: - #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_EXCEPTS) - ~static_public_function() BOOST_NOEXCEPT_IF(false) { - this->assert_initialized(); - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - if(checking::already()) return; - checking k; - #endif - - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - this->check_exit_static_inv(); - #endif - if(std::uncaught_exception()) { - #ifndef BOOST_CONTRACT_NO_EXCEPTS - this->check_except(); - #endif - } else { - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - this->check_post(none()); - #endif - } - } - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/operator_safe_bool.hpp b/include/boost/contract/detail/operator_safe_bool.hpp deleted file mode 100644 index 0e951da0..00000000 --- a/include/boost/contract/detail/operator_safe_bool.hpp +++ /dev/null @@ -1,73 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL_HPP_ -#define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -// NOTE: This code is inspired by . - -/* PRIVATE */ - -// operator! is redundant, but some compilers need it. -#define BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) \ - bool operator!() const BOOST_NOEXCEPT { return !(bool_expr); } - -/* PUBLIC */ - -#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS) && \ - !defined(BOOST_NO_CXX11_NULLPTR) - #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \ - explicit operator bool() const BOOST_NOEXCEPT { return (bool_expr); } \ - BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) -#elif (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || \ - defined(__CINT__) - #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \ - operator bool() const BOOST_NOEXCEPT { return (bool_expr); } \ - BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) -#elif defined(_MANAGED) - #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \ - static void BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func)( \ - this_type***) {} \ - typedef void (*BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type))( \ - this_type***); \ - operator BOOST_CONTRACT_DETAIL_NANE(operator_safe_bool_type)() \ - const BOOST_NOEXCEPT { \ - return (bool_expr) ? \ - &BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func) : 0; \ - } \ - BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) -#elif (defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200)) || \ - (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304)) || \ - (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)) - #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \ - void BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func)() const {} \ - typedef void (this_type::*BOOST_CONTRACT_DETAIL_NAME1( \ - operator_safe_bool_type))() const; \ - operator BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type)() \ - const BOOST_NOEXCEPT { \ - return (bool_expr) ? &this_type:: \ - BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_func) : 0; \ - } \ - BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) -#else - #define BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(this_type, bool_expr) \ - void* BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_data); \ - typedef void* this_type::*BOOST_CONTRACT_DETAIL_NAME1( \ - operator_safe_bool_type);\ - operator BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_type)() \ - const BOOST_NOEXCEPT { \ - return (bool_expr) ? &this_type:: \ - BOOST_CONTRACT_DETAIL_NAME1(operator_safe_bool_data) : 0; \ - } \ - BOOST_CONTRACT_OPERATOR_SAFE_BOOL_NOT_(bool_expr) -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/preprocessor/keyword/private.hpp b/include/boost/contract/detail/preprocessor/keyword/private.hpp deleted file mode 100644 index 4e162999..00000000 --- a/include/boost/contract/detail/preprocessor/keyword/private.hpp +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_HPP_ -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PRIVATE */ - -// Must expand to a single comma `,` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_CAT_TO_COMMAprivate , - -// Must expand to empty `` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_CAT_TO_EMPTYprivate - -/* PUBLIC */ - -// Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PRIVATE(tokens) \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS( \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_CAT_TO_COMMA, tokens) - -// Precondition: tokens must start with `private` (this can be -// checked with `..._IS_PRIVATE` macro above). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_PRIVATE(tokens) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_PP_KEYWORD_PRIVATE_CAT_TO_EMPTY, tokens) - -#endif // #include guard - diff --git a/include/boost/contract/detail/preprocessor/keyword/protected.hpp b/include/boost/contract/detail/preprocessor/keyword/protected.hpp deleted file mode 100644 index b864a762..00000000 --- a/include/boost/contract/detail/preprocessor/keyword/protected.hpp +++ /dev/null @@ -1,36 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_HPP_ -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PRIVATE */ - -// Must expand to a single comma `,` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_CAT_TO_COMMAprotected , - -// Must expand to empty `` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_CAT_TO_EMPTYprotected - -/* PUBLIC */ - -// Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PROTECTED(tokens) \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS( \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_CAT_TO_COMMA, tokens) - -// Precondition: tokens must start with `protected` (this can be -// checked with `..._IS_PROTECTED` macro above). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_PROTECTED(tokens) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_PP_KEYWORD_PROTECTED_CAT_TO_EMPTY, \ - tokens) - -#endif // #include guard - diff --git a/include/boost/contract/detail/preprocessor/keyword/public.hpp b/include/boost/contract/detail/preprocessor/keyword/public.hpp deleted file mode 100644 index 60bc03bd..00000000 --- a/include/boost/contract/detail/preprocessor/keyword/public.hpp +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_HPP_ -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PRIVATE */ - -// Must expand to a single comma `,` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_CAT_TO_COMMApublic , - -// Must expand to empty `` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_CAT_TO_EMPTYpublic - -/* PUBLIC */ - -// Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_PUBLIC(tokens) \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS( \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_CAT_TO_COMMA, tokens) - -// Precondition: tokens must start with `public` (this can be -// checked with `..._IS_PUBLIC` macro above). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_PUBLIC(tokens) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_PP_KEYWORD_PUBLIC_CAT_TO_EMPTY, tokens) - -#endif // #include guard - diff --git a/include/boost/contract/detail/preprocessor/keyword/utility/is.hpp b/include/boost/contract/detail/preprocessor/keyword/utility/is.hpp deleted file mode 100644 index 4d4c934b..00000000 --- a/include/boost/contract/detail/preprocessor/keyword/utility/is.hpp +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS_HPP_ -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PRIVATE */ - -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS_1 0 -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS_2 1 - -/* PUBLIC */ - -// Precondition: A macro named `cat_to_comma_prefix ## token-to-check` must be -// #defined to expand to `,`. -// Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS( \ - cat_to_comma_prefix, tokens) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS_, \ - BOOST_PP_VARIADIC_SIZE(BOOST_PP_CAT(cat_to_comma_prefix, tokens))) - -#endif // #include guard - diff --git a/include/boost/contract/detail/preprocessor/keyword/virtual.hpp b/include/boost/contract/detail/preprocessor/keyword/virtual.hpp deleted file mode 100644 index 46c5e59f..00000000 --- a/include/boost/contract/detail/preprocessor/keyword/virtual.hpp +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_HPP_ -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include - -/* PRIVATE */ - -// Must expand to a single comma `,` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_CAT_TO_COMMAvirtual , - -// Must expand to empty `` (not local macros, do not #undefine). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_CAT_TO_EMPTYvirtual - -/* PUBLIC */ - -// Precondition: tokens must start with a token concatenable to a macro name -// (e.g., a literal or integral token). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_IS_VIRTUAL(tokens) \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_UTILITY_IS( \ - BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_CAT_TO_COMMA, tokens) - -// Precondition: tokens must start with `virtual` (this can be -// checked with `..._IS_VIRTUAL` macro above). -#define BOOST_CONTRACT_DETAIL_PP_KEYWORD_REMOVE_VIRTUAL(tokens) \ - BOOST_PP_CAT(BOOST_CONTRACT_DETAIL_PP_KEYWORD_VIRTUAL_CAT_TO_EMPTY, tokens) - -#endif // #include guard - diff --git a/include/boost/contract/detail/tvariadic.hpp b/include/boost/contract/detail/tvariadic.hpp deleted file mode 100644 index 8b7ddae9..00000000 --- a/include/boost/contract/detail/tvariadic.hpp +++ /dev/null @@ -1,190 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_ -#define BOOST_CONTRACT_DETAIL_TVARIADIC_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES - #define BOOST_CONTRACT_DETAIL_TVARIADIC 0 -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC 1 -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #include - - /* CODE */ - - namespace boost { namespace contract { namespace detail { - namespace tvariadic_ { - template struct indexes {}; - - template struct indexes_of : - indexes_of {}; - template struct indexes_of<0, I...> - { typedef indexes type; }; - } } } } // namespace - -#else - #include - #include - #include - #include - #include - - /* PRIVATE */ - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_(z, n, tuple) \ - BOOST_PP_CAT(tuple, n) - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_(z, n, tuplevar_values) \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, tuplevar_values), n)( \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, tuplevar_values), n)) - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_(z, n, type_qualifier_name) \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \ - BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n) \ - ; - - #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_(z, n, tokens) \ - tokens - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_(z, n, name) \ - BOOST_PP_CAT(name, n) - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_(z, n, type_qualifier_name) \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 0, type_qualifier_name), n) \ - BOOST_PP_TUPLE_ELEM(3, 1, type_qualifier_name) \ - BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 2, type_qualifier_name), n) - - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_(z, n, name) \ - typename BOOST_PP_CAT(name, n) -#endif - -/* PUBLIC */ - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - , -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_PP_COMMA_IF(arity) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) /* nothing */ -#else - #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity) \ - BOOST_PP_COMMA_IF(arity) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) sizeof...(name) -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, name) arity -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \ - typename... name -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, name) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAM_, \ - name) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \ - z, arity, type, qualifier, name) \ - type qualifier ... name -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z( \ - z, arity, type, qualifier, name) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAM_, \ - (type, qualifier, name)) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \ - name... -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, name) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_ARG_, name) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \ - /* nothing */ -#else - #define BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity, tokens) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_, \ - tokens) -#endif - -// Tuple. - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \ - z, arity, type, qualifier, name) \ - std::tuple name; -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z( \ - z, arity, type, qualifier, name) \ - BOOST_PP_REPEAT_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_, \ - (type, qualifier, name)) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \ - arity, tuple, values) \ - tuple(values...) -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(z, \ - arity, tuple, values) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_,\ - (tuple, values)) -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \ - int... indexes -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_TPARAM(indexes) \ - /* nothing */ -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \ - boost::contract::detail::tvariadic_::indexes<_indexes...> -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_FPARAM(_indexes) \ - /* nothing */ -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(tuple_type) \ - typename boost::contract::detail::tvariadic_::indexes_of< \ - sizeof...(tuple_type)>::type() -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(unused) \ - /* nothing */ -#endif - -#if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \ - z, arity, indexes, tuple) \ - std::get(tuple)... -#else - #define BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEMS_Z( \ - z, arity, indexes, tuple) \ - BOOST_PP_ENUM_ ## z(arity, BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_ELEM_,\ - tuple) -#endif - -#endif // #include guard - diff --git a/include/boost/contract/detail/type_traits/member_function_types.hpp b/include/boost/contract/detail/type_traits/member_function_types.hpp deleted file mode 100644 index 438ba771..00000000 --- a/include/boost/contract/detail/type_traits/member_function_types.hpp +++ /dev/null @@ -1,72 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_MEMBER_FUNCTION_TYPES_HPP_ -#define BOOST_CONTRACT_DETAIL_MEMBER_FUNCTION_TYPES_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace boost { - namespace contract { - class virtual_; - } -} - -namespace boost { namespace contract { namespace detail { - -template -struct member_function_types { - typedef typename boost::function_types::result_type::type result_type; - - // Never include leading class type. - typedef typename boost::mpl::pop_front::type>::type argument_types; - - // Always include trailing virtual_* type. - typedef typename boost::mpl::if_::type, boost::contract::virtual_*>, - boost::mpl::identity - , - boost::mpl::push_back - >::type::type virtual_argument_types; - - typedef typename boost::mpl::if_, - boost::is_volatile >, - boost::function_types::cv_qualified - , typename boost::mpl::if_, - boost::function_types::const_non_volatile - , typename boost::mpl::if_, - boost::function_types::volatile_non_const - , - boost::function_types::null_tag - >::type>::type>::type property_tag; -}; - -// Also handles none type. -template -struct member_function_types { - typedef none result_type; - typedef none argument_types; - typedef none virtual_argument_types; - typedef none property_tag; -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/type_traits/mirror.hpp b/include/boost/contract/detail/type_traits/mirror.hpp deleted file mode 100644 index 9f2ae5c6..00000000 --- a/include/boost/contract/detail/type_traits/mirror.hpp +++ /dev/null @@ -1,111 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_MIRROR_HPP_ -#define BOOST_CONTRACT_DETAIL_MIRROR_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// NOTE: Unfortunately, it is not possible to use Boost.TTI because it not -// always works on MSVC (e.g., when the mirror meta-function is invoked -// multiple times, MSVC 2010 gives an internal compiler error). This is a -// simpler mirror implementation that seems to work better on MSVC. - -/* PRIVATE */ - -#define BOOST_CONTRACT_DETAIL_MIRROR_END_(tparam) \ - template \ - static boost::contract::detail::mirror::no& check(...); \ - public: \ - static bool const value = sizeof(check(0)) == \ - sizeof(boost::contract::detail::mirror::yes); \ - typedef boost::mpl::bool_ type; - -#define BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_(is_static, \ - trait, func_name) \ - template< \ - typename BOOST_CONTRACT_DETAIL_NAME1(T), \ - typename BOOST_CONTRACT_DETAIL_NAME1(R), \ - class BOOST_CONTRACT_DETAIL_NAME1(P), \ - class BOOST_CONTRACT_DETAIL_NAME1(G) = boost::function_types::null_tag \ - > \ - class trait { \ - template \ - static boost::contract::detail::mirror::yes& check( \ - boost::contract::detail::mirror::check_function< \ - typename \ - BOOST_PP_IIF(is_static, \ - boost::function_types::function_pointer \ - , \ - boost::function_types::member_function_pointer \ - ) \ - < \ - typename boost::mpl::push_front< \ - BOOST_PP_IIF(is_static, \ - BOOST_CONTRACT_DETAIL_NAME1(P) \ - BOOST_PP_TUPLE_EAT(2) \ - , \ - BOOST_PP_TUPLE_REM(2) \ - )( \ - typename boost::mpl::push_front< \ - BOOST_CONTRACT_DETAIL_NAME1(P), \ - BOOST_CONTRACT_DETAIL_NAME1(C) \ - >::type \ - ) \ - , BOOST_CONTRACT_DETAIL_NAME1(R) \ - >::type, \ - BOOST_CONTRACT_DETAIL_NAME1(G) \ - >::type, \ - &BOOST_CONTRACT_DETAIL_NAME1(C)::func_name \ - >* \ - ); \ - BOOST_CONTRACT_DETAIL_MIRROR_END_( \ - BOOST_CONTRACT_DETAIL_NAME1(T)) \ - }; - -/* PUBLIC */ - -#define BOOST_CONTRACT_DETAIL_MIRROR_HAS_TYPE(trait, type_name)\ - template \ - class trait { \ - template \ - static boost::contract::detail::mirror::yes& check( \ - typename BOOST_CONTRACT_DETAIL_NAME1(C)::type_name*); \ - BOOST_CONTRACT_DETAIL_MIRROR_END_( \ - BOOST_CONTRACT_DETAIL_NAME1(T)) \ - }; - -#define BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \ - trait, func_name) \ - BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_( \ - /* is_static = */ 0, trait, func_name) - -#define BOOST_CONTRACT_DETAIL_MIRROR_HAS_STATIC_MEMBER_FUNCTION(trait, \ - func_name) \ - BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION_( \ - /* is_static = */ 1, trait, func_name) - -/* CODE */ - -namespace boost { namespace contract { namespace detail { namespace mirror { - -typedef class {} yes; -typedef yes no[2]; - -template class check_function; - -} } } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/type_traits/optional.hpp b/include/boost/contract/detail/type_traits/optional.hpp deleted file mode 100644 index 5a6b2c4c..00000000 --- a/include/boost/contract/detail/type_traits/optional.hpp +++ /dev/null @@ -1,42 +0,0 @@ - -#ifndef BOOST_CONTRACT_DETAIL_OPTIONAL_HPP_ -#define BOOST_CONTRACT_DETAIL_OPTIONAL_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -#include -#include -#include - -namespace boost { namespace contract { namespace detail { - -template -struct is_optional : boost::false_type {}; -template -struct is_optional > : boost::true_type {}; - -template -struct optional_value_type { typedef T type; }; -template -struct optional_value_type > { typedef T type; }; - -template -struct remove_value_reference_if_optional { typedef T type; }; -template -struct remove_value_reference_if_optional > - { typedef typename boost::remove_reference::type type; }; - -template -T& optional_get(T& x) { return x; } -template -T& optional_get(boost::optional& x) { return x.get(); } -template -T& optional_get(boost::optional& x) { return x.get(); } - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/function.hpp b/include/boost/contract/function.hpp deleted file mode 100644 index 40df205f..00000000 --- a/include/boost/contract/function.hpp +++ /dev/null @@ -1,63 +0,0 @@ - -#ifndef BOOST_CONTRACT_FUNCTION_HPP_ -#define BOOST_CONTRACT_FUNCTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Program contracts for (non-public) functions. -*/ - -#include -#include -#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #include -#endif - -namespace boost { namespace contract { - -/** -Program contracts for non-member, private and protected functions. - -This is used to specify preconditions, postconditions, exception guarantees, and -old copies at body for non-member, private and protected functions (these -functions never check class invariants, see -@RefSect{contract_programming_overview, Contract Programming Overview}). -It can be used also to program contracts in implementation code for lambda -functions, loops, and arbitrary blocks of code. - -For optimization, this can be omitted for code that does not have preconditions, -postconditions, and exception guarantees. - -@see @RefSect{tutorial.non_member_functions, Non-Member Functions}, - @RefSect{advanced.private_and_protected_functions, - Private and Protected Functions}, - @RefSect{advanced.lambdas__loops__code_blocks__and__constexpr__, - Lambdas\, Loops\, Code Blocks} - -@return The result of this function must be explicitly assigned to a variable of - type @RefClass{boost::contract::check} declared locally just before the - function body code (otherwise this library will generate a run-time - error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). -*/ -inline specify_precondition_old_postcondition_except<> function() { - // Must #if also on ..._INVARIANTS here because specify_... is generic. - #if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \ - !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - return specify_precondition_old_postcondition_except<>( - new boost::contract::detail::function()); - #else - return specify_precondition_old_postcondition_except<>(); - #endif -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/old.hpp b/include/boost/contract/old.hpp deleted file mode 100644 index 060cc985..00000000 --- a/include/boost/contract/old.hpp +++ /dev/null @@ -1,752 +0,0 @@ - -#ifndef BOOST_CONTRACT_OLD_HPP_ -#define BOOST_CONTRACT_OLD_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Handle old values. -*/ - -#include -#include -#ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - #include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !BOOST_PP_VARIADICS - -#define BOOST_CONTRACT_OLDOF \ -BOOST_CONTRACT_ERROR_macro_OLDOF_requires_variadic_macros_otherwise_manually_program_old_values - -#else // variadics - -#include -#include -#include -#include - -/* PRIVATE */ - -/** @cond */ - -#ifdef BOOST_NO_CXX11_AUTO_DECLARATIONS - #define BOOST_CONTRACT_OLDOF_AUTO_TYPEOF_(value) /* nothing */ -#else - #include - // Explicitly force old_ptr<...> conversion to allow for C++11 auto decl. - #define BOOST_CONTRACT_OLDOF_AUTO_TYPEOF_(value) \ - boost::contract::old_ptr -#endif - -#define BOOST_CONTRACT_ERROR_macro_OLDOF_has_invalid_number_of_arguments_2( \ - v, value) \ - BOOST_CONTRACT_OLDOF_AUTO_TYPEOF_(value)(boost::contract::make_old(v, \ - boost::contract::copy_old(v) ? (value) : boost::contract::null_old() \ - )) - -#define BOOST_CONTRACT_ERROR_macro_OLDOF_has_invalid_number_of_arguments_1( \ - value) \ - BOOST_CONTRACT_OLDOF_AUTO_TYPEOF_(value)(boost::contract::make_old( \ - boost::contract::copy_old() ? (value) : boost::contract::null_old() \ - )) - -/** @endcond */ - -/* PUBLIC */ - -// NOTE: Leave this #defined the same regardless of ..._NO_OLDS. -/** -Macro typically used to copy an old value expression and assign it to an old -value pointer. - -The expression expanded by this macro should be assigned to an old value -pointer of type @RefClass{boost::contract::old_ptr} or -@RefClass{boost::contract::old_ptr_if_copyable}. -This is an overloaded variadic macro and it can be used in the following -different ways. - -1\. From within virtual public functions and public functions overrides: - -@code -BOOST_CONTRACT_OLDOF(v, expr) -@endcode - -2\. From all other operations: - -@code -BOOST_CONTRACT_OLDOF(expr) -@endcode - -Where: - -@arg v is the extra parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual public function or public function - overrides declaring the contract. - (This is not a variadic macro parameter so any comma it might contain - must be protected by round parenthesis, - BOOST_CONTRACT_OLDOF((v), expr) will always work.) -@arg expr is the expression to be evaluated and copied to the - old value pointer. - (This is not a variadic macro parameter so any comma it might contain - must be protected by round parenthesis, - BOOST_CONTRACT_OLDOF(v, (expr)) will always work.) - -On compilers that do not support variadic macros, programmers can manually copy -old value expressions without using this macro (see -@RefSect{extras.no_macros__and_no_variadic_macros_, No Macros}). - -@see @RefSect{tutorial.old_values, Old Values} -*/ -#define BOOST_CONTRACT_OLDOF(...) \ - BOOST_PP_CAT( /* CAT(..., EMTPY()) required on MSVC */ \ - BOOST_PP_OVERLOAD( \ - BOOST_CONTRACT_ERROR_macro_OLDOF_has_invalid_number_of_arguments_, \ - __VA_ARGS__ \ - )(__VA_ARGS__), \ - BOOST_PP_EMPTY() \ - ) - -#endif // variadics - -/* CODE */ - -namespace boost { namespace contract { - -/** -Trait to check if an old value type can be copied or not. - -By default, this unary boolean meta-function is equivalent to -@c boost::is_copy_constructible but programmers can chose to specialize it -for user-defined types (in general some kind of specialization is needed on -compilers that do not support C++11, see also - -boost::is_copy_constructible). - -A given old value type @c X is copied only if -@c boost::contract::is_old_value_copyable::value is @c true. -Copyable old value types are always copied using -@c boost::contract::old_value_copy. -Non-copyable old value types generate a compile-time error when -@c boost::contract::old_ptr is dereferenced, but instead leave -@c boost::contract::old_ptr_if_copyable always null (without generating -compile-time errors). - -@see @RefSect{extras.old_value_requirements__templates_, - Old Value Requirements} -*/ -template -struct is_old_value_copyable : boost::is_copy_constructible {}; - -/** @cond */ -class old_value; - -template<> // Needed because `old_value` incomplete type when trait first used. -struct is_old_value_copyable : boost::true_type {}; -/** @endcond */ - -/** -Trait to copy an old value. - -By default, the implementation of this trait uses @c T's copy constructor to -make one single copy of the specified @p value. -However, programmers can specialize this trait to copy old values using -user-specific operations different from @c T's copy constructor. -The default implementation of this trait is equivalent to: - -@code -template -class old_value_copy { -public: - explicit old_value_copy(T const& old) : - old_(value) // One single copy of value using T's copy constructor. - {} - - T const& old() const { return old_; } - -private: - T const old_; // The old value copy. -}; -@endcode - -This library will instantiate and use this trait only on old value types @c T -that are copyable (i.e., for which -boost::contract::is_old_value_copyable::value is @c true). - -@see @RefSect{extras.old_value_requirements__templates_, - Old Value Requirements} -*/ -template // Used only if is_old_value_copyable. -struct old_value_copy { - /** - Construct this object by making one single copy of the specified old value. - - This is the only operation within this library that actually copies old - values. - - @param old The old value to copy. - */ - explicit old_value_copy(T const& old) : - old_(old) {} // This makes the one single copy of T. - - /** - Return a (constant) reference to the old value that was copied. - - Contract assertions should not change the state of the program so the old - value copy is returned as @c const (see also - @RefSect{contract_programming_overview.constant_correctness, - Constant Correctness}). - */ - T const& old() const { return old_; } - -private: - T const old_; -}; - -template -class old_ptr_if_copyable; - -/** -Old value pointer (that requires the pointed old value type to be copyable). - -This is set to point to an actual old value copy using either -@RefMacro{BOOST_CONTRACT_OLDOF} or @RefFunc{boost::contract::make_old} (that is -why this class does not have public non-default constructors). - -@see @RefSect{tutorial.old_values, Old Values} - -@tparam T Type of the pointed old value. - This type must be copyable (i.e., - boost::contract::is_old_value_copyable::value is @c true), - otherwise this pointer will always be null and this library will - generate a compile-time error when the pointer is dereferenced. -*/ -template -class old_ptr { /* copyable (as *) */ -public: - /** Pointed old value type. */ - typedef T element_type; - - /** Construct this old value pointer as null. */ - old_ptr() {} - - /** - Dereference this old value pointer. - - This will generate a run-time error if this pointer is null and a - compile-time error if the pointed type @c T is not copyable (i.e., if - @c boost::contract::is_old_value_copyable::value is @c false). - - @return The pointed old value. - Contract assertions should not change the state of the program so - this member function is @c const and it returns the old value as a - reference to a constant object (see also - @RefSect{contract_programming_overview.constant_correctness, - Constant Correctness}). - */ - T const& operator*() const { - BOOST_STATIC_ASSERT_MSG( - boost::contract::is_old_value_copyable::value, - "old_ptr requires T copyable (see is_old_value_copyable), " - "otherwise use old_ptr_if_copyable" - ); - BOOST_CONTRACT_DETAIL_DEBUG(typed_copy_); - return typed_copy_->old(); - } - - /** - Structure-dereference this old value pointer. - - This will generate a compile-time error if the pointed type @c T is not - copyable (i.e., if @c boost::contract::is_old_value_copyable::value is - @c false). - - @return A pointer to the old value (null if this old value pointer is null). - Contract assertions should not change the state of the program so - this member function is @c const and it returns the old value as a - constant pointer to a constant object (see also - @RefSect{contract_programming_overview.constant_correctness, - Constant Correctness}). - */ - T const* const operator->() const { - BOOST_STATIC_ASSERT_MSG( - boost::contract::is_old_value_copyable::value, - "old_ptr requires T copyble (see is_old_value_copyable), " - "otherwise use old_ptr_if_copyable" - ); - if(typed_copy_) return &typed_copy_->old(); - return 0; - } - - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(old_ptr, - !!typed_copy_) - #else - /** - Check if this old value pointer is null or not. - - (This is implemented using safe-bool emulation on compilers that do not - support C++11 explicit type conversion operators.) - - @return True if this pointer is not null, false otherwise. - */ - explicit operator bool() const; - #endif - -/** @cond */ -private: - #ifndef BOOST_CONTRACT_NO_OLDS - explicit old_ptr(boost::shared_ptr > old) - : typed_copy_(old) {} - #endif - - boost::shared_ptr > typed_copy_; - - friend class old_pointer; - friend class old_ptr_if_copyable; -/** @endcond */ -}; - -/** -Old value pointer (that does not require the pointed old value type to be -copyable). - -This is set to point to an actual old value copy using either -@RefMacro{BOOST_CONTRACT_OLDOF} or @RefFunc{boost::contract::make_old}. - -@see @RefSect{extras.old_value_requirements__templates_, - Old Value Requirements} - -@tparam T Type of the pointed old value. - If this type is not copyable (i.e., - boost::contract::is_old_value_copyable::value is @c false), - this pointer will always be null (but this library will not generate a - compile-time error when this pointer is dereferenced). -*/ -template -class old_ptr_if_copyable { /* copyable (as *) */ -public: - /** Pointed old value type. */ - typedef T element_type; - - /** Construct this old value pointer as null. */ - old_ptr_if_copyable() {} - - /** - Construct this old value pointer from an old value pointer that requires - the old value type to be copyable. - - This constructor is implicitly called by this library when assigning an - object of this type using @RefMacro{BOOST_CONTRACT_OLDOF} (this constructor - is usually not explicitly called by user code). - - @param other Old value pointer that requires the old value type to be - copyable. - */ - /* implicit */ old_ptr_if_copyable(old_ptr const& other) : - typed_copy_(other.typed_copy_) {} - - /** - Dereference this old value pointer. - - This will generate a run-time error if this pointer is null, but no - compile-time error is generated if the pointed type @c T is not copyable - (i.e., if @c boost::contract::is_old_value_copyable::value is @c false). - - @return The pointed old value. - Contract assertions should not change the state of the program so - this member function is @c const and it returns the old value as a - reference to a constant object (see also - @RefSect{contract_programming_overview.constant_correctness, - Constant Correctness}). - */ - T const& operator*() const { - BOOST_CONTRACT_DETAIL_DEBUG(typed_copy_); - return typed_copy_->old(); - } - - /** - Structure-dereference this old value pointer. - - This will return null but will not generate a compile-time error if the - pointed type @c T is not copyable (i.e., if - @c boost::contract::is_old_value_copyable::value is @c false). - - @return A pointer to the old value (null if this old value pointer is null). - Contract assertions should not change the state of the program so - this member function is @c const and it returns the old value as a - constant pointer to a constant object (see also - @RefSect{contract_programming_overview.constant_correctness, - Constant Correctness}). - */ - T const* const operator->() const { - if(typed_copy_) return &typed_copy_->old(); - return 0; - } - - #ifndef BOOST_CONTRACT_DETAIL_DOXYGEN - BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(old_ptr_if_copyable, - !!typed_copy_) - #else - /** - Check if this old value pointer is null or not (safe-bool operator). - - (This is implemented using safe-bool emulation on compilers that do not - support C++11 explicit type conversion operators.) - - @return True if this pointer is not null, false otherwise. - */ - explicit operator bool() const; - #endif - -/** @cond */ -private: - #ifndef BOOST_CONTRACT_NO_OLDS - explicit old_ptr_if_copyable(boost::shared_ptr > old) - : typed_copy_(old) {} - #endif - - boost::shared_ptr > typed_copy_; - - friend class old_pointer; -/** @endcond */ -}; - -/** -Convert user-specified expressions to old values. - -This class is often only implicitly used by this library and it does not -explicitly appear in user code. - -On older compilers that cannot correctly deduce the -@c boost::contract::is_old_value_copyable trait, programmers can manually -specialize that trait to make sure that only old value types that are copyable -are actually copied. - -@see @RefSect{extras.old_value_requirements__templates_, - Old Value Requirements} -*/ -class old_value { // Copyable (as *). -public: - // Following implicitly called by ternary operator `... ? ... : null_old()`. - - /** - Construct this object from the specified old value when the old value type - is copy constructible. - - The specified old value is copied (one time only) using - @c boost::contract::old_value_copy, in which case related old value pointer - will not be null (no copy is made if postconditions and exception guarantees - are not being checked, see @RefMacro{BOOST_CONTRACT_NO_OLDS}). - - @param old Old value to be copied. - - @tparam T Old value type. - */ - template - /* implicit */ old_value( - T const& old, - typename boost::enable_if - >::type* = 0 - ) - #ifndef BOOST_CONTRACT_NO_OLDS - : untyped_copy_(new old_value_copy(old)) - #endif // Else, leave ptr_ null (thus no copy of T). - {} - - /** - Construct this object from the specified old value when the old value type - is not copyable. - - The specified old value cannot be copied in this case so it is not copied - and the related old value pointer will always be null (thus a call to this - constructor has no effect and it will likely be optimized away by most - compilers). - - @param old Old value (that will not be copied in this case). - - @tparam T Old value type. - */ - template - /* implicit */ old_value( - T const& old, - typename boost::disable_if - >::type* = 0 - ) {} // Leave ptr_ null (thus no copy of T). - -/** @cond */ -private: - explicit old_value() {} - - #ifndef BOOST_CONTRACT_NO_OLDS - boost::shared_ptr untyped_copy_; // Type erasure. - #endif - - friend class old_pointer; - friend old_value null_old(); -/** @endcond */ -}; - -/** -Convert old value copies to old value pointers. - -This class is often only implicitly used by this library and it does not -explicitly appear in user code (that is why this class does not have public -constructors, etc.). -*/ -class old_pointer { // Copyable (as *). -public: - /** - Convert this object to an actual old value pointer (the old value type might - or not be copyable). - - For example, this is implicitly called when assigning or initializing old - value pointers. - - @tparam T Type of the pointed old value. - The old value pointer will always be null if this type is not - copyable (see - @c boost::contract::is_old_value_copyable), but this library - will not generate a compile-time error. - */ - template - /* implicit */ operator old_ptr_if_copyable() { - return get >(); - } - - /** - Convert this object to an actual old value pointer (the old value type must - be copyable). - - For example, this is implicitly called when assigning or initializing old - value pointers. - - @tparam T Type of the pointed old value. This type must be copyable - (see @c boost::contract::is_old_value_copyable), - otherwise this library will generate a compile-time error when - the old value pointer is dereferenced. - */ - template - /* implicit */ operator old_ptr() { - return get >(); - } - -/** @cond */ -private: - explicit old_pointer(virtual_* v, old_value const& old) - #ifndef BOOST_CONTRACT_NO_OLDS - : v_(v), untyped_copy_(old.untyped_copy_) - #endif - {} - - template - Ptr get() { - #ifndef BOOST_CONTRACT_NO_OLDS - if(!boost::contract::is_old_value_copyable::value) { - BOOST_CONTRACT_DETAIL_DEBUG(!untyped_copy_); - return Ptr(); // Non-copyable so no old value and return null. - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - } else if(!v_ && boost::contract::detail::checking::already()) { - return Ptr(); // Not checking (so return null). - #endif - } else if(!v_) { - BOOST_CONTRACT_DETAIL_DEBUG(untyped_copy_); - typedef old_value_copy copied_type; - boost::shared_ptr typed_copy = // Un-erase type. - boost::static_pointer_cast(untyped_copy_); - BOOST_CONTRACT_DETAIL_DEBUG(typed_copy); - return Ptr(typed_copy); - } else if( - v_->action_ == boost::contract::virtual_::push_old_init_copy || - v_->action_ == boost::contract::virtual_::push_old_ftor_copy - ) { - BOOST_CONTRACT_DETAIL_DEBUG(untyped_copy_); - std::queue >& copies = v_->action_ == - boost::contract::virtual_::push_old_ftor_copy ? - v_->old_ftor_copies_ - : - v_->old_init_copies_ - ; - copies.push(untyped_copy_); - return Ptr(); // Pushed (so return null). - } else if( - boost::contract::virtual_::pop_old_init_copy(v_->action_) || - v_->action_ == boost::contract::virtual_::pop_old_ftor_copy - ) { - // Copy not null, but still pop it from the queue. - BOOST_CONTRACT_DETAIL_DEBUG(!untyped_copy_); - - std::queue >& copies = v_->action_ == - boost::contract::virtual_::pop_old_ftor_copy ? - v_->old_ftor_copies_ - : - v_->old_init_copies_ - ; - boost::shared_ptr untyped_copy = copies.front(); - BOOST_CONTRACT_DETAIL_DEBUG(untyped_copy); - copies.pop(); - - typedef old_value_copy copied_type; - boost::shared_ptr typed_copy = // Un-erase type. - boost::static_pointer_cast(untyped_copy); - BOOST_CONTRACT_DETAIL_DEBUG(typed_copy); - return Ptr(typed_copy); - } - BOOST_CONTRACT_DETAIL_DEBUG(!untyped_copy_); - #endif - return Ptr(); - } - - #ifndef BOOST_CONTRACT_NO_OLDS - virtual_* v_; - boost::shared_ptr untyped_copy_; // Type erasure. - #endif - - friend old_pointer make_old(old_value const&); - friend old_pointer make_old(virtual_*, old_value const&); -/** @endcond */ -}; - -/** -Return a null old value. - -The related old value pointer will also be null. -This function is often only used by the code expanded by -@RefMacro{BOOST_CONTRACT_OLDOF}. - -@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - -@return Null old value. -*/ -old_value null_old() { return old_value(); } - -/** -Make an old value pointer (but not for virtual public functions and public -functions overrides). - -The related old value pointer will not be null if the specified old value was -actually copied. -This function is often only used by the code expanded by -@RefMacro{BOOST_CONTRACT_OLDOF} which is equivalent to: - -@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - -@param old Old value (usually implicitly constructed from the user old value - expression to be copied). - -@return Old value pointer (usually implicitly converted to either - @RefClass{boost::contract::old_ptr} or - @RefClass{boost::contract::old_ptr_if_copyable} in user code). -*/ -old_pointer make_old(old_value const& old) { - return old_pointer(0, old); -} - -/** -Make an old value pointer (for virtual public functions and public functions -overrides). - -The related old value pointer will not be null if the specified old value was -actually copied. -This function is often only used by the code expanded by -@RefMacro{BOOST_CONTRACT_OLDOF}. - -@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - -@param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual or overriding public function declaring - the contract. -@param old Old value (usually implicitly constructed from the user old value - expression to be copied). - -@return Old value pointer (usually implicitly converted to either - @RefClass{boost::contract::old_ptr} or - @RefClass{boost::contract::old_ptr_if_copyable} in user code). -*/ -old_pointer make_old(virtual_* v, old_value const& old) { - return old_pointer(v, old); -} - -/** -Check if old values need to be copied (but not for virtual public functions and -public function overrides). - -For example, this function always returns false when both postconditions and -exception guarantees are not being checked (see also -@RefMacro{BOOST_CONTRACT_NO_OLDS}). -This function is often only used by the code expanded by -@c BOOST_CONTRACT_OLDOF. - -@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - -@return True if old values need to be copied, false otherwise. -*/ -bool copy_old() { - #ifndef BOOST_CONTRACT_NO_OLDS - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - return !boost::contract::detail::checking::already(); - #else - return true; - #endif - #else - return false; // No post checking, so never copy old values. - #endif -} - -/** -Check if old values need to be copied (for virtual public functions and public -function overrides). - -For example, this function always returns false when both postconditions and -exception guarantees are not being checked (see also -@RefMacro{BOOST_CONTRACT_NO_OLDS}). -In addition, this function returns false when overridden functions are being -called subsequent times by this library to support subcontracting. -This function is often only used by the code expanded by -@c BOOST_CONTRACT_OLDOF. - -@see @RefSect{extras.no_macros__and_no_variadic_macros_, No Macros} - -@param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual or overriding public function declaring - the contract. - -@return True if old values need to be copied, false otherwise. -*/ -bool copy_old(virtual_* v) { - #ifndef BOOST_CONTRACT_NO_OLDS - if(!v) { - #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION - return !boost::contract::detail::checking::already(); - #else - return true; - #endif - } - return v->action_ == boost::contract::virtual_::push_old_init_copy || - v->action_ == boost::contract::virtual_::push_old_ftor_copy; - #else - return false; // No post checking, so never copy old values. - #endif -} - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/override.hpp b/include/boost/contract/override.hpp deleted file mode 100644 index 4c1585a4..00000000 --- a/include/boost/contract/override.hpp +++ /dev/null @@ -1,187 +0,0 @@ - -#ifndef BOOST_CONTRACT_OVERRIDE_HPP_ -#define BOOST_CONTRACT_OVERRIDE_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Handle public function overrides (for subcontracting). -*/ - -// IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes. -#include -#include -#include - -#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #include - #include - #include - #include - #include - - /* PRIVATE */ - - #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, \ - arity, arity_compl, function_name) \ - template< \ - class BOOST_CONTRACT_DETAIL_NAME1(B), \ - class BOOST_CONTRACT_DETAIL_NAME1(C) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, \ - BOOST_CONTRACT_DETAIL_NAME1(Args)) \ - > \ - static void BOOST_CONTRACT_DETAIL_NAME1(call_base)( \ - boost::contract::virtual_* BOOST_CONTRACT_DETAIL_NAME1(v), \ - BOOST_CONTRACT_DETAIL_NAME1(C)* BOOST_CONTRACT_DETAIL_NAME1(obj) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(z, arity, \ - BOOST_CONTRACT_DETAIL_NAME1(Args), \ - &, \ - BOOST_CONTRACT_DETAIL_NAME1(args) \ - ) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \ - boost::contract::detail::none&) \ - ) { \ - BOOST_CONTRACT_DETAIL_NAME1(obj)-> \ - BOOST_CONTRACT_DETAIL_NAME1(B)::function_name( \ - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, \ - BOOST_CONTRACT_DETAIL_NAME1(args)) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_NAME1(v) \ - ); \ - } - - #if BOOST_CONTRACT_DETAIL_TVARIADIC - #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(function_name) \ - BOOST_CONTRACT_OVERRIDE_CALL_BASE_(1, ~, ~, function_name) - #else - #include - #include - #include - - #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(function_name) \ - BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), \ - BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_, function_name) \ - - #define BOOST_CONTRACT_OVERRIDE_CALL_BASE_ARITY_(z, arity, \ - function_name) \ - BOOST_CONTRACT_OVERRIDE_CALL_BASE_(z, arity, \ - BOOST_PP_SUB(BOOST_CONTRACT_MAX_ARGS, arity), function_name) - #endif - - /* PUBLIC */ - - #define BOOST_CONTRACT_NAMED_OVERRIDE(override_name, function_name) \ - struct override_name { \ - BOOST_CONTRACT_DETAIL_MIRROR_HAS_MEMBER_FUNCTION( \ - BOOST_CONTRACT_DETAIL_NAME1(has_member_function), \ - function_name \ - ) \ - BOOST_CONTRACT_OVERRIDE_CALL_BASE_DECL_(function_name) \ - }; -#else - /** - Declare an override type with an arbitrary name. - - Declare the override type to pass as an explicit template parameter to - @RefFunc{boost::contract::public_function} for public function overrides. - - @see @RefSect{advanced.named_overrides, Named Overrides} - - @param override_name Name of the override type this macro will declare. - (This is not a variadic macro parameter but it - should never contain commas because it is an - identifier.) - @param function_name Function name of the public function override. - This macro is called just once even if the function - name is overloaded (the same override type is used - for all overloaded functions with the same name, see - @RefSect{advanced.function_overloads, - Function Overloads}). - (This is not a variadic macro parameter but it - should never contain commas because it is an - identifier.) - */ - #define BOOST_CONTRACT_NAMED_OVERRIDE(override_name, function_name) \ - struct override_name {}; /* empty (not used), just to compile */ -#endif - -/* PUBLIC */ - -/** -Declare an override type named override_function_name. - -Declare the override type to pass as an explicit template parameter to -@RefFunc{boost::contract::public_function} for public function overrides. - -@see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} - -@param function_name Function name of the public function override. - This macro is called just once even if the function - name is overloaded (the same override type is used for - all overloaded functions with the same name, see - @RefSect{advanced.function_overloads, - Function Overloads}). - (This is not a variadic macro parameter but it should - never contain any comma because it is an identifier.) -*/ -#define BOOST_CONTRACT_OVERRIDE(function_name) \ - BOOST_CONTRACT_NAMED_OVERRIDE(BOOST_PP_CAT(override_, function_name), \ - function_name) - -#if BOOST_PP_VARIADICS - #include - #include - - /* PRIVATE */ - - /** @cond */ - #define BOOST_CONTRACT_OVERRIDES_SEQ_(r, unused, function_name) \ - BOOST_CONTRACT_OVERRIDE(function_name) - /** @endcond */ - - /* PUBLIC */ - - /** - Declare multiple override types at once naming them override_... (for - convenience). - - This variadic macro is provided for convenience only, - BOOST_CONTRACT_OVERRIDES(f1, f2, ..., fn) expands to code equivalent - to: - - @code - BOOST_CONTRACT_OVERRIDE(f1) - BOOST_CONTRACT_OVERRIDE(f2) - ... - BOOST_CONTRACT_OVERRIDE(fn) - @endcode - - On compilers that do not support variadic macros, - the override types can be equivalently programmed one-by-one calling - @RefMacro{BOOST_CONTRACT_OVERRIDE} for each function name as shown above. - - @see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} - - @param ... A comma separated list of one or more function names of public - function overrides. - (Each function name should never contain commas because it is an - identifier.) - */ - #define BOOST_CONTRACT_OVERRIDES(...) \ - BOOST_PP_SEQ_FOR_EACH(BOOST_CONTRACT_OVERRIDES_SEQ_, ~, \ - BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) -#else - #define BOOST_CONTRACT_OVERRIDES \ -BOOST_CONTRACT_ERROR_macro_OVERRIDES_requires_variadic_macros_otherwise_manually_repeat_OVERRIDE_macro -#endif - -#endif // #include guard - diff --git a/include/boost/contract/public_function.hpp b/include/boost/contract/public_function.hpp deleted file mode 100644 index 8bbcf7b4..00000000 --- a/include/boost/contract/public_function.hpp +++ /dev/null @@ -1,610 +0,0 @@ - -#ifndef BOOST_CONTRACT_PUBLIC_FUNCTION_HPP_ -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Program contracts for public functions (including subcontracting). -Overloads handle public functions that are static, virtual void, virtual non-void, overriding void, and overriding non-void. -*/ - -#include -#include -#include -#include -/** @cond */ -// Needed within macro expansions below instead of defined(...) (PRIVATE macro). -#if !defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS) || \ - defined(BOOST_CONTRACT_STATIC_LINK) - #define BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_ 1 -#else - #define BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_ 0 -#endif -/** @endcond */ -#include -#include -#if BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_ - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include -#endif -#if !BOOST_CONTRACT_DETAIL_TVARIADIC - #include - #include - #include -#endif -#include -#include -#include - -namespace boost { namespace contract { - -// NOTE: Override and (optionally) VirtualResult allowed only when v is present -// because: -// * An overriding func must override a base func declared virtual so with -// v extra param, thus the overriding func must also always have v (i.e., -// Override might be present only if v is also present). However, the first -// appearing virtual func (e.g., in root class) will not override any -// previously declared virtual func so does not need Override (i.e., Override -// always optional). -// Furthermore, F needs to be specified only together with Override. -// * VirtualResult is only used for virtual functions (i.e., VirtualResult might -// be present only if v is also present). -// However, VirtualResult is never specified, not even for virtual functions, -// when the return type is void (i.e., VirtualResult always optional). - -/** -Program contracts for static public functions. - -This is used to specify preconditions, postconditions, exception guarantees, old -value copies at body, and check static class invariants for static public -functions. - -For optimization, this can be omitted for static public functions that do not -have preconditions, postconditions and exception guarantees, within classes that -have no static invariants. - -@see @RefSect{tutorial.static_public_functions, Static Public Functions} - -@tparam Class The type of the class containing the static public function - declaring the contract. - This template parameter must be explicitly specified for static - public functions (because they have no object @c this so there - is no function argument from which this type template parameter - can be automatically deduced by C++). - -@return The result of this function must be explicitly assigned to a variable of - type @RefClass{boost::contract::check} declared locally just before the - code of the static function body (otherwise this library will generate a - run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). -*/ -template -specify_precondition_old_postcondition_except<> public_function() { - #if BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_ - return specify_precondition_old_postcondition_except<>( - new boost::contract::detail::static_public_function()); - #else - return specify_precondition_old_postcondition_except<>(); - #endif -} - -/** -Program contracts for public functions that are not static, not virtual, and do -not not override. - -This is used to specify preconditions, postconditions, exception guarantees, old -value copies at body, and check class invariants for public functions that are -not static, not virtual, and do not override. - -For optimization, this can be omitted for public functions that do not have -preconditions, postconditions and exception guarantees, within classes that have -no invariants. - -@see @RefSect{tutorial.public_functions, Public Functions} - -@param obj The object @c this from the scope of the enclosing public function - declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the enclosing - function (volatile virtual public functions will check volatile - class invariants, see - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - -@tparam Class The type of the class containing the public function declaring - the contract. - (Usually this template parameter is automatically deduced by C++ - and it does not need to be explicitly specified by programmers.) - -@return The result of this function must be explicitly assigned to a variable of - type @RefClass{boost::contract::check} declared locally just before the - code of the public function body (otherwise this library will generate a - run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). -*/ -template -specify_precondition_old_postcondition_except<> public_function(Class* obj) { - #if BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_ - return specify_precondition_old_postcondition_except<>( - new boost::contract::detail::public_function< - boost::contract::detail::none, - boost::contract::detail::none, - boost::contract::detail::none, - Class - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA( - BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(1, - BOOST_CONTRACT_MAX_ARGS, - boost::contract::detail::none - ) - >( - static_cast(0), - obj, - boost::contract::detail::none::value() - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA( - BOOST_CONTRACT_MAX_ARGS) - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(1, - BOOST_CONTRACT_MAX_ARGS, - boost::contract::detail::none::value() - ) - ) - ); - #else - return specify_precondition_old_postcondition_except<>(); - #endif -} - -/** @cond */ - -// For non-static, virtual, and non-overriding public functions (PRIVATE macro). -#define BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_NO_OVERRIDE_( \ - has_virtual_result) \ - template< \ - BOOST_PP_EXPR_IIF(has_virtual_result, typename VirtualResult) \ - BOOST_PP_COMMA_IF(has_virtual_result) \ - class Class \ - > \ - specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)> \ - public_function( \ - virtual_* v \ - BOOST_PP_COMMA_IF(has_virtual_result) \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult& r) \ - , Class* obj \ - ) { \ - BOOST_PP_IIF(BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_, \ - /* no F... so cannot enforce contracted F returns VirtualResult */ \ - return (specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>( \ - new boost::contract::detail::public_function< \ - boost::contract::detail::none, \ - BOOST_PP_IIF(has_virtual_result, \ - VirtualResult \ - , \ - boost::contract::detail::none \ - ), \ - boost::contract::detail::none, \ - Class \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA( \ - BOOST_CONTRACT_MAX_ARGS) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(1, \ - BOOST_CONTRACT_MAX_ARGS, \ - boost::contract::detail::none \ - ) \ - >( \ - v, \ - obj, \ - BOOST_PP_IIF(has_virtual_result, \ - r \ - , \ - boost::contract::detail::none::value() \ - ) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA( \ - BOOST_CONTRACT_MAX_ARGS) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(1, \ - BOOST_CONTRACT_MAX_ARGS, \ - boost::contract::detail::none::value() \ - ) \ - ) \ - )); \ - , \ - return specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>(); \ - ) \ - } - -/** @endcond */ - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Program contracts for void virtual public functions that do not override. - - This is used to specify preconditions, postconditions, exception guarantees, - old value copies at body, and check class invariants for public functions - that are virtual, do not override, and return @c void. - - A virtual public function should always call - @RefFunc{boost::contract::public_function} otherwise this library will not - be able to correctly use it for subcontracting. - - @see @RefSect{tutorial.virtual_public_functions, Virtual Public Functions} - - @param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value - @c 0 from the enclosing virtual public function. - @param obj The object @c this from the scope of the enclosing virtual - public function declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the - enclosing function (volatile public functions will check - volatile class invariants, see - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - - @tparam Class The type of the class containing the virtual public function - declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers.) - - @return The result of this function must be explicitly assigned to a - variable of type @RefClass{boost::contract::check} declared locally - just before the code of the public function body (otherwise this - library will generate a run-time error, see - @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). - */ - template - specify_precondition_old_postcondition_except<> public_function( - virtual_* v, Class* obj); - - /** - Program contracts for non-void virtual public functions that do not - override. - - This is used to specify preconditions, postconditions, exception guarantees, - old value copies at body, and check class invariants for public functions - that are virtual, do not override, and do not return @c void. - - A virtual public function should always call - @RefFunc{boost::contract::public_function} otherwise this library will not - be able to correctly use it for subcontracting. - - @see @RefSect{tutorial.virtual_public_functions, Virtual Public Functions} - - @param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value - @c 0 from the enclosing virtual public function. - @param r A reference to the return value of the enclosing virtual public - function declaring the contract. - This is usually a local variable declared by the enclosing - virtual public function just before the contract, but - programmers must set it to the actual value being returned by - the function at each @c return statement. - @param obj The object @c this from the scope of the enclosing virtual - public function declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the - enclosing function (volatile public functions will check - volatile class invariants, see - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - - @tparam VirtualResult This type must be the same as, or compatible with, - the return type of the enclosing virtual public - function declaring the contract (this library might - not be able to generate a compile-time error if - these types mismatch, but in general that will cause - run-time errors or undefined behaviour). - Alternatively, - boost::optional<return-type> can also - be used (see - @RefSect{advanced.optional_return_value, - Optional Return Value}). - (Usually this template parameter is automatically - deduced by C++ and it does not need to be explicitly - specified by programmers.) - @tparam Class The type of the class containing the virtual public function - declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers.) - - @return The result of this function must be explicitly assigned to a - variable of type @RefClass{boost::contract::check} declared locally - just before the code of the public function body (otherwise this - library will generate a run-time error, see - @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). - */ - template - specify_precondition_old_postcondition_except - public_function(virtual_* v, VirtualResult& r, Class* obj); -#else - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_NO_OVERRIDE_( - /* has_virtual_result = */ 0) - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_NO_OVERRIDE_( - /* has_virtual_result = */ 1) -#endif - -/** @cond */ - -// For non-static, virtual, and overriding public functions (PRIVATE macro). -#define BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_( \ - z, arity, arity_compl, has_virtual_result) \ - BOOST_CONTRACT_DETAIL_DECL_OVERRIDING_PUBLIC_FUNCTION_Z(z, \ - arity, /* is_friend = */ 0, has_virtual_result, \ - Override, VirtualResult, F, Class, Args, \ - v, r, f, obj, args \ - ) { \ - BOOST_PP_IIF(BOOST_CONTRACT_PUBLIC_FUNCTIONS_IMPL_, \ - /* this assert not strictly necessary as compilation will fail */ \ - /* anyways, but helps limiting cryptic compiler's errors */ \ - BOOST_STATIC_ASSERT_MSG( \ - /* -2 for both `this` and `virtual_*` extra parameters */ \ - boost::function_types::function_arity::value - 2 == \ - BOOST_CONTRACT_DETAIL_TVARIADIC_SIZEOF(arity, Args), \ - "missing one or more arguments for specified function" \ - ); \ - /* assert consistency of F's result type and VirtualResult */ \ - BOOST_PP_IIF(has_virtual_result, \ - BOOST_STATIC_ASSERT_MSG \ - , \ - BOOST_PP_TUPLE_EAT(2) \ - )( \ - (boost::is_same< \ - typename boost::remove_reference::type>::type, \ - typename boost::contract::detail:: \ - remove_value_reference_if_optional::type\ - >::value), \ - "mismatching result type for specified function" \ - ); \ - /* assert this so lib can check and enforce override */ \ - BOOST_STATIC_ASSERT_MSG( \ - boost::contract::access::has_base_types::value, \ - "enclosing class missing 'base-types' typedef" \ - ); \ - return (specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>( \ - new boost::contract::detail::public_function< \ - Override, \ - BOOST_PP_IIF(has_virtual_result, \ - VirtualResult \ - , \ - boost::contract::detail::none \ - ), \ - F, \ - Class \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, Args) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \ - boost::contract::detail::none) \ - >( \ - v, \ - obj, \ - BOOST_PP_IIF(has_virtual_result, \ - r \ - , \ - boost::contract::detail::none::value() \ - ) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(arity) \ - BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(z, arity, args) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_COMMA(arity_compl) \ - BOOST_CONTRACT_DETAIL_NO_TVARIADIC_ENUM_Z(z, arity_compl, \ - boost::contract::detail::none::value()) \ - ) \ - )); \ - , \ - return specify_precondition_old_postcondition_except< \ - BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>(); \ - ) \ - } - -/** @endcond */ - -#ifdef BOOST_CONTRACT_DETAIL_DOXYGEN - /** - Program contracts for void public functions overrides (virtual or not). - - This is used to specify preconditions, postconditions, exception guarantees, - old value copies at body, and check class invariants for public function - overrides (virtual or not) that return @c void. - - A public function override should always call - @RefFunc{boost::contract::public_function} otherwise this library will not - be able to correctly use it for subcontracting. - - @see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} - - @param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value - @c 0 from the enclosing public function override. - @param f A pointer to the enclosing public function override declaring - the contract. - @param obj The object @c this from the scope of the enclosing public - function override declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the - enclosing function (volatile public functions will check - volatile class invariants, see - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - @param args All arguments passed to the enclosing public function override - declaring the contract (by reference and in the order they - appear in the enclosing function declaration), but excluding the - trailing argument @c v. - - @tparam Override The type override_function-name declared - using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or related - macros. - This template parameter must be explicitly specified - (because there is no function argument from which it can - be automatically deduced by C++). - @tparam F The function pointer type of the enclosing public function - override declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers, but see - @RefSect{advanced.function_overloads, Function Overloads}.) - @tparam Class The type of the class containing the virtual public function - declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers.) - @tparam Args The types of all parameters passed to the enclosing public - function override declaring the contract, but excluding the - trailing parameter type boost::contract::virtual_*. - On compilers that do not support variadic templates, this - library internally implements this function using - preprocessor meta-programming (in this case, the maximum - number of supported arguments is defined by - @RefMacro{BOOST_CONTRACT_MAX_ARGS}). - (Usually these template parameters are automatically deduced - by C++ and they do not need to be explicitly specified by - programmers.) - - @return The result of this function must be explicitly assigned to a - variable of type @RefClass{boost::contract::check} declared locally - just before the code of the public function body (otherwise this - library will generate a run-time error, see - @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). - */ - template - specify_precondition_old_postcondition_except<> public_function( - virtual_* v, F f, Class* obj, Args&... args); - - /** - Program contracts for non-void public functions overrides (virtual or not). - - This is used to specify preconditions, postconditions, exception guarantees, - old value copies at body, and check class invariants for public function - overrides (virtual or not) that do not return @c void. - - A public function override should always call - @RefFunc{boost::contract::public_function} otherwise this library will not - be able to correctly use it for subcontracting. - - @see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides} - - @param v The trailing parameter of type - @RefClass{boost::contract::virtual_}* and default value - @c 0 from the enclosing public function override. - @param r A reference to the return value of the enclosing public function - override declaring the contract. - This is usually a local variable declared by the enclosing - public function override just before the contract, but - programmers must set it to the actual value being returned by - the function at each @c return statement. - @param f A pointer to the enclosing public function override declaring - the contract. - @param obj The object @c this from the scope of the enclosing public - function override declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the - enclosing function (volatile public functions will check - volatile class invariants, see - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - @param args All arguments passed to the enclosing public function override - declaring the contract (by reference and in the order they - appear in the enclosing function declaration), but excluding the - trailing argument @c v. - - @tparam Override The type override_function-name declared - using the @RefMacro{BOOST_CONTRACT_OVERRIDE} or related - macros. - This template parameter must be explicitly specified - (because there is no function argument from which it can - be automatically deduced by C++). - @tparam VirtualResult This type must be the same as, or compatible with, - the return type of the enclosing public function - override declaring the contract (this library might - not be able to generate a compile-time error if - these types mismatch, but in general that will cause - run-time errors or undefined behaviour). - Alternatively, - boost::optional<return-type> can also - be used (see - @RefSect{advanced.optional_return_value, - Optional Return Value}). - (Usually this template parameter is automatically - deduced by C++ and it does not need to be explicitly - specified by programmers.) - @tparam F The function pointer type of the enclosing public function - override declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers, but see - @RefSect{advanced.function_overloads, - Function Overloads}.) - @tparam Class The type of the class containing the virtual public function - declaring the contract. - (Usually this template parameter is automatically deduced by - C++ and it does not need to be explicitly specified by - programmers.) - @tparam Args The types of all parameters passed to the enclosing public - function override declaring the contract, but excluding the - trailing parameter type boost::contract::virtual_*. - On compilers that do not support variadic templates, this - library internally implements this function using - preprocessor meta-programming (in this case, the maximum - number of supported arguments is defined by - @RefMacro{BOOST_CONTRACT_MAX_ARGS}). - (Usually these template parameters are automatically deduced - by C++ and they do not need to be explicitly specified by - programmers.) - - @return The result of this function must be explicitly assigned to a - variable of type @RefClass{boost::contract::check} declared locally - just before the code of the public function body (otherwise this - library will generate a run-time error, see - @RefMacro{BOOST_CONTRACT_ON_MISSING_CHECK_DECL}). - */ - template - specify_precondition_old_postcondition_except - public_function(virtual_* v, VirtualResult& r, F f, Class* obj, - Args&... args); -#elif BOOST_CONTRACT_DETAIL_TVARIADIC - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_(1, /* arity = */ ~, - /* arity_compl = */ ~, /* has_virtual_result = */ 0) - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_(1, /* arity = */ ~, - /* arity_compl = */ ~, /* has_virtual_result = */ 1) -#else - /* PRIVATE */ - - #define BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_ARITY_( \ - z, arity, unused) \ - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDES_(z, arity, \ - BOOST_PP_SUB(BOOST_CONTRACT_MAX_ARGS, arity), ~) - - #define BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDES_(z, \ - arity, arity_compl, unused) \ - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_(z, \ - arity, arity_compl, /* has_virtual_result = */ 0) \ - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_(z, \ - arity, arity_compl, /* has_virtual_result = */ 1) - - /* CODE */ - - BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_CONTRACT_MAX_ARGS), - BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_ARITY_, ~) -#endif - -} } // namespace - -#endif // #include guard - diff --git a/include/boost/contract_macro.hpp b/include/boost/contract_macro.hpp deleted file mode 100644 index e8f6bdb4..00000000 --- a/include/boost/contract_macro.hpp +++ /dev/null @@ -1,895 +0,0 @@ - -#ifndef BOOST_CONTRACT_MACRO_HPP_ -#define BOOST_CONTRACT_MACRO_HPP_ - -// Copyright (C) 2008-2017 Lorenzo Caminiti -// Distributed under the Boost Software License, Version 1.0 (see accompanying -// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). -// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html - -/** @file -Completely disable compile-time and run-time overhead introduced by contracts. -This header also includes all headers file boost/contract/\*.hpp that are -necessary to use its macros. - -Almost all the macros defined in this header file are variadic macros. On -compilers that do not support variadic macros, programmers can manually code -\#ifndef BOOST_CONTRACT_NO_... statements instead (see -@RefSect{extras.disable_contract_compilation__macro_interface_, -Disable Contract Compilation}). -*/ - -// IMPORTANT: Following headers can always be #included (without any #if-guard) -// because they expand to trivial code that does not affect compile-time. These -// headers must always be #included here (without any #if-guard) because they -// define types and macros that are typically left in user code even when -// contracts are disables (these types and macros never affect run-time and -// their definitions are trivial when contracts are disabled so their impact on -// compile-time is negligible). -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef BOOST_CONTRACT_NO_CONDITIONS - #include -#endif - -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS - #define BOOST_CONTRACT_PRECONDITION(...) .precondition(__VA_ARGS__) -#else - /** - Program preconditions that can be completely disabled at compile-time. - - @c BOOST_CONTRACT_PRECONDITION(f) expands to code equivalent to the - following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - .precondition(f) - #endif - @endcode - - Where: - - @arg f is the nullay functor called by this library to - check preconditions @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this functor indicates a contract assertion failure (and will - result in this library calling - @RefFunc{boost::contract::precondition_failure}). - This functor should capture variables by (constant) value, or better - by (constant) reference (to avoid extra copies). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.preconditions, Preconditions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_PRECONDITION(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - #define BOOST_CONTRACT_POSTCONDITION(...) .postcondition(__VA_ARGS__) -#else - /** - Program postconditions that can be completely disabled at compile-time. - - @c BOOST_CONTRACT_POSTCONDITION(f) expands to code equivalent to the - following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - .postcondition(f) - #endif - @endcode - - Where: - - @arg f is the functor called by this library to check - postconditions f(...). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this functor indicates a contract assertion failure (and will - result in this library calling - @RefFunc{boost::contract::postcondition_failure}). - This functor should capture variables by (constant) references (to - access the values they will have at function exit). - This functor takes the return value as its one single parameter but - only for virtual public functions and public functions overrides, - otherwise it takes no parameter. - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.postconditions, Postconditions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_POSTCONDITION(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_EXCEPTS - #define BOOST_CONTRACT_EXCEPT(...) .except(__VA_ARGS__) -#else - /** - Program exception guarantees that can be completely disabled at - compile-time. - - @c BOOST_CONTRACT_EXCEPT(f) expands to code equivalent to the following - (note that no code is generated when @RefMacro{BOOST_CONTRACT_NO_EXCEPTS} - is defined): - - @code - #ifndef BOOST_CONTRACT_NO_EXCEPTS - .except(f) - #endif - @endcode - - Where: - - @arg f is the nullary functor called by this library to - check exception guarantees @c f(). - Assertions within this functor are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this functor indicates a contract assertion failure (and will - result in this library calling - @RefFunc{boost::contract::except_failure}). - This functor should capture variables by (constant) references (to - access the values they will have at function exit). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.exception_guarantees, Exception Guarantees}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_EXCEPT(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_OLDS - #include - #include - #include - #include - - /* PRIVATE */ - - #define BOOST_CONTRACT_OLD_VAR_1(ptr) \ - ptr - #define BOOST_CONTRACT_OLD_VAR_2(ptr, expr) \ - ptr = BOOST_CONTRACT_OLDOF(expr) - #define BOOST_CONTRACT_OLD_VAR_3(v, ptr, expr) \ - ptr = BOOST_CONTRACT_OLDOF(v, expr) - - #define BOOST_CONTRACT_OLD_VAR_(...) \ - BOOST_PP_CAT(BOOST_PP_OVERLOAD(BOOST_CONTRACT_OLD_VAR_, __VA_ARGS__) \ - (__VA_ARGS__), BOOST_PP_EMPTY()) - - /* PUBLIC */ - - #define BOOST_CONTRACT_OLD(...) .old(__VA_ARGS__) - - #define BOOST_CONTRACT_OLD_PTR(...) \ - boost::contract::old_ptr< __VA_ARGS__ > \ - BOOST_CONTRACT_OLD_VAR_ - - #define BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...) \ - boost::contract::old_ptr_if_copyable< __VA_ARGS__ > \ - BOOST_CONTRACT_OLD_VAR_ -#else - #include - - /** - Program old copies at body that can be completely disabled at compile-time. - - @c BOOST_CONTRACT_OLD(f) expands to code equivalent to the following (note - that no code is generated when @RefMacro{BOOST_CONTRACT_NO_OLDS} is - defined): - - @code - #ifndef BOOST_CONTRACT_NO_OLDS - .old(f) - #endif - @endcode - - Where: - - @arg f is the nullary functor called by this library - @c f() to assign old value copies just before the body is execute - but after entry invariants (when they apply) and preconditions are - checked. - Old value pointers within this functor call are usually assigned - using @RefMacro{BOOST_CONTRACT_OLDOF}. - Any exception thrown by a call to this functor will result in - this library calling @RefFunc{boost::contract::old_failure} (because - old values could not be copied to check postconditions and exception - guarantees). - This functor should capture old value pointers by references so they - can be assigned (all other variables needed to evaluate old value - expressions can be captured by (constant) value, or better by - (constant) reference to avoid extra copies). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{advanced.old_copies_at_body, Old Copies at Body}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_OLD(...) /* nothing */ - - /** - Program old values that can be completely disabled at compile-time (requires - the old value type to be copyable). - - This is an overloaded variadic macro and it can be used in the following - different ways (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_OLDS} is defined). - - 1\. BOOST_CONTRACT_OLD_PTR(T)(ptr) expands to code equivalent - to the following (this leaves the old value pointer null): - - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr ptr // This never uses `v`. - #endif - @endcode - - 2\. BOOST_CONTRACT_OLD_PTR(T)(ptr, expr) expands to code equivalent - to the following (this initializes the pointer to the old value copy, - but not to be used for virtual public functions and public function - overrides): - - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr ptr = BOOST_CONTRACT_OLDOF(expr) - #endif - @endcode - - 3\. BOOST_CONTRACT_OLD_PTR(T)(v, ptr, expr) expands to code - equivalent to the following (this initializes the pointer to the old - value copy for virtual public functions and public function overrides): - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr ptr = BOOST_CONTRACT_OLDOF(v, expr) - #endif - @endcode - - Where: - - @arg T is the type of the pointed old value. - This type must be copyable (i.e., - boost::contract::is_old_value_copyable::value is @c true), - otherwise this pointer will always be null and this library will - generate a compile-time error when the pointer is dereferenced - (but see @RefMacro{BOOST_CONTRACT_OLD_PTR_IF_COPYABLE}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg v is the extra parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual public function or public function - override declaring the contract. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - BOOST_CONTRACT_OLD_PTR(T)((v), ptr, expr) will always work.) - @arg ptr is the name of the old value pointer variable. - (This is not a variadic macro parameter but it should never contain - commas because it is an identifier.) - @arg expr is the expression to be evaluated and copied in - the old value pointer. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - BOOST_CONTRACT_OLD_PTR(T)(v, ptr, (expr)) will always work.) - - @see @RefSect{tutorial.old_values, Old Values}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_OLD_PTR(...) BOOST_PP_TUPLE_EAT(0) - - /** - Program old values that can be completely disabled at compile-time (does not - require the old value type to be copyable). - - This is an overloaded variadic macro and it can be used in the following - different ways (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_OLDS} is defined). - - 1\. BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(T)(ptr) expands to code - equivalent to the following (this leaves the old value pointer null): - - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr_if_copyable ptr // This never uses `v`. - #endif - @endcode - - 2\. BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(T)(ptr, expr) expands to code - equivalent to the following (this initializes the pointer to the old - value copy, but not to be used for virtual public functions and public - function overrides): - - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr_if_copyable ptr = BOOST_CONTRACT_OLDOF(expr) - #endif - @endcode - - 3\. BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(T)(v, ptr, expr) expands to - code equivalent to the following (this initializes the pointer to the - old value copy for virtual public functions and public function - overrides): - @code - #ifndef BOOST_CONTRACT_NO_OLDS - boost::contract::old_ptr_if_copyable ptr = - BOOST_CONTRACT_OLDOF(v, expr) - #endif - @endcode - - Where: - - @arg T is the type of the pointed old value. - If this type is not copyable (i.e., - boost::contract::is_old_value_copyable::value is - @c false), this pointer will always be null, but this library will - not generate a compile-time error when this pointer is dereferenced - (but see @RefMacro{BOOST_CONTRACT_OLD_PTR}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg v is the extra parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual public function or public function - override declaring the contract. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(T)((v), ptr, expr) will - always work.) - @arg ptr is the name of the old value pointer variable. - (This is not a variadic macro parameter but it should never contain - commas because it is an identifier.) - @arg expr is the expression to be evaluated and copied in - the old value pointer. - (This is not a variadic macro parameter so any comma it might - contain must be protected by round parenthesis, - BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(T)(v, ptr, (expr)) will - always work.) - - @see @RefSect{extras.old_value_requirements__templates_, - Old Value Requirements}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...) BOOST_PP_TUPLE_EAT(0) -#endif - -#ifndef BOOST_CONTRACT_NO_INVARIANTS - #include - - #define BOOST_CONTRACT_INVARIANT(...) \ - void BOOST_CONTRACT_INVARIANT_FUNC() const __VA_ARGS__ - - #define BOOST_CONTRACT_INVARIANT_VOLATILE(...) \ - void BOOST_CONTRACT_INVARIANT_FUNC() const volatile __VA_ARGS__ - - #define BOOST_CONTRACT_STATIC_INVARIANT(...) \ - static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() __VA_ARGS__ -#else - /** - Program (constant) class invariants that can be completely disabled at - compile-time. - - @c BOOST_CONTRACT_INVARIANT({ ... }) expands to code equivalent to the - following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_INVARIANTS - void BOOST_CONTRACT_INVARIANT_FUNC() const { - ... - } - #endif - @endcode - - Where: - - @arg { ... } is the definition of the function that checks class - invariants for public functions that are not static and not volatile - (see @RefMacro{BOOST_CONTRACT_STATIC_INVARIANT} and - @RefMacro{BOOST_CONTRACT_INVARIANT_VOLATILE}). - Assertions within this function are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this function indicates a contract assertion failure (and will - result in this library calling either - @RefFunc{boost::contract::entry_invariant_failure} or - @RefFunc{boost::contract::exit_invariant_failure}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_INVARIANT(...) /* nothing */ - - /** - Program volatile class invariants that can be completely disabled at - compile-time. - - @c BOOST_CONTRACT_INVARIANT_VOLATILE({ ... }) expands to code equivalent to - the following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_INVARIANTS - void BOOST_CONTRACT_INVARIANT_FUNC() const volatile { - ... - } - #endif - @endcode - - Where: - - @arg { ... } is the definition of the function that checks class - invariants for volatile public functions - (see @RefMacro{BOOST_CONTRACT_INVARIANT} and - @RefMacro{BOOST_CONTRACT_STATIC_INVARIANT}). - Assertions within this function are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this function indicates a contract assertion failure (and will - result in this library calling either - @RefFunc{boost::contract::entry_invariant_failure} or - @RefFunc{boost::contract::exit_invariant_failure}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{extras.volatile_public_functions, - Volatile Public Functions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_INVARIANT_VOLATILE(...) /* nothing */ - - /** - Program static class invariants that can be completely disabled at - compile-time. - - @c BOOST_CONTRACT_STATIC_INVARIANT({ ... }) expands to code equivalent to - the following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_INVARIANTS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_INVARIANTS - static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() { - ... - } - #endif - @endcode - - Where: - - @arg { ... } is the definition of the function that checks class - invariants for static public functions - (see @RefMacro{BOOST_CONTRACT_INVARIANT} and - @RefMacro{BOOST_CONTRACT_INVARIANT_VOLATILE}). - Assertions within this function are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this function indicates a contract assertion failure (and will - result in this library calling either - @RefFunc{boost::contract::entry_invariant_failure} or - @RefFunc{boost::contract::exit_invariant_failure}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.class_invariants, Class Invariants}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_STATIC_INVARIANT(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - #include - #include - #include - - #define BOOST_CONTRACT_CONSTRUCTOR(...) \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::constructor(__VA_ARGS__) -#else - /** - Program contracts that can be completely disabled at compile-time for - constructors. - - @c BOOST_CONTRACT_CONSTRUCTOR(obj) expands to code equivalent to the - following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_CONSTRUCTORS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::check internal_var = boost::contract:: - constructor(obj) - #endif - @endcode - - Where: - - @arg obj is the object @c this from the scope of the - enclosing constructor declaring the contract. - Constructors check all class invariants, including static and - volatile invariants (see @RefSect{tutorial.class_invariants, - Class Invariants} and - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.constructors, Constructors}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation}, - @RefMacro{BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION} - */ - #define BOOST_CONTRACT_CONSTRUCTOR(...) /* nothing */ -#endif -#ifndef BOOST_CONTRACT_NO_PRECONDITIONS // Do not check NO_CONSTRUCTORS here. - // constructor_precondition.hpp already #included at top. - - #define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...) \ - boost::contract::constructor_precondition< __VA_ARGS__ > -#else - #include - // constructor_precondition.hpp always #included at top of this file. - - /** - Program preconditions that can be disabled at compile-time for constructors. - - BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(Class)(f) expands - to code equivalent to the following (note that when - @RefMacro{BOOST_CONTRACT_NO_PRECONDITIONS} is defined, this macro trivially - expands to a default constructor call that is internally implemented to do - nothing so this should have minimal to no overhead): - - @code - // Guarded only by NO_PRECONDITIONS (and not also by NO_CONSTRUCTORS) - // because for constructor's preconditions (not for postconditions, etc.). - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - boost::contract::constructor_precondition(f) - #else - // No-op call (likely optimized away, minimal to no overhead). - boost::contract::constructor_precondition() - #endif - - @endcode - - Where: - - @arg Class is the type of the class containing the - constructor for which preconditions are being programmed. - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg f is the nullary functor called by this library to - check constructor preconditions @c f(). - Assertions within this functor call are usually programmed using - @RefMacro{BOOST_CONTRACT_ASSERT}, but any exception thrown by a call - to this functor indicates a contract failure (and will result in - this library calling - @RefFunc{boost::contract::precondition_failure}). - This functor should capture variables by (constant) value, or better - by (constant) reference to avoid extra copies. - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - - @see @RefSect{tutorial.constructors, Constructors}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation}, - @RefMacro{BOOST_CONTRACT_CONSTRUCTOR} - */ - #define BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...) \ - /* always use default ctor (i.e., do nothing) */ \ - boost::contract::constructor_precondition< __VA_ARGS__ >() \ - BOOST_PP_TUPLE_EAT(0) -#endif - -#ifndef BOOST_CONTRACT_NO_DESTRUCTORS - #include - #include - #include - - #define BOOST_CONTRACT_DESTRUCTOR(...) \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::destructor(__VA_ARGS__) -#else - /** - Program contracts that can be completely disabled at compile-time for - destructors. - - @c BOOST_CONTRACT_DESTRUCTOR(obj) expands to code equivalent to the - following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_DESTRUCTORS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - boost::contract::check internal_var = boost::contract:: - destructor(obj) - #endif - @endcode - - Where: - - @arg obj is the object @c this from the scope of the - enclosing destructor declaring the contract. - Destructors check all class invariants, including static and - volatile invariants (see @RefSect{tutorial.class_invariants, - Class Invariants} and - @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.destructors, Destructors}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_DESTRUCTOR(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - #include - #include - #include - - #define BOOST_CONTRACT_PUBLIC_FUNCTION(...) \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::public_function(__VA_ARGS__) - - #define BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...) \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::public_function<__VA_ARGS__> - - #define BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...) \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::public_function< __VA_ARGS__ >() -#else - #include - - /** - Program contracts that can be completely disabled at compile-time for - non-static public functions (virtual or not) that do not override. - - This is an overloaded variadic macro and it can be used in the following - different ways (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined). - - 1\. BOOST_CONTRACT_PUBLIC_FUNCTION(obj) expands to code - equivalent to the following (for non-virtual public functions that are - not static and do not override, returning void or not): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function(obj) - #endif - @endcode - - 2\. BOOST_CONTRACT_PUBLIC_FUNCTION(v, obj) expands to code - equivalent to the following (for virtual public functions that are - not static and do not override, returning void): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function(v, obj) - #endif - @endcode - - 3\. BOOST_CONTRACT_PUBLIC_FUNCTION(v, r, obj) expands to code - equivalent to the following (for virtual public functions that are - not static and do not override, not returning void): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function(v, r, obj) - #endif - @endcode - - Where (these are all variadic macro parameters so they can contain commas - not protected by round parenthesis): - - @arg v is the extra parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual public function declaring the contract. - @arg r is a reference to the return value of the enclosing - virtual public function declaring the contract. - This is usually a local variable declared by the enclosing virtual - public function just before the contract, but programmers must set - it to the actual value being returned by the function at each - @c return statement. - @arg obj is the object @c this from the scope of the - enclosing public function declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the enclosing - function (volatile public functions will check volatile class - invariants, see @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.public_functions, Public Functions}, - @RefSect{tutorial.virtual_public_functions, - Virtual Public Functions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_PUBLIC_FUNCTION(...) /* nothing */ - - /** - Program contracts that can be completely disabled at compile-time for - public function overrides (virtual or not). - - This is an overloaded variadic macro and it can be used in the following - different ways (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined). - - 1\. BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(Override)(v, f, obj, ...) - expands to code equivalent to the following (for public function - overrides that return void): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function(v, f, obj, ...) - #endif - @endcode - - 2\. BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(Override)(v, r, f, obj, ...) - expands to code equivalent to the following (for public function - overrides that do not return void): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function(v, r, f, obj, ...) - #endif - @endcode - - Where (these are all variadic macro parameters so they can contain commas - not protected by round parenthesis): - - @arg Override is the type - override_function-name declared using the - @RefMacro{BOOST_CONTRACT_OVERRIDE} or related macros. - @arg v is the extra parameter of type - @RefClass{boost::contract::virtual_}* and default value @c 0 - from the enclosing virtual public function declaring the contract. - @arg r is a reference to the return value of the enclosing - virtual public function declaring the contract. - This is usually a local variable declared by the enclosing virtual - public function just before the contract, but programmers must set - it to the actual value being returned by the function at each - @c return statement. - @arg f is a pointer to the enclosing public function - override declaring the contract. - @arg obj is the object @c this from the scope of the - enclosing public function declaring the contract. - This object might be mutable, @c const, @c volatile, or - const volatile depending on the cv-qualifier of the enclosing - function (volatile public functions will check volatile class - invariants, see @RefSect{extras.volatile_public_functions, - Volatile Public Functions}). - @arg ... is a variadic macro parameter listing all the - arguments passed to the enclosing public function override declaring - the contract (by reference and in order they appear in the enclosing - function declaration), but excluding the trailing argument @c v. - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.public_function_overrides__subcontracting_, - Public Function Overrides}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...) \ - BOOST_PP_TUPLE_EAT(0) - - /** - Program contracts that can be completely disabled at compile-time for static - public functions. - - @c BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(Class) expands to code equivalent - to the following (note that no code is generated when - @RefMacro{BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS} is defined): - - @code - #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - public_function() - #endif - @endcode - - Where: - - @arg Class is the type of the class containing the - static public function declaring the contract. - (This is a variadic macro parameter so it can contain commas not - protected by round parenthesis.) - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.static_public_functions, Static Public Functions}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...) /* nothing */ -#endif - -#ifndef BOOST_CONTRACT_NO_FUNCTIONS - #include - #include - #include - - #define BOOST_CONTRACT_FUNCTION() \ - boost::contract::check BOOST_CONTRACT_DETAIL_NAME2(c, __LINE__) = \ - boost::contract::function() -#else - #include - - /** - Program contracts that can be completely disabled at compile-time for - (non-public) functions. - - This can be used to program contracts for non-member functions but also for - private and protected functions, lambda functions, loops, arbitrary blocks - of code, etc. - - @c BOOST_CONTRACT_FUNCTION() expands to code equivalent to the following - (note that no code is generated when @RefMacro{BOOST_CONTRACT_NO_FUNCTIONS} - is defined): - - @code - #ifndef BOOST_CONTRACT_NO_FUNCTIONS - boost::contract::check internal_var = boost::contract:: - function() - #endif - @endcode - - Where: - - @arg internal_var is a variable name internally generated - by this library (this name is unique but only on different line - numbers so this macro cannot be expanded multiple times on the same - line). - - @see @RefSect{tutorial.non_member_functions, Non-Member Functions}, - @RefSect{advanced.private_and_protected_functions, - Private and Protected Functions}, - @RefSect{advanced.lambdas__loops__code_blocks__and__constexpr__, - Lambdas\, Loops\, Code Blocks}, - @RefSect{extras.disable_contract_compilation__macro_interface_, - Disable Contract Compilation} - */ - #define BOOST_CONTRACT_FUNCTION() /* nothing */ -#endif - -#endif // #include guard - diff --git a/index.html b/index.html deleted file mode 100644 index 6861cd17..00000000 --- a/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - Automatic redirection failed, click this - link