123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- #ifndef BOOST_SCOPE_SCOPE_FAIL_HPP_INCLUDED_
- #define BOOST_SCOPE_SCOPE_FAIL_HPP_INCLUDED_
- #include <type_traits>
- #include <boost/scope/detail/config.hpp>
- #include <boost/scope/exception_checker.hpp>
- #include <boost/scope/scope_exit.hpp>
- #include <boost/scope/detail/is_not_like.hpp>
- #include <boost/scope/detail/type_traits/conjunction.hpp>
- #include <boost/scope/detail/type_traits/is_invocable.hpp>
- #include <boost/scope/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- namespace scope {
- template< typename Func, typename Cond >
- class scope_fail;
- namespace detail {
- template< typename T >
- using is_not_like_scope_fail = detail::is_not_like< T, scope_fail >;
- }
- template< typename Func, typename Cond = exception_checker >
- class scope_fail :
- public scope_exit< Func, Cond >
- {
- private:
- using base_type = scope_exit< Func, Cond >;
- public:
-
- template<
- typename F
-
- , typename = typename std::enable_if< detail::conjunction<
- std::is_constructible< base_type, F, bool >,
- detail::is_not_like_scope_fail< F >
- >::value >::type
-
- >
- explicit scope_fail(F&& func, bool active = true)
- noexcept(BOOST_SCOPE_DETAIL_DOC_HIDDEN(std::is_nothrow_constructible< base_type, F, bool >::value)) :
- base_type(static_cast< F&& >(func), active)
- {
- }
-
- template<
- typename F,
- typename C
-
- , typename = typename std::enable_if< std::is_constructible< base_type, F, C, bool >::value >::type
-
- >
- explicit scope_fail(F&& func, C&& cond, bool active = true)
- noexcept(BOOST_SCOPE_DETAIL_DOC_HIDDEN(std::is_nothrow_constructible< base_type, F, C, bool >::value)) :
- base_type(static_cast< F&& >(func), static_cast< C&& >(cond), active)
- {
- }
-
-
- template<
- bool Requires = std::is_move_constructible< base_type >::value,
- typename = typename std::enable_if< Requires >::type
- >
-
- scope_fail(scope_fail&& that)
- noexcept(BOOST_SCOPE_DETAIL_DOC_HIDDEN(std::is_nothrow_move_constructible< base_type >::value)) :
- base_type(static_cast< base_type&& >(that))
- {
- }
- scope_fail& operator= (scope_fail&&) = delete;
- scope_fail(scope_fail const&) = delete;
- scope_fail& operator= (scope_fail const&) = delete;
- };
- #if !defined(BOOST_NO_CXX17_DEDUCTION_GUIDES)
- template< typename Func >
- explicit scope_fail(Func) -> scope_fail< Func >;
- template< typename Func >
- explicit scope_fail(Func, bool) -> scope_fail< Func >;
- template<
- typename Func,
- typename Cond,
- typename = typename std::enable_if< detail::is_invocable< Cond const& >::value >::type
- >
- explicit scope_fail(Func, Cond) -> scope_fail< Func, Cond >;
- template<
- typename Func,
- typename Cond,
- typename = typename std::enable_if< detail::is_invocable< Cond const& >::value >::type
- >
- explicit scope_fail(Func, Cond, bool) -> scope_fail< Func, Cond >;
- #endif
- template< typename F >
- inline scope_fail< typename std::decay< F >::type > make_scope_fail(F&& func, bool active = true)
- noexcept(std::is_nothrow_constructible<
- scope_fail< typename std::decay< F >::type >,
- F,
- bool
- >::value)
- {
- return scope_fail< typename std::decay< F >::type >(static_cast< F&& >(func), active);
- }
- template< typename F, typename C >
- inline
- #if !defined(BOOST_SCOPE_DOXYGEN)
- typename std::enable_if<
- detail::is_invocable< C const& >::value,
- scope_fail< typename std::decay< F >::type, typename std::decay< C >::type >
- >::type
- #else
- scope_fail< typename std::decay< F >::type, typename std::decay< C >::type >
- #endif
- make_scope_fail(F&& func, C&& cond, bool active = true)
- noexcept(std::is_nothrow_constructible<
- scope_fail< typename std::decay< F >::type, typename std::decay< C >::type >,
- F,
- C,
- bool
- >::value)
- {
- return scope_fail< typename std::decay< F >::type, typename std::decay< C >::type >(static_cast< F&& >(func), static_cast< C&& >(cond), active);
- }
- }
- }
- #include <boost/scope/detail/footer.hpp>
- #endif
|