Struct assertion_verifier

Synopsis

#include <include/type_safe/constrained_type.hpp>

struct assertion_verifier

Description

A Verifier for [ts::constrained_type]() that DEBUG_ASSERTs the constraint.

If [TYPE_SAFE_ENABLE_PRECONDITION_CHECKS]() is true, it will assert that the value fulfills the predicate and returns it unchanged. If assertions are disabled, it will just return the value unchanged. \output_section Constrained type

Methods

verify

Source

Lines 26-37 in include/type_safe/constrained_type.hpp.

struct assertion_verifier
{
    template <typename Value, typename Predicate>
    static constexpr auto verify(Value&& val, const Predicate& p) ->
        typename std::decay<Value>::type
    {
        return p(val) ? std::forward<Value>(val)
                      : (DEBUG_UNREACHABLE(detail::precondition_error_handler{},
                                           "value does not fulfill constraint"),
                         std::forward<Value>(val));
    }
};





Add Discussion as Guest

Log in