2 #ifndef BOOST_CONTRACT_DETAIL_COND_POST_HPP_
3 #define BOOST_CONTRACT_DETAIL_COND_POST_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
10 #include <boost/contract/core/exception.hpp>
11 #include <boost/contract/core/config.hpp>
12 #include <boost/contract/detail/condition/cond_base.hpp>
13 #include <boost/contract/detail/none.hpp>
14 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
15 #include <boost/contract/detail/type_traits/optional.hpp>
16 #include <boost/optional.hpp>
17 #include <boost/function.hpp>
18 #include <boost/type_traits/remove_reference.hpp>
19 #include <boost/mpl/if.hpp>
20 #include <boost/preprocessor/facilities/empty.hpp>
25 #define BOOST_CONTRACT_DETAIL_COND_POST_DEF_( \
26 result_type, result_param, ftor_type, ftor_var, ftor_call) \
28 template<typename F> \
29 void set_post(F const& f) { ftor_var = f; } \
32 void check_post(result_type const& result_param) { \
33 if(failed()) return; \
34 try { if(ftor_var) { ftor_call; } } \
35 catch(...) { fail(&boost::contract::postcondition_failure); } \
39 boost::function<ftor_type> ftor_var; /* Boost.Func for lambdas, etc. */
43 namespace boost { namespace contract { namespace detail {
46 class cond_post : public cond_base { // Non-copyable base.
48 explicit cond_post(boost::contract::from from) : cond_base(from) {}
50 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
51 private: typedef typename boost::mpl::if_<is_optional<VR>,
52 boost::optional<typename boost::remove_reference<typename
53 optional_value_type<VR>::type>::type const&> const&
58 BOOST_CONTRACT_DETAIL_COND_POST_DEF_(
62 // Won't raise this error if NO_POST (for optimization).
63 BOOST_CONTRACT_ERROR_postcondition_result_parameter_required,
64 BOOST_CONTRACT_ERROR_postcondition_result_parameter_required(r)
70 class cond_post<none> : public cond_base { // Non-copyable base.
72 explicit cond_post(boost::contract::from from) : cond_base(from) {}
74 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
75 BOOST_CONTRACT_DETAIL_COND_POST_DEF_(
77 /* r */ BOOST_PP_EMPTY(),
79 // Won't raise this error if NO_POST (for optimization).
80 BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed,
81 BOOST_CONTRACT_ERROR_postcondition_result_parameter_not_allowed()
88 #endif // #include guard