mirror of
https://github.com/boostorg/leaf.git
synced 2026-02-01 08:32:14 +00:00
Deleted match_if, function pointers can be passed to match now.
This commit is contained in:
@@ -1895,7 +1895,7 @@ namespace boost { namespace leaf {
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR int get_id() const noexcept
|
||||
int get_id() const noexcept
|
||||
{
|
||||
int err_id = leaf_detail::current_id();
|
||||
if( err_id != err_id_ )
|
||||
@@ -1904,12 +1904,12 @@ namespace boost { namespace leaf {
|
||||
return leaf_detail::new_id();
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR error_id check() const noexcept
|
||||
error_id check() const noexcept
|
||||
{
|
||||
return leaf_detail::make_error_id(check_id());
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR error_id assigned_error_id() const noexcept
|
||||
error_id assigned_error_id() const noexcept
|
||||
{
|
||||
return leaf_detail::make_error_id(get_id());
|
||||
}
|
||||
@@ -2184,7 +2184,7 @@ namespace boost { namespace leaf {
|
||||
|
||||
public:
|
||||
|
||||
BOOST_LEAF_CONSTEXPR capturing_exception(std::exception_ptr && ex, context_ptr && ctx) noexcept:
|
||||
capturing_exception(std::exception_ptr && ex, context_ptr && ctx) noexcept:
|
||||
ex_(std::move(ex)),
|
||||
ctx_(std::move(ctx))
|
||||
{
|
||||
@@ -2540,10 +2540,10 @@ namespace boost { namespace leaf {
|
||||
struct e_unexpected_info;
|
||||
#endif
|
||||
|
||||
template <class A, bool RequiresCatch = std::is_base_of<std::exception, typename std::decay<A>::type>::value>
|
||||
template <class E, bool RequiresCatch = std::is_base_of<std::exception, typename std::decay<E>::type>::value>
|
||||
struct handler_argument_traits_defaults
|
||||
{
|
||||
using error_type = typename std::decay<A>::type;
|
||||
using error_type = typename std::decay<E>::type;
|
||||
constexpr static bool requires_catch = RequiresCatch;
|
||||
constexpr static bool always_available = false;
|
||||
|
||||
@@ -2554,20 +2554,20 @@ namespace boost { namespace leaf {
|
||||
BOOST_LEAF_CONSTEXPR static error_type * check( Tup &, error_info const & ) noexcept;
|
||||
|
||||
template <class Tup>
|
||||
BOOST_LEAF_CONSTEXPR static A get( Tup & tup, error_info const & ei ) noexcept
|
||||
BOOST_LEAF_CONSTEXPR static E get( Tup & tup, error_info const & ei ) noexcept
|
||||
{
|
||||
return *check(tup, ei);
|
||||
}
|
||||
|
||||
static_assert(!std::is_same<A, error_info>::value, "Handlers must take leaf::error_info arguments by const &");
|
||||
static_assert(!std::is_same<A, diagnostic_info>::value, "Handlers must take leaf::diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<A, verbose_diagnostic_info>::value, "Handlers must take leaf::verbose_diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<E, error_info>::value, "Handlers must take leaf::error_info arguments by const &");
|
||||
static_assert(!std::is_same<E, diagnostic_info>::value, "Handlers must take leaf::diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<E, verbose_diagnostic_info>::value, "Handlers must take leaf::verbose_diagnostic_info arguments by const &");
|
||||
};
|
||||
|
||||
template <class A>
|
||||
template <class E>
|
||||
struct handler_argument_always_available
|
||||
{
|
||||
using error_type = A;
|
||||
using error_type = E;
|
||||
constexpr static bool requires_catch = false;
|
||||
constexpr static bool always_available = true;
|
||||
|
||||
@@ -2578,24 +2578,24 @@ namespace boost { namespace leaf {
|
||||
};
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits: handler_argument_traits_defaults<A>
|
||||
template <class E>
|
||||
struct handler_argument_traits: handler_argument_traits_defaults<E>
|
||||
{
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits<A &&>
|
||||
template <class E>
|
||||
struct handler_argument_traits<E &&>
|
||||
{
|
||||
static_assert(sizeof(A) == 0, "Error handlers may not take rvalue ref arguments");
|
||||
static_assert(sizeof(E) == 0, "Error handlers may not take rvalue ref arguments");
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits<A *>: handler_argument_always_available<typename std::remove_const<A>::type>
|
||||
template <class E>
|
||||
struct handler_argument_traits<E *>: handler_argument_always_available<typename std::remove_const<E>::type>
|
||||
{
|
||||
template <class Tup>
|
||||
BOOST_LEAF_CONSTEXPR static A * get( Tup & tup, error_info const & ei) noexcept
|
||||
BOOST_LEAF_CONSTEXPR static E * get( Tup & tup, error_info const & ei) noexcept
|
||||
{
|
||||
return handler_argument_traits_defaults<A>::check(tup, ei);
|
||||
return handler_argument_traits_defaults<E>::check(tup, ei);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2664,23 +2664,32 @@ namespace boost { namespace leaf {
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class MatchType>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, bool (*pred)(MatchType const &) noexcept ) noexcept
|
||||
#if __cplusplus >= 201703L
|
||||
template <class MatchType, class T>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, bool (*P)(T) noexcept ) noexcept
|
||||
{
|
||||
BOOST_LEAF_ASSERT(pred != 0);
|
||||
return pred(x);
|
||||
BOOST_LEAF_ASSERT(P != 0);
|
||||
return P(e);
|
||||
}
|
||||
|
||||
template <class MatchType, class V>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, V v ) noexcept
|
||||
template <class MatchType, class T>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, bool (*P)(T) )
|
||||
{
|
||||
return x == v;
|
||||
BOOST_LEAF_ASSERT(P != 0);
|
||||
return P(e);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class MatchType, class V>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, V v )
|
||||
{
|
||||
return e == v;
|
||||
}
|
||||
|
||||
template <class MatchType, class VCar, class... VCdr>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, VCar car, VCdr ... cdr ) noexcept
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, VCar car, VCdr ... cdr )
|
||||
{
|
||||
return cmp_value_pack(x, car) || cmp_value_pack(x, cdr...);
|
||||
return cmp_value_pack(e, car) || cmp_value_pack(e, cdr...);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2797,43 +2806,6 @@ namespace boost { namespace leaf {
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class E, bool (*F)(E const &)>
|
||||
struct match_if;
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class E, bool (*F)(E const &)>
|
||||
struct handler_argument_traits<match_if<E, F>>: handler_argument_pred<match_if<E, F>>
|
||||
{
|
||||
};
|
||||
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> const &>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> const *>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> &>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> *>: bad_predicate<match_if<E, F>> { };
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class P>
|
||||
struct if_not;
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class P>
|
||||
struct handler_argument_traits<if_not<P>>: handler_argument_pred<if_not<P>>
|
||||
{
|
||||
};
|
||||
|
||||
template <class P> struct handler_argument_traits<if_not<P> const &>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> const *>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> &>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> *>: bad_predicate<if_not<P>> { };
|
||||
}
|
||||
|
||||
|
||||
} }
|
||||
|
||||
#ifndef BOOST_LEAF_NO_EXCEPTIONS
|
||||
@@ -4409,12 +4381,14 @@ namespace boost { namespace leaf {
|
||||
static_assert(std::is_error_condition_enum<Enum>::value || std::is_error_code_enum<Enum>::value, "leaf::condition<Enum> requires Enum to be registered either with std::is_error_condition_enum or std::is_error_code_enum.");
|
||||
};
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
template <class ErrorCodeEnum>
|
||||
BOOST_LEAF_CONSTEXPR inline bool category( std::error_code const & ec ) noexcept
|
||||
{
|
||||
static_assert(std::is_error_code_enum<ErrorCodeEnum>::value, "leaf::category requires an error code enum");
|
||||
return &ec.category() == &std::error_code(ErrorCodeEnum{}).category();
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
@@ -4611,24 +4585,6 @@ namespace boost { namespace leaf {
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class E, bool(*F)(E const &)>
|
||||
struct match_if: leaf_detail::pred<E const &>
|
||||
{
|
||||
using error_type = E;
|
||||
|
||||
BOOST_LEAF_CONSTEXPR explicit match_if(E const & e) noexcept:
|
||||
leaf_detail::pred<E const &>(e)
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR static bool evaluate(E const & e) noexcept
|
||||
{
|
||||
return F(e);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class P>
|
||||
struct if_not: leaf_detail::pred<typename P::error_type const &>
|
||||
{
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace boost { namespace leaf {
|
||||
|
||||
public:
|
||||
|
||||
BOOST_LEAF_CONSTEXPR capturing_exception(std::exception_ptr && ex, context_ptr && ctx) noexcept:
|
||||
capturing_exception(std::exception_ptr && ex, context_ptr && ctx) noexcept:
|
||||
ex_(std::move(ex)),
|
||||
ctx_(std::move(ctx))
|
||||
{
|
||||
|
||||
@@ -36,10 +36,10 @@ namespace boost { namespace leaf {
|
||||
struct e_unexpected_info;
|
||||
#endif
|
||||
|
||||
template <class A, bool RequiresCatch = std::is_base_of<std::exception, typename std::decay<A>::type>::value>
|
||||
template <class E, bool RequiresCatch = std::is_base_of<std::exception, typename std::decay<E>::type>::value>
|
||||
struct handler_argument_traits_defaults
|
||||
{
|
||||
using error_type = typename std::decay<A>::type;
|
||||
using error_type = typename std::decay<E>::type;
|
||||
constexpr static bool requires_catch = RequiresCatch;
|
||||
constexpr static bool always_available = false;
|
||||
|
||||
@@ -50,20 +50,20 @@ namespace boost { namespace leaf {
|
||||
BOOST_LEAF_CONSTEXPR static error_type * check( Tup &, error_info const & ) noexcept;
|
||||
|
||||
template <class Tup>
|
||||
BOOST_LEAF_CONSTEXPR static A get( Tup & tup, error_info const & ei ) noexcept
|
||||
BOOST_LEAF_CONSTEXPR static E get( Tup & tup, error_info const & ei ) noexcept
|
||||
{
|
||||
return *check(tup, ei);
|
||||
}
|
||||
|
||||
static_assert(!std::is_same<A, error_info>::value, "Handlers must take leaf::error_info arguments by const &");
|
||||
static_assert(!std::is_same<A, diagnostic_info>::value, "Handlers must take leaf::diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<A, verbose_diagnostic_info>::value, "Handlers must take leaf::verbose_diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<E, error_info>::value, "Handlers must take leaf::error_info arguments by const &");
|
||||
static_assert(!std::is_same<E, diagnostic_info>::value, "Handlers must take leaf::diagnostic_info arguments by const &");
|
||||
static_assert(!std::is_same<E, verbose_diagnostic_info>::value, "Handlers must take leaf::verbose_diagnostic_info arguments by const &");
|
||||
};
|
||||
|
||||
template <class A>
|
||||
template <class E>
|
||||
struct handler_argument_always_available
|
||||
{
|
||||
using error_type = A;
|
||||
using error_type = E;
|
||||
constexpr static bool requires_catch = false;
|
||||
constexpr static bool always_available = true;
|
||||
|
||||
@@ -74,24 +74,24 @@ namespace boost { namespace leaf {
|
||||
};
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits: handler_argument_traits_defaults<A>
|
||||
template <class E>
|
||||
struct handler_argument_traits: handler_argument_traits_defaults<E>
|
||||
{
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits<A &&>
|
||||
template <class E>
|
||||
struct handler_argument_traits<E &&>
|
||||
{
|
||||
static_assert(sizeof(A) == 0, "Error handlers may not take rvalue ref arguments");
|
||||
static_assert(sizeof(E) == 0, "Error handlers may not take rvalue ref arguments");
|
||||
};
|
||||
|
||||
template <class A>
|
||||
struct handler_argument_traits<A *>: handler_argument_always_available<typename std::remove_const<A>::type>
|
||||
template <class E>
|
||||
struct handler_argument_traits<E *>: handler_argument_always_available<typename std::remove_const<E>::type>
|
||||
{
|
||||
template <class Tup>
|
||||
BOOST_LEAF_CONSTEXPR static A * get( Tup & tup, error_info const & ei) noexcept
|
||||
BOOST_LEAF_CONSTEXPR static E * get( Tup & tup, error_info const & ei) noexcept
|
||||
{
|
||||
return handler_argument_traits_defaults<A>::check(tup, ei);
|
||||
return handler_argument_traits_defaults<E>::check(tup, ei);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -160,23 +160,32 @@ namespace boost { namespace leaf {
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class MatchType>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, bool (*pred)(MatchType const &) noexcept ) noexcept
|
||||
#if __cplusplus >= 201703L
|
||||
template <class MatchType, class T>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, bool (*P)(T) noexcept ) noexcept
|
||||
{
|
||||
BOOST_LEAF_ASSERT(pred != 0);
|
||||
return pred(x);
|
||||
BOOST_LEAF_ASSERT(P != 0);
|
||||
return P(e);
|
||||
}
|
||||
|
||||
template <class MatchType, class V>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, V v ) noexcept
|
||||
template <class MatchType, class T>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, bool (*P)(T) )
|
||||
{
|
||||
return x == v;
|
||||
BOOST_LEAF_ASSERT(P != 0);
|
||||
return P(e);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class MatchType, class V>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, V v )
|
||||
{
|
||||
return e == v;
|
||||
}
|
||||
|
||||
template <class MatchType, class VCar, class... VCdr>
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & x, VCar car, VCdr ... cdr ) noexcept
|
||||
BOOST_LEAF_CONSTEXPR BOOST_LEAF_ALWAYS_INLINE bool cmp_value_pack( MatchType const & e, VCar car, VCdr ... cdr )
|
||||
{
|
||||
return cmp_value_pack(x, car) || cmp_value_pack(x, cdr...);
|
||||
return cmp_value_pack(e, car) || cmp_value_pack(e, cdr...);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,43 +302,6 @@ namespace boost { namespace leaf {
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class E, bool (*F)(E const &)>
|
||||
struct match_if;
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class E, bool (*F)(E const &)>
|
||||
struct handler_argument_traits<match_if<E, F>>: handler_argument_pred<match_if<E, F>>
|
||||
{
|
||||
};
|
||||
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> const &>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> const *>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> &>: bad_predicate<match_if<E, F>> { };
|
||||
template <class E, bool (*F)(E const &)> struct handler_argument_traits<match_if<E, F> *>: bad_predicate<match_if<E, F>> { };
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class P>
|
||||
struct if_not;
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
template <class P>
|
||||
struct handler_argument_traits<if_not<P>>: handler_argument_pred<if_not<P>>
|
||||
{
|
||||
};
|
||||
|
||||
template <class P> struct handler_argument_traits<if_not<P> const &>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> const *>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> &>: bad_predicate<if_not<P>> { };
|
||||
template <class P> struct handler_argument_traits<if_not<P> *>: bad_predicate<if_not<P>> { };
|
||||
}
|
||||
|
||||
|
||||
} }
|
||||
|
||||
#ifndef BOOST_LEAF_NO_EXCEPTIONS
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace boost { namespace leaf {
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR int get_id() const noexcept
|
||||
int get_id() const noexcept
|
||||
{
|
||||
int err_id = leaf_detail::current_id();
|
||||
if( err_id != err_id_ )
|
||||
@@ -63,12 +63,12 @@ namespace boost { namespace leaf {
|
||||
return leaf_detail::new_id();
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR error_id check() const noexcept
|
||||
error_id check() const noexcept
|
||||
{
|
||||
return leaf_detail::make_error_id(check_id());
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR error_id assigned_error_id() const noexcept
|
||||
error_id assigned_error_id() const noexcept
|
||||
{
|
||||
return leaf_detail::make_error_id(get_id());
|
||||
}
|
||||
|
||||
@@ -56,12 +56,14 @@ namespace boost { namespace leaf {
|
||||
static_assert(std::is_error_condition_enum<Enum>::value || std::is_error_code_enum<Enum>::value, "leaf::condition<Enum> requires Enum to be registered either with std::is_error_condition_enum or std::is_error_code_enum.");
|
||||
};
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
template <class ErrorCodeEnum>
|
||||
BOOST_LEAF_CONSTEXPR inline bool category( std::error_code const & ec ) noexcept
|
||||
{
|
||||
static_assert(std::is_error_code_enum<ErrorCodeEnum>::value, "leaf::category requires an error code enum");
|
||||
return &ec.category() == &std::error_code(ErrorCodeEnum{}).category();
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
@@ -258,24 +260,6 @@ namespace boost { namespace leaf {
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class E, bool(*F)(E const &)>
|
||||
struct match_if: leaf_detail::pred<E const &>
|
||||
{
|
||||
using error_type = E;
|
||||
|
||||
BOOST_LEAF_CONSTEXPR explicit match_if(E const & e) noexcept:
|
||||
leaf_detail::pred<E const &>(e)
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_LEAF_CONSTEXPR static bool evaluate(E const & e) noexcept
|
||||
{
|
||||
return F(e);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class P>
|
||||
struct if_not: leaf_detail::pred<typename P::error_type const &>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user