debug: allow specialisation of validator for aux validation variables

This commit is contained in:
Danny Robson 2018-06-29 13:08:32 +10:00
parent 4e10aa59b2
commit 23e581ad6a

View File

@ -562,24 +562,27 @@ namespace util::debug {
// returns true if an instance of type `T' appears to be in a valid state.
//
// written as a struct rather than a function so that behaviour may be
// arbitrarily specialised. all users are free to specialise this struct
// partially specialised. all users are free to specialise this struct
// with an user types.
//
// all specialisations must be safe to call on arbitrary data without
// exceptions or faults as this mechanism is used to control some
// debugging paths which themselves are the configuration points for
// throwing/logging/etc behaviour.
template <typename T>
//
// ArgsT is an optional set of auxiliary values that are required to
// validate the target value.
template <typename T, typename ...ArgsT>
struct validator {
static bool is_valid (const T&) noexcept;
static bool is_valid (T const&, ArgsT const&...) noexcept;
};
//-------------------------------------------------------------------------
template <typename T>
bool is_valid (const T &t) noexcept
template <typename T, typename ...ArgsT>
bool is_valid (const T &t, const ArgsT &...args) noexcept
{
return validator<T>::is_valid (t);
return validator<T,ArgsT...>::is_valid (t, args...);
}
@ -587,11 +590,11 @@ namespace util::debug {
// forwarding validator from a pointer type to a reference type.
//
// null pointers are assumed to be invalid
template <typename T>
struct validator<T*> {
static bool is_valid (const T *val) noexcept
template <typename T, typename ...ArgsT>
struct validator<T*,ArgsT...> {
static bool is_valid (const T *val, ArgsT const &...args) noexcept
{
return val && ::util::debug::is_valid (*val);
return val && ::util::debug::is_valid (*val, args...);
}
};