From f0ca795867c77cc9045c3f8e56fc556f89b6c0ca Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Thu, 11 Jun 2015 08:02:46 -0700 Subject: [PATCH] replaced free/private/protected_function with just function and started to program n1962 examples --- example/Jamfile.v2 | 2 + example/cline90/calendar.cpp | 81 ++++++++++++++++ example/cline90/vector.hpp | 11 +++ example/cline90/vstack.cpp | 96 ++++++++++++------- example/mitchell02/observer/subject.hpp | 10 +- example/mitchell02/simple_queue.cpp | 2 +- include/boost/contract.hpp | 4 +- .../contract/aux_/check/check_pre_post.hpp | 71 -------------- .../{check => condition}/check_pre_only.hpp | 0 .../aux_/condition/check_pre_post.hpp | 92 ++++++++++++++++++ .../check_pre_post_inv.hpp | 2 +- .../check_subcontracted_pre_post_inv.hpp | 6 +- .../aux_/function/private_function.hpp | 20 ---- .../aux_/function/protected_function.hpp | 20 ---- include/boost/contract/aux_/none.hpp | 6 -- .../{function => operation}/constructor.hpp | 2 +- .../{function => operation}/destructor.hpp | 2 +- .../function.hpp} | 18 ++-- .../public_function.hpp | 4 +- .../public_static_function.hpp | 4 +- .../type_traits/member_function_types.hpp | 2 + include/boost/contract/constructor.hpp | 2 +- include/boost/contract/core/exception.hpp | 5 +- include/boost/contract/core/set_nothing.hpp | 2 +- .../contract/core/set_postcondition_only.hpp | 2 +- .../contract/core/set_precondition_only.hpp | 2 +- .../core/set_precondition_postcondition.hpp | 6 +- include/boost/contract/destructor.hpp | 2 +- .../{free_function.hpp => function.hpp} | 10 +- include/boost/contract/guard.hpp | 2 +- include/boost/contract/private_function.hpp | 23 ----- include/boost/contract/protected_function.hpp | 23 ----- include/boost/contract/public_function.hpp | 61 +++++++----- test/Jamfile.v2 | 10 +- .../body_throw.cpp | 4 +- .../main.cpp => function/pre_post.cpp} | 4 +- test/private_function/bases.cpp | 74 -------------- test/private_function/body_throw.cpp | 49 ---------- test/protected_function/bases.cpp | 74 -------------- test/protected_function/body_throw.cpp | 49 ---------- test/set/nothing.cpp | 4 +- test/set/post_only.cpp | 4 +- test/set/post_post-error.cpp | 4 +- test/set/post_pre.cpp | 4 +- test/set/post_pre_post-error.cpp | 4 +- test/set/pre_only.cpp | 4 +- test/set/pre_post.cpp | 4 +- test/set/pre_post_pre-error.cpp | 4 +- test/set/pre_pre-error.cpp | 4 +- 49 files changed, 346 insertions(+), 549 deletions(-) create mode 100644 example/cline90/calendar.cpp delete mode 100644 include/boost/contract/aux_/check/check_pre_post.hpp rename include/boost/contract/aux_/{check => condition}/check_pre_only.hpp (100%) create mode 100644 include/boost/contract/aux_/condition/check_pre_post.hpp rename include/boost/contract/aux_/{check => condition}/check_pre_post_inv.hpp (97%) rename include/boost/contract/aux_/{check => condition}/check_subcontracted_pre_post_inv.hpp (96%) delete mode 100644 include/boost/contract/aux_/function/private_function.hpp delete mode 100644 include/boost/contract/aux_/function/protected_function.hpp rename include/boost/contract/aux_/{function => operation}/constructor.hpp (95%) rename include/boost/contract/aux_/{function => operation}/destructor.hpp (96%) rename include/boost/contract/aux_/{function/free_function.hpp => operation/function.hpp} (54%) rename include/boost/contract/aux_/{function => operation}/public_function.hpp (92%) rename include/boost/contract/aux_/{function => operation}/public_static_function.hpp (89%) rename include/boost/contract/{free_function.hpp => function.hpp} (54%) delete mode 100644 include/boost/contract/private_function.hpp delete mode 100644 include/boost/contract/protected_function.hpp rename test/{free_function => function}/body_throw.cpp (88%) rename test/{free_function/main.cpp => function/pre_post.cpp} (94%) delete mode 100644 test/private_function/bases.cpp delete mode 100644 test/private_function/body_throw.cpp delete mode 100644 test/protected_function/bases.cpp delete mode 100644 test/protected_function/body_throw.cpp diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index ab43ca9..3af9d3f 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -13,4 +13,6 @@ subdir-run mitchell02 : counter_main ; 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 new file mode 100644 index 0000000..8dd3336 --- /dev/null +++ b/example/cline90/calendar.cpp @@ -0,0 +1,81 @@ + +#include +#include + +class calendar { +public: + 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())); + } + + calendar() : month_(1), date_(31) { + auto c = boost::contract::constructor(this) + .postcondition([&] { + BOOST_CONTRACT_ASSERT(month() == 1); + BOOST_CONTRACT_ASSERT(date() == 31); + }) + ; + } + + virtual ~calendar() { + auto c = boost::contract::destructor(this); // Check invariants. + } + + int month() const { + auto c = boost::contract::public_function(this); // Check invariants. + return month_; + } + + int date() const { + auto c = boost::contract::public_function(this); // Check invariants. + return date_; + } + + void reset(int new_month) { + auto 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; + auto 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; + BOOST_TEST_EQ(cal.date(), 31); + BOOST_TEST_EQ(cal.month(), 1); + + cal.reset(8); // Set month + BOOST_TEST_EQ(cal.month(), 8); + + return boost::report_errors(); +} + diff --git a/example/cline90/vector.hpp b/example/cline90/vector.hpp index 2a25549..bb18ef2 100644 --- a/example/cline90/vector.hpp +++ b/example/cline90/vector.hpp @@ -75,6 +75,17 @@ public: return data_[index]; } + + T const& operator[](int index) const { + auto c = boost::contract::public_function(this) + .precondition([&] { + BOOST_CONTRACT_ASSERT(index >= 0); + BOOST_CONTRACT_ASSERT(index < size()); + }) + ; + + return data_[index]; + } private: T* data_; diff --git a/example/cline90/vstack.cpp b/example/cline90/vstack.cpp index 8b0b5cc..512e1c0 100644 --- a/example/cline90/vstack.cpp +++ b/example/cline90/vstack.cpp @@ -1,7 +1,9 @@ #include "vector.hpp" #include -#incldue +#include +#include +#include template class abstract_stack { @@ -10,9 +12,8 @@ public: abstract_stack() { auto c = boost::contract::constructor(this) - .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); - }) + // Postcondition: empty() (but it cannot be checked here to avoid + // calling pure virtual function length() during construction). ; } @@ -41,38 +42,46 @@ public: } virtual int length(boost::contract::virtual_* v = 0) const = 0; - virtual int capacity(boost::contract::virtual_* v = 0) const = 0; - virtual void push(T const& value, boost::contract::virtual_* v = 0) = 0; + virtual T const& item(boost::contract::virtual_* v = 0) const = 0; - virtual T pop(boost::contract::virtual_* v = 0) = 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 { - auto c = boost::contract::public_function(v, this) + int result; + auto c = boost::contract::public_function(v, result, this) .postcondition([&] (int const& result) { BOOST_CONTRACT_ASSERT(result >= 0); }) ; - - throw std::logic_error(); - return -1; + assert(false); return result; } template int abstract_stack::capacity(boost::contract::virtual_* v) const { - auto c = boost::contract::public_function(v, this) + int result; + auto c = boost::contract::public_function(v, result, this) .postcondition([&] (int const& result) { BOOST_CONTRACT_ASSERT(result >= 0); }) ; + assert(false); return result; +} - throw std::logic_error(); - return -1; +template +T const& abstract_stack::item(boost::contract::virtual_* v) const { + auto c = boost::contract::public_function(v, this) + .precondition([&] { + BOOST_CONTRACT_ASSERT(!empty()); + }) + ; + assert(false); return *boost::optional(); } template @@ -85,33 +94,33 @@ void abstract_stack::push(T const& value, boost::contract::virtual_* v) { BOOST_CONTRACT_ASSERT(!empty()); }) ; - - throw std::logic_error(); + assert(false); } template -void abstract_stack::pop(boost::contract::virtual_* v) { - auto c = boost::contract::public_function(v, this) +T const& abstract_stack::pop(boost::contract::virtual_* v) { + boost::optional result; + auto old_item = BOOST_CONTRACT_OLDOF(v, item()); + auto c = boost::contract::public_function(v, result, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) - .postcondition([&] { + .postcondition([&] (boost::optional const& result) { BOOST_CONTRACT_ASSERT(!full()); + BOOST_CONTRACT_ASSERT(*result == *old_item); }) ; - - throw std::logic_error(); + assert(false); return *boost::optional(); } template void abstract_stack::clear(boost::contract::virtual_* v) { auto c = boost::contract::public_function(v, this) .postcondition([&] { - BOOST_CONTRACT_ASSERT(empty()); + BOOST_CONTRACT_ASSERT(this->empty()); }) ; - - throw std::logic_error(); + assert(false); } template @@ -129,13 +138,13 @@ public: BOOST_CONTRACT_ASSERT(length() < capacity()); } - static vstack_precondition(int const& count) { + static void vstack_precondition(int const& count) { BOOST_CONTRACT_ASSERT(count >= 0); } explicit vstack(int count = 10) : boost::contract::constructor_precondition(boost::bind( &vstack::vstack_precondition, boost::cref(count))), - v_(count), // OK, executed after precondition so count >= 0. + vect_(count), // OK, executed after precondition so count >= 0. len_(0) { auto c = boost::contract::constructor(this) @@ -146,36 +155,49 @@ public: ; } - virtual ~vstack() { auto c = boost::contract::destrucotr(this); } + virtual ~vstack() { auto c = boost::contract::destructor(this); } // Inherited from abstract_stack. virtual int length(boost::contract::virtual_* v = 0) const /* override */ { + int result; auto c = boost::contract::public_function( - v, &vstack::length, this); - return len_; + v, result, &vstack::length, this); + return result = len_; } BOOST_CONTRACT_OVERRIDE(length) - virtual int capacity() const /* override */ { + virtual int capacity(boost::contract::virtual_* v = 0) + const /* override */ { + int result; auto c = boost::contract::public_function( - v, &vstack::capacity, this); - return v_.size(); + v, result, &vstack::capacity, this); + return result = vect_.size(); } BOOST_CONTRACT_OVERRIDE(capacity) + virtual T const& item(boost::contract::virtual_* v = 0) + const /* override */ { + boost::optional result; + auto c = boost::contract::public_function( + v, result, &vstack::item, this); + return *(result = vect_[len_ - 1]); + } + BOOST_CONTRACT_OVERRIDE(item) + virtual void push(T const& value, boost::contract::virtual_* v = 0) /* override */ { auto c = boost::contract::public_function( v, &vstack::push, this, value); - v_[len_++] = value; + vect_[len_++] = value; } BOOST_CONTRACT_OVERRIDE(push) - virtual T pop(boost::contract::virtual_* v = 0) /* override */ { + virtual T const& pop(boost::contract::virtual_* v = 0) /* override */ { + boost::optional result; auto c = boost::contract::public_function( - v, &vstack::pop, this); - return v_[--len_]; + v, result, &vstack::pop, this); + return *(result = vect_[--len_]); } BOOST_CONTRACT_OVERRIDE(pop) @@ -187,7 +209,7 @@ public: BOOST_CONTRACT_OVERRIDE(clear); private: - vector v_; + vector vect_; int len_; }; diff --git a/example/mitchell02/observer/subject.hpp b/example/mitchell02/observer/subject.hpp index cc5ec35..8c5409d 100644 --- a/example/mitchell02/observer/subject.hpp +++ b/example/mitchell02/observer/subject.hpp @@ -78,8 +78,6 @@ protected: // All observers attached to this subject. std::vector observers() const { - auto c = boost::contract::protected_function(); - std::vector obs; for(std::vector::const_iterator i = observers_.cbegin(); i != observers_.cend(); ++i) { @@ -92,7 +90,7 @@ protected: // Update all attached observers. void notify() { - auto c = boost::contract::protected_function() + auto c = boost::contract::function() .postcondition([&] { if(O_N <= COMPLEXITY_MAX) { // All updated. @@ -114,8 +112,6 @@ private: /* Contract Helpers */ static bool all_observers_valid(std::vector const& obs) { - auto c = boost::contract::private_function(); - for(std::vector::const_iterator i = obs.cbegin(); i != obs.cend(); ++i) { if(!*i) return false; @@ -128,7 +124,7 @@ private: std::vector const& new_obs, observer const* ob ) { - auto c = boost::contract::private_function() + auto c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(ob); // Not null. }) @@ -149,8 +145,6 @@ private: } static bool all_observers_updated(std::vector const& obs) { - auto c = boost::contract::private_function(); - for(std::vector::const_iterator i = obs.cbegin(); i != obs.cend(); ++i) { if(!*i) return false; diff --git a/example/mitchell02/simple_queue.cpp b/example/mitchell02/simple_queue.cpp index e196061..0ba16e6 100644 --- a/example/mitchell02/simple_queue.cpp +++ b/example/mitchell02/simple_queue.cpp @@ -176,7 +176,7 @@ private: // Contract helper. static bool all_equal(std::vector const& left, std::vector const& right, unsigned offset = 0) { - auto c = boost::contract::private_function() + auto c = boost::contract::function() .precondition([&] { // Correct offset. BOOST_CONTRACT_ASSERT(right.size() == left.size() + offset); diff --git a/include/boost/contract.hpp b/include/boost/contract.hpp index f1387f0..4d8b97e 100644 --- a/include/boost/contract.hpp +++ b/include/boost/contract.hpp @@ -8,12 +8,10 @@ #include #include #include -#include +#include #include #include #include -#include -#include #include #endif // #include guard diff --git a/include/boost/contract/aux_/check/check_pre_post.hpp b/include/boost/contract/aux_/check/check_pre_post.hpp deleted file mode 100644 index ed42efc..0000000 --- a/include/boost/contract/aux_/check/check_pre_post.hpp +++ /dev/null @@ -1,71 +0,0 @@ - -#ifndef BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ -#define BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ - -#include -#include -#include -#include -/** @cond */ -#include // TODO: Can I reduce boost.function overhead? -/** @endcond */ - -namespace boost { namespace contract { namespace aux { - -// TODO: Does this need to be copied? Copying function<> could copy captures -// (if function is a lambda) and it could be expensive... check all classes -// that MUST be copiable, make sure their copies are effecient, make all other -// calsses noncopyable. -template -class check_pre_post : public check_pre_only { -public: - explicit check_pre_post(boost::contract::from from) : - check_pre_only(from) {} - - virtual ~check_pre_post() {} - - template - void set_post(F const& f) { post_ = f; post_available(); } - -protected: - void check_post(R& r) { - try { if(post_) post_(r); } - catch(...) { boost::contract::postcondition_failed(from()); } - } - - virtual void post_available() {} - -private: - boost::function post_; -}; - -// TODO: I should avoid repeating code between this and above... -template<> -class check_pre_post : public check_pre_only { -public: - explicit check_pre_post(boost::contract::from from) : - check_pre_only(from) {} - - virtual ~check_pre_post() {} - - template - void set_post(F const& f) { post_ = f; post_available(); } - -protected: - void check_post() { - try { if(post_) post_(); } - catch(...) { boost::contract::postcondition_failed(from()); } - } - - void check_post(none&) { check_post(); } - - virtual void post_available() {} - -private: - boost::function post_; -}; - -} } } - -#endif // #include guard - diff --git a/include/boost/contract/aux_/check/check_pre_only.hpp b/include/boost/contract/aux_/condition/check_pre_only.hpp similarity index 100% rename from include/boost/contract/aux_/check/check_pre_only.hpp rename to include/boost/contract/aux_/condition/check_pre_only.hpp diff --git a/include/boost/contract/aux_/condition/check_pre_post.hpp b/include/boost/contract/aux_/condition/check_pre_post.hpp new file mode 100644 index 0000000..99c203b --- /dev/null +++ b/include/boost/contract/aux_/condition/check_pre_post.hpp @@ -0,0 +1,92 @@ + +#ifndef BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ +#define BOOST_CONTRACT_AUX_CHECK_PRE_POST_HPP_ + +#include +#include +#include +#include +/** @cond */ +#include +#include // TODO: Can I reduce boost.function overhead? +/** @endcond */ + +namespace boost { namespace contract { namespace aux { + +// TODO: Does this need to be copied? Copying function<> could copy captures +// (if function is a lambda) and it could be expensive... check all classes +// that MUST be copiable, make sure their copies are effecient, make all other +// calsses noncopyable. + +// TODO: This also handles R = boost::optional<...> but the case where base and +// derived function used mixed (one does not use optional but the other does) +// still gives a run-time error because optional is not set (at least when +// the base uses optional but the derived does not). Fix that. + +template +class check_pre_post : public check_pre_only { +public: + explicit check_pre_post(boost::contract::from from) : + check_pre_only(from) {} + + virtual ~check_pre_post() {} + + template + void set_post(F const& f) { + BOOST_CONTRACT_ERROR_postcondition_result_parameter_required = f; + post_available(); + } + +protected: + void check_post(R& r) { + try { + if(BOOST_CONTRACT_ERROR_postcondition_result_parameter_required) { + BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r); + } + } catch(...) { boost::contract::postcondition_failed(from()); } + } + + virtual void post_available() {} + +private: + boost::function + BOOST_CONTRACT_ERROR_postcondition_result_parameter_required; +}; + +// TODO: Try to limit code repetition between code below and above. +template<> +class check_pre_post : public check_pre_only { +public: + explicit check_pre_post(boost::contract::from from) : + check_pre_only(from) {} + + virtual ~check_pre_post() {} + + template + void set_post(F const& f) { + BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed = f; + post_available(); + } + +protected: + void check_post() { + try { + if(BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed){ + BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed(); + } + } catch(...) { boost::contract::postcondition_failed(from()); } + } + + void check_post(none&) { check_post(); } + + virtual void post_available() {} + +private: + boost::function + BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed; +}; + +} } } + +#endif // #include guard + diff --git a/include/boost/contract/aux_/check/check_pre_post_inv.hpp b/include/boost/contract/aux_/condition/check_pre_post_inv.hpp similarity index 97% rename from include/boost/contract/aux_/check/check_pre_post_inv.hpp rename to include/boost/contract/aux_/condition/check_pre_post_inv.hpp index f93230f..9fd2b5f 100644 --- a/include/boost/contract/aux_/check/check_pre_post_inv.hpp +++ b/include/boost/contract/aux_/condition/check_pre_post_inv.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include /** @cond */ diff --git a/include/boost/contract/aux_/check/check_subcontracted_pre_post_inv.hpp b/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp similarity index 96% rename from include/boost/contract/aux_/check/check_subcontracted_pre_post_inv.hpp rename to include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp index f4855fd..d662b1a 100644 --- a/include/boost/contract/aux_/check/check_subcontracted_pre_post_inv.hpp +++ b/include/boost/contract/aux_/condition/check_subcontracted_pre_post_inv.hpp @@ -4,7 +4,7 @@ // TODO: Review and cleanup all #includes. #include -#include +#include #include #include #include @@ -78,7 +78,8 @@ public: if(!boost::mpl::empty::value) { v_ = new boost::contract::virtual_( boost::contract::virtual_::no_action); - v_->result_ = &r_; + // C-style cast to handle both pointer type and const. + v_->result_ = (void*)&r_; } else v_ = 0; } check_base_.nest(this); @@ -132,6 +133,7 @@ protected: private: void check_post_result() { + // Ternary op here avoids extra copy of R (because constructing a &). R& r = base_call_ ? *static_cast(v_->result_) : r_; this->check_post(r); } diff --git a/include/boost/contract/aux_/function/private_function.hpp b/include/boost/contract/aux_/function/private_function.hpp deleted file mode 100644 index 6ab6006..0000000 --- a/include/boost/contract/aux_/function/private_function.hpp +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef BOOST_CONTRACT_AUX_PRIVATE_FUNCTION_HPP_ -#define BOOST_CONTRACT_AUX_PRIVATE_FUNCTION_HPP_ - -#include -#include - -namespace boost { namespace contract { namespace aux { - -// Non-public member functions (e.g., private member functions) are allowed to -// fail class invariants (so no inv), plus they do not participate in virtual -// function polymorphism according to substitution principle (so no -// subcontracting). Therefore, these contract like free functions. -typedef boost::contract::aux::basic_free_function< - boost::contract::from_private_function> private_function; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/aux_/function/protected_function.hpp b/include/boost/contract/aux_/function/protected_function.hpp deleted file mode 100644 index 8d00326..0000000 --- a/include/boost/contract/aux_/function/protected_function.hpp +++ /dev/null @@ -1,20 +0,0 @@ - -#ifndef BOOST_CONTRACT_AUX_PROTECTED_FUNCTION_HPP_ -#define BOOST_CONTRACT_AUX_PROTECTED_FUNCTION_HPP_ - -#include -#include - -namespace boost { namespace contract { namespace aux { - -// Non-public member functions (e.g., protected member functions) are allowed -// to fail class invariants (so no inv) and they do not participate in virtual -// function polymorphism according to substitution principle (so no -// subcontracting). Therefore, these contract like free functions. -typedef boost::contract::aux::basic_free_function< - boost::contract::from_protected_function> protected_function; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/aux_/none.hpp b/include/boost/contract/aux_/none.hpp index a6e2eba..3ae8c11 100644 --- a/include/boost/contract/aux_/none.hpp +++ b/include/boost/contract/aux_/none.hpp @@ -19,12 +19,6 @@ none none::value; template struct none_if_void { typedef T type; }; template<> struct none_if_void { typedef none type; }; -// TODO: Remove, for testing only... -#include -std::ostream& operator<<(std::ostream& out, none const&) { - return out << ""; -} - } } } // namespace #endif // #include guard diff --git a/include/boost/contract/aux_/function/constructor.hpp b/include/boost/contract/aux_/operation/constructor.hpp similarity index 95% rename from include/boost/contract/aux_/function/constructor.hpp rename to include/boost/contract/aux_/operation/constructor.hpp index b7fed45..90a36a6 100644 --- a/include/boost/contract/aux_/function/constructor.hpp +++ b/include/boost/contract/aux_/operation/constructor.hpp @@ -3,7 +3,7 @@ #define BOOST_CONTRACT_AUX_CONSTRUCTOR_HPP_ #include -#include +#include #include #include /** @cond */ diff --git a/include/boost/contract/aux_/function/destructor.hpp b/include/boost/contract/aux_/operation/destructor.hpp similarity index 96% rename from include/boost/contract/aux_/function/destructor.hpp rename to include/boost/contract/aux_/operation/destructor.hpp index c0ef05c..282c9ea 100644 --- a/include/boost/contract/aux_/function/destructor.hpp +++ b/include/boost/contract/aux_/operation/destructor.hpp @@ -3,7 +3,7 @@ #define BOOST_CONTRACT_AUX_DESTRUCTOR_HPP_ #include -#include +#include #include #include /** @cond */ diff --git a/include/boost/contract/aux_/function/free_function.hpp b/include/boost/contract/aux_/operation/function.hpp similarity index 54% rename from include/boost/contract/aux_/function/free_function.hpp rename to include/boost/contract/aux_/operation/function.hpp index 59bbaa9..99e4635 100644 --- a/include/boost/contract/aux_/function/free_function.hpp +++ b/include/boost/contract/aux_/operation/function.hpp @@ -1,9 +1,9 @@ -#ifndef BOOST_CONTRACT_AUX_FREE_FUNCTION_HPP_ -#define BOOST_CONTRACT_AUX_FREE_FUNCTION_HPP_ +#ifndef BOOST_CONTRACT_AUX_FUNCTION_HPP_ +#define BOOST_CONTRACT_AUX_FUNCTION_HPP_ #include -#include +#include #include #include /** @cond */ @@ -13,11 +13,11 @@ namespace boost { namespace contract { namespace aux { -// Also used for private and protected member functions. -template -class basic_free_function : public check_pre_post { +// Used for free function, private and protected member functions. +class function : public check_pre_post { public: - explicit basic_free_function() : check_pre_post(From) {} + explicit function() : check_pre_post( + boost::contract::from_function) {} private: void pre_available() /* override */ { @@ -26,14 +26,12 @@ private: } public: - ~basic_free_function() { + ~function() { BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN if(!std::uncaught_exception()) this->check_post(); } }; -typedef basic_free_function free_function; - } } } // namespace #endif // #include guard diff --git a/include/boost/contract/aux_/function/public_function.hpp b/include/boost/contract/aux_/operation/public_function.hpp similarity index 92% rename from include/boost/contract/aux_/function/public_function.hpp rename to include/boost/contract/aux_/operation/public_function.hpp index 79b8d17..63b605b 100644 --- a/include/boost/contract/aux_/function/public_function.hpp +++ b/include/boost/contract/aux_/operation/public_function.hpp @@ -3,7 +3,7 @@ #define BOOST_CONTRACT_AUX_PUBLIC_FUNCTION_HPP_ #include -#include +#include #include #include /** @cond */ @@ -19,7 +19,7 @@ public: explicit public_function( boost::contract::virtual_* v, C* obj, R& r, A0& a0, A1& a1) : check_subcontracted_pre_post_inv( - boost::contract::from_public_function, v, obj, r, a0, a1) + boost::contract::from_function, v, obj, r, a0, a1) { BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN this->copy_subcontracted_oldof(); diff --git a/include/boost/contract/aux_/function/public_static_function.hpp b/include/boost/contract/aux_/operation/public_static_function.hpp similarity index 89% rename from include/boost/contract/aux_/function/public_static_function.hpp rename to include/boost/contract/aux_/operation/public_static_function.hpp index 5092c56..34ff899 100644 --- a/include/boost/contract/aux_/function/public_static_function.hpp +++ b/include/boost/contract/aux_/operation/public_static_function.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include /** @cond */ @@ -19,7 +19,7 @@ template class public_static_function : public check_pre_post_inv { public: explicit public_static_function() : check_pre_post_inv( - boost::contract::from_public_function, /* obj = */ 0) { + boost::contract::from_function, /* obj = */ 0) { BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN this->check_entry_static_inv(); } diff --git a/include/boost/contract/aux_/type_traits/member_function_types.hpp b/include/boost/contract/aux_/type_traits/member_function_types.hpp index a66c864..e4b14d7 100644 --- a/include/boost/contract/aux_/type_traits/member_function_types.hpp +++ b/include/boost/contract/aux_/type_traits/member_function_types.hpp @@ -4,6 +4,7 @@ #include #include +/** @cond */ #include #include #include @@ -16,6 +17,7 @@ #include #include #include +/** @endcond */ namespace boost { namespace contract { namespace aux { diff --git a/include/boost/contract/constructor.hpp b/include/boost/contract/constructor.hpp index ecba5a9..6b6eb4f 100644 --- a/include/boost/contract/constructor.hpp +++ b/include/boost/contract/constructor.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include /** @cond */ #include /** @endcond */ diff --git a/include/boost/contract/core/exception.hpp b/include/boost/contract/core/exception.hpp index ca1d637..e75fbc0 100644 --- a/include/boost/contract/core/exception.hpp +++ b/include/boost/contract/core/exception.hpp @@ -56,10 +56,7 @@ private: enum from { from_constructor, from_destructor, - from_public_function, - from_protected_function, - from_private_function, - from_free_function + from_function }; typedef void (*assertion_failed_handler)(from); diff --git a/include/boost/contract/core/set_nothing.hpp b/include/boost/contract/core/set_nothing.hpp index 2f8fcd4..e0c8e75 100644 --- a/include/boost/contract/core/set_nothing.hpp +++ b/include/boost/contract/core/set_nothing.hpp @@ -4,7 +4,7 @@ /** @file */ -#include +#include /** @cond */ #include /** @endcond */ diff --git a/include/boost/contract/core/set_postcondition_only.hpp b/include/boost/contract/core/set_postcondition_only.hpp index cd1951a..9623348 100644 --- a/include/boost/contract/core/set_postcondition_only.hpp +++ b/include/boost/contract/core/set_postcondition_only.hpp @@ -5,7 +5,7 @@ /** @file */ #include -#include +#include #include /** @cond */ #include diff --git a/include/boost/contract/core/set_precondition_only.hpp b/include/boost/contract/core/set_precondition_only.hpp index bbb6be0..a36ec52 100644 --- a/include/boost/contract/core/set_precondition_only.hpp +++ b/include/boost/contract/core/set_precondition_only.hpp @@ -5,7 +5,7 @@ /** @file */ #include -#include +#include /** @cond */ #include /** @endcond */ diff --git a/include/boost/contract/core/set_precondition_postcondition.hpp b/include/boost/contract/core/set_precondition_postcondition.hpp index e43d073..6c05ced 100644 --- a/include/boost/contract/core/set_precondition_postcondition.hpp +++ b/include/boost/contract/core/set_precondition_postcondition.hpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include /** @cond */ #include @@ -47,9 +47,7 @@ private: // Friendship used to limit library's public API. friend class guard; - friend set_precondition_postcondition<> free_function(); - friend set_precondition_postcondition<> protected_function(); - friend set_precondition_postcondition<> private_function(); + friend set_precondition_postcondition<> function(); template friend set_precondition_postcondition<> public_function(); diff --git a/include/boost/contract/destructor.hpp b/include/boost/contract/destructor.hpp index 5c1d014..b509b73 100644 --- a/include/boost/contract/destructor.hpp +++ b/include/boost/contract/destructor.hpp @@ -5,7 +5,7 @@ /** @file */ #include -#include +#include /** @cond */ #include /** @endcond */ diff --git a/include/boost/contract/free_function.hpp b/include/boost/contract/function.hpp similarity index 54% rename from include/boost/contract/free_function.hpp rename to include/boost/contract/function.hpp index bba5a03..c36f945 100644 --- a/include/boost/contract/free_function.hpp +++ b/include/boost/contract/function.hpp @@ -1,20 +1,20 @@ -#ifndef BOOST_CONTRACT_FREE_FUNCTION_HPP_ -#define BOOST_CONTRACT_FREE_FUNCTION_HPP_ +#ifndef BOOST_CONTRACT_FUNCTION_HPP_ +#define BOOST_CONTRACT_FUNCTION_HPP_ /** @file */ #include -#include +#include /** @cond */ #include /** @endcond */ namespace boost { namespace contract { -set_precondition_postcondition<> free_function() { +set_precondition_postcondition<> function() { return set_precondition_postcondition<>(boost::make_shared< - boost::contract::aux::free_function>()); + boost::contract::aux::function>()); } } } // namespace diff --git a/include/boost/contract/guard.hpp b/include/boost/contract/guard.hpp index 2a1b728..dc6d718 100644 --- a/include/boost/contract/guard.hpp +++ b/include/boost/contract/guard.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include /** @cond */ #include #include diff --git a/include/boost/contract/private_function.hpp b/include/boost/contract/private_function.hpp deleted file mode 100644 index cf9b373..0000000 --- a/include/boost/contract/private_function.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef BOOST_CONTRACT_PRIVATE_FUNCTION_HPP_ -#define BOOST_CONTRACT_PRIVATE_FUNCTION_HPP_ - -/** @file */ - -#include -#include -/** @cond */ -#include -/** @endcond */ - -namespace boost { namespace contract { - -set_precondition_postcondition<> private_function() { - return set_precondition_postcondition<>(boost::make_shared< - boost::contract::aux::private_function>()); -} - -} } // namespace - -#endif // - diff --git a/include/boost/contract/protected_function.hpp b/include/boost/contract/protected_function.hpp deleted file mode 100644 index 58e9724..0000000 --- a/include/boost/contract/protected_function.hpp +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef BOOST_CONTRACT_PROTECTED_FUNCTION_HPP_ -#define BOOST_CONTRACT_PROTECTED_FUNCTION_HPP_ - -/** @file */ - -#include -#include -/** @cond */ -#include -/** @endcond */ - -namespace boost { namespace contract { - -set_precondition_postcondition<> protected_function() { - return set_precondition_postcondition<>(boost::make_shared< - boost::contract::aux::protected_function>()); -} - -} } // namespace - -#endif // - diff --git a/include/boost/contract/public_function.hpp b/include/boost/contract/public_function.hpp index e90dc3b..bb3887a 100644 --- a/include/boost/contract/public_function.hpp +++ b/include/boost/contract/public_function.hpp @@ -6,42 +6,29 @@ #include #include -#include -#include +#include +#include #include #include /** @cond */ +#include +#include #include +#include #include #include #include -#include /** @endcond */ /* PRIVATE */ -// Always enforce this so this lib can check and enforce override. -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) \ - BOOST_STATIC_ASSERT_MSG( \ - boost::contract::aux::has_base_types::value, \ - "enclosing class missing 'base types' typdef" \ - ); - -#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) \ - BOOST_STATIC_ASSERT_MSG( \ - boost::is_same< \ - typename boost::remove_reference::type>::type, \ - R \ - >::value, \ - "miss-matching result type for specified function" \ - ); - +// This check is strictly not necessary because compilation will fail anyways, +// but it helps limiting cryptic compiler's errors. #define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_ARITY(F, arity) \ BOOST_STATIC_ASSERT_MSG( \ - /* -1 for this and -1 for virtual_* so -2 total */ \ + /* -2 for both `this` and `virtual_*` extra parameters */ \ boost::function_types::function_arity::value - 2 == arity, \ - "missing one or more parameters for specified function" \ + "missing one or more arguments for specified function" \ ); // Always enforce this so base contracts can always specify postconditions with @@ -52,13 +39,41 @@ typename boost::function_types::result_type::type, \ void \ >::value, \ - "missing result parameter for non-void function" \ + "missing result argument for non-void function" \ + ); + +#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_RESULT_(F, R) \ + BOOST_STATIC_ASSERT_MSG( \ + boost::is_same< \ + typename boost::remove_reference::type>::type, \ + typename boost::contract::public_function_:: \ + remove_optional::type \ + >::value, \ + "miss-matching result type for specified function" \ + ); + +// Always enforce this so this lib can check and enforce override. +#define BOOST_CONTRACT_PUBLIC_FUNCTION_HAS_BASE_TYPES_(C) \ + BOOST_STATIC_ASSERT_MSG( \ + boost::contract::aux::has_base_types::value, \ + "enclosing class missing 'base types' typdef" \ ); /* CODE */ namespace boost { namespace contract { +namespace public_function_ { + template + struct remove_optional { typedef R type; }; + + template + struct remove_optional > { + typedef typename boost::remove_reference::type type; + }; +} + // For static member functions. template set_precondition_postcondition<> public_function() { diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1c42f42..1a94c59 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -14,14 +14,8 @@ subdir-run public_function : body_throw ; subdir-run public_function : static ; subdir-run public_function : static_body_throw ; -subdir-run protected_function : bases ; -subdir-run protected_function : body_throw ; - -subdir-run private_function : bases ; -subdir-run private_function : body_throw ; - -subdir-run free_function : main ; -subdir-run free_function : body_throw ; +subdir-run function : pre_post ; +subdir-run function : body_throw ; subdir-run disable : checking ; diff --git a/test/free_function/body_throw.cpp b/test/function/body_throw.cpp similarity index 88% rename from test/free_function/body_throw.cpp rename to test/function/body_throw.cpp index 42186b2..6142687 100644 --- a/test/free_function/body_throw.cpp +++ b/test/function/body_throw.cpp @@ -2,7 +2,7 @@ // Test free function body throwing. #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -12,7 +12,7 @@ boost::contract::aux::test::oteststream out; struct e {}; void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([&] { out << "f::pre" << std::endl; }) .postcondition([&] { out << "f::post" << std::endl; }) ; diff --git a/test/free_function/main.cpp b/test/function/pre_post.cpp similarity index 94% rename from test/free_function/main.cpp rename to test/function/pre_post.cpp index c2de3fe..3cbd083 100644 --- a/test/free_function/main.cpp +++ b/test/function/pre_post.cpp @@ -3,7 +3,7 @@ #include "../aux_/oteststream.hpp" #include "../aux_/cpcnt.hpp" -#include +#include #include #include #include @@ -22,7 +22,7 @@ bool swap(x_type& x, y_type& y) { BOOST_CONTRACT_OLDOF(x_type::eval(x)); boost::shared_ptr old_y = BOOST_CONTRACT_OLDOF(y_type::eval(y)); - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([&] { out << "swap::pre" << std::endl; BOOST_CONTRACT_ASSERT(x.value != y.value); diff --git a/test/private_function/bases.cpp b/test/private_function/bases.cpp deleted file mode 100644 index 2f7c14a..0000000 --- a/test/private_function/bases.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -// Test private member function contracts. - -#include "../aux_/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::aux::test::oteststream out; - -struct b { - void invariant() const { out << "b::inv" << std::endl; } - static void static_invariant() { out << "b::static_inv" << std::endl; } - -private: - virtual void f() { - boost::contract::guard c = boost::contract::private_function() - .precondition([&] { - out << "b::f::pre" << 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 - - void invariant() const { out << "a::inv" << std::endl; } - static void static_invariant() { out << "a::static_inv" << std::endl; } - - void call_f() { f(); } - -private: - virtual void f() { - boost::contract::guard c = boost::contract::private_function() - .precondition([&] { - out << "a::f::pre" << 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.call_f(); - ok.str(""); ok - // Test not part of public API so no inv, plus cannot be called directly - // so substitution principle does not applu and no subcontracting. - << "a::f::pre" << std::endl - << "a::f::body" << std::endl - << "a::f::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/private_function/body_throw.cpp b/test/private_function/body_throw.cpp deleted file mode 100644 index 2779250..0000000 --- a/test/private_function/body_throw.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -// Test private member function throwing. - -#include "../aux_/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::aux::test::oteststream out; - -struct a { - void invariant() const { out << "a::inv" << std::endl; } - static void static_invariant() { out << "a::static_inv" << std::endl; } - - struct e {}; - - void call_f() { f(); } - -private: - virtual void f() { - boost::contract::guard c = boost::contract::private_function() - .precondition([&] { out << "a::f::pre" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - throw a::e(); - } -}; - -int main() { - std::ostringstream ok; - - a aa; - bool threw = false; - out.str(""); - try { aa.call_f(); } - catch(a::e const&) { threw = true; } - BOOST_TEST(threw); - ok.str(""); ok - << "a::f::pre" << std::endl - << "a::f::body" << std::endl - // Test no post because body threw (never inv because not public). - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/protected_function/bases.cpp b/test/protected_function/bases.cpp deleted file mode 100644 index c4c7b59..0000000 --- a/test/protected_function/bases.cpp +++ /dev/null @@ -1,74 +0,0 @@ - -// Test protected member function contracts. - -#include "../aux_/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::aux::test::oteststream out; - -struct b { - void invariant() const { out << "b::inv" << std::endl; } - static void static_invariant() { out << "b::static_inv" << std::endl; } - -protected: - virtual void f() { - boost::contract::guard c = boost::contract::protected_function() - .precondition([&] { - out << "b::f::pre" << 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 - - void invariant() const { out << "a::inv" << std::endl; } - static void static_invariant() { out << "a::static_inv" << std::endl; } - - void call_f() { f(); } - -protected: - virtual void f() { - boost::contract::guard c = boost::contract::protected_function() - .precondition([&] { - out << "a::f::pre" << 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.call_f(); - ok.str(""); ok - // Test not part of public API so no inv, plus cannot be called directly - // so no substitution principle and no subcontracting. - << "a::f::pre" << std::endl - << "a::f::body" << std::endl - << "a::f::post" << std::endl - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/protected_function/body_throw.cpp b/test/protected_function/body_throw.cpp deleted file mode 100644 index c6325fe..0000000 --- a/test/protected_function/body_throw.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -// Test protected member function throwing. - -#include "../aux_/oteststream.hpp" -#include -#include -#include -#include - -boost::contract::aux::test::oteststream out; - -struct a { - void invariant() const { out << "a::inv" << std::endl; } - static void static_invariant() { out << "a::static_inv" << std::endl; } - - struct e {}; - - void call_f() { f(); } - -protected: - virtual void f() { - boost::contract::guard c = boost::contract::protected_function() - .precondition([&] { out << "a::f::pre" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - throw a::e(); - } -}; - -int main() { - std::ostringstream ok; - - a aa; - bool threw = false; - out.str(""); - try { aa.call_f(); } - catch(a::e const&) { threw = true; } - BOOST_TEST(threw); - ok.str(""); ok - << "a::f::pre" << std::endl - << "a::f::body" << std::endl - // Test no post because body threw (never inv because not public). - ; - BOOST_TEST(out.eq(ok.str())); - - return boost::report_errors(); -} - diff --git a/test/set/nothing.cpp b/test/set/nothing.cpp index 1882852..a8c12f2 100644 --- a/test/set/nothing.cpp +++ b/test/set/nothing.cpp @@ -2,7 +2,7 @@ // Test no pre or post (for free func, but same for all contracts). #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -10,7 +10,7 @@ boost::contract::aux::test::oteststream out; void f() { - boost::contract::guard c = boost::contract::free_function(); + boost::contract::guard c = boost::contract::function(); out << "f::body" << std::endl; } diff --git a/test/set/post_only.cpp b/test/set/post_only.cpp index 6fde1ac..c7f06d8 100644 --- a/test/set/post_only.cpp +++ b/test/set/post_only.cpp @@ -2,7 +2,7 @@ // Test post only specified (for free func, but same for all contracts). #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -10,7 +10,7 @@ boost::contract::aux::test::oteststream out; void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .postcondition([] { out << "f::post" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/set/post_post-error.cpp b/test/set/post_post-error.cpp index d27a8f8..ea7a0f1 100644 --- a/test/set/post_post-error.cpp +++ b/test/set/post_post-error.cpp @@ -1,11 +1,11 @@ // Test multiple post error (for free func, but same for all contracts). -#include +#include #include void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .postcondition([] {}) .postcondition([] {}) // Error (multiple post). ; diff --git a/test/set/post_pre.cpp b/test/set/post_pre.cpp index c96500d..cc4c962 100644 --- a/test/set/post_pre.cpp +++ b/test/set/post_pre.cpp @@ -2,7 +2,7 @@ // Test post before pre (for free func, but same for all contracts). #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -10,7 +10,7 @@ boost::contract::aux::test::oteststream out; void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .postcondition([] { out << "f::post" << std::endl; }) .precondition([] { out << "f::pre" << std::endl; }) ; diff --git a/test/set/post_pre_post-error.cpp b/test/set/post_pre_post-error.cpp index dea5424..d4ba795 100644 --- a/test/set/post_pre_post-error.cpp +++ b/test/set/post_pre_post-error.cpp @@ -1,11 +1,11 @@ // Test multi post around pre error (for free func, but same for all contracts). -#include +#include #include void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .postcondition([] {}) .precondition([] {}) .postcondition([] {}) // Error (multiple post around pre). diff --git a/test/set/pre_only.cpp b/test/set/pre_only.cpp index 99694cd..870c9b7 100644 --- a/test/set/pre_only.cpp +++ b/test/set/pre_only.cpp @@ -2,7 +2,7 @@ // Test pre only specified (for free func, but same for all contracts). #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -10,7 +10,7 @@ boost::contract::aux::test::oteststream out; void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/set/pre_post.cpp b/test/set/pre_post.cpp index 8a4d6eb..5de032f 100644 --- a/test/set/pre_post.cpp +++ b/test/set/pre_post.cpp @@ -2,7 +2,7 @@ // Test pre before post (for free func, but same for all contracts). #include "../aux_/oteststream.hpp" -#include +#include #include #include #include @@ -10,7 +10,7 @@ boost::contract::aux::test::oteststream out; void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) .postcondition([] { out << "f::post" << std::endl; }) ; diff --git a/test/set/pre_post_pre-error.cpp b/test/set/pre_post_pre-error.cpp index 7abe97b..7080d85 100644 --- a/test/set/pre_post_pre-error.cpp +++ b/test/set/pre_post_pre-error.cpp @@ -1,11 +1,11 @@ // Test multi pre around post error (for free func, but same for all contracts). -#include +#include #include void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([] {}) .postcondition([] {}) .precondition([] {}) // Error (multiple pre around post). diff --git a/test/set/pre_pre-error.cpp b/test/set/pre_pre-error.cpp index 94a1a90..dfe2e79 100644 --- a/test/set/pre_pre-error.cpp +++ b/test/set/pre_pre-error.cpp @@ -1,11 +1,11 @@ // Test multiple pre error (for free func, but same for all contracts). -#include +#include #include void f() { - boost::contract::guard c = boost::contract::free_function() + boost::contract::guard c = boost::contract::function() .precondition([] {}) .precondition([] {}) // Error (multiple pre). ;