#ifndef BOOST_CONTRACT_DETAIL_COND_POST_HPP_ #define BOOST_CONTRACT_DETAIL_COND_POST_HPP_ // Copyright (C) 2008-2018 Lorenzo Caminiti // Distributed under the Boost Software License, Version 1.0 (see accompanying // file LICENSE_1_0.txt or a 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