#ifndef BOOST_CONTRACT_DETAIL_FUNCTION_HPP_ #define BOOST_CONTRACT_DETAIL_FUNCTION_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 #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(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