Struct throwing_verifier


#include <include/type_safe/constrained_type.hpp>

struct throwing_verifier


A Verifier for [ts::constrained_type]() that throws an exception in case of failure.

Unlike [ts::assertion_verifier](), it will always check the constrain. If it is not fulfilled, it throws an exception of type [ts::constrain_error](), otherwise return the original value unchanged. \notes [ts::assertion_verifier]() is the default, because a constrain violation is a logic error, usually done by a programmer. Use this one only if you want to use [ts::constrained_type]() with unsanitized user input, for example.

Mentioned in




Lines 58-67 in include/type_safe/constrained_type.hpp.

struct throwing_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)
                      : (TYPE_SAFE_THROW(constrain_error{}), std::forward<Value>(val));

Add Discussion as Guest

Log in