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. // 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 // 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. // with an user types.
// //
// all specialisations must be safe to call on arbitrary data without // all specialisations must be safe to call on arbitrary data without
// exceptions or faults as this mechanism is used to control some // exceptions or faults as this mechanism is used to control some
// debugging paths which themselves are the configuration points for // debugging paths which themselves are the configuration points for
// throwing/logging/etc behaviour. // 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 { struct validator {
static bool is_valid (const T&) noexcept; static bool is_valid (T const&, ArgsT const&...) noexcept;
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename T> template <typename T, typename ...ArgsT>
bool is_valid (const T &t) noexcept 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. // forwarding validator from a pointer type to a reference type.
// //
// null pointers are assumed to be invalid // null pointers are assumed to be invalid
template <typename T> template <typename T, typename ...ArgsT>
struct validator<T*> { struct validator<T*,ArgsT...> {
static bool is_valid (const T *val) noexcept 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...);
} }
}; };