From 00eca4445bbd849a6310351d6c251bd9cd775aa0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 10 Aug 2016 17:36:25 +1000 Subject: [PATCH] debug: use less complex specialistion for validator --- debug.hpp | 21 ++++++++++++++------- extent.cpp | 12 ++++++------ geom/aabb.cpp | 4 ++-- region.cpp | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/debug.hpp b/debug.hpp index 21d1694a..3daa4eae 100644 --- a/debug.hpp +++ b/debug.hpp @@ -77,7 +77,7 @@ #define CHECK_SANITY(A) do { \ DEBUG_ONLY( \ const auto &__a = (A); \ - if (!util::debug::valid (__a)) { \ + if (!util::debug::is_valid (__a)) { \ _CHECK_PANIC("failed sanity test for %s, %!\n", #A, __a); \ } \ ); \ @@ -344,7 +344,14 @@ namespace util { namespace debug { template - bool valid (const T&); + struct validator { + static bool is_valid (const T&); + }; + + + template + bool is_valid (const T &t) + { return validator::is_valid (t); } template < @@ -352,7 +359,7 @@ namespace util { namespace debug { size_t S, typename ...Args > - struct validator { + struct validator> { static bool is_valid (const T&); }; @@ -362,15 +369,15 @@ namespace util { namespace debug { size_t S, typename ...Args > - bool valid (const T &v) - { return validator::is_valid (v); } + bool is_valid (const T &v) + { return validator>::is_valid (v); } template void sanity (const T &t) { (void)t; - CHECK (valid (t)); + CHECK (is_valid (t)); } @@ -381,7 +388,7 @@ namespace util { namespace debug { void sanity (const T &t) { (void)t; - CHECK (valid (t)); + CHECK (is_valid (t)); } } } diff --git a/extent.cpp b/extent.cpp index 7e1c3eb0..a6bb2a47 100644 --- a/extent.cpp +++ b/extent.cpp @@ -216,7 +216,7 @@ extent_range::iterator::operator!= (const iterator &rhs) const /////////////////////////////////////////////////////////////////////////////// namespace util { namespace debug { template - struct validator { + struct validator> { static bool is_valid (const extent &e) { return std::all_of (std::begin (e.data), @@ -226,11 +226,11 @@ namespace util { namespace debug { }; } } -template bool util::debug::valid (const extent<2,float>&); -template bool util::debug::valid (const extent<2,double>&); -template bool util::debug::valid (const extent<2,uint16_t>&); -template bool util::debug::valid (const extent<2,uint32_t>&); -template bool util::debug::valid (const extent<2,uint64_t>&); +template bool util::debug::is_valid (const extent<2,float>&); +template bool util::debug::is_valid (const extent<2,double>&); +template bool util::debug::is_valid (const extent<2,uint16_t>&); +template bool util::debug::is_valid (const extent<2,uint32_t>&); +template bool util::debug::is_valid (const extent<2,uint64_t>&); //----------------------------------------------------------------------------- diff --git a/geom/aabb.cpp b/geom/aabb.cpp index 4a1071d2..3aac3ff9 100644 --- a/geom/aabb.cpp +++ b/geom/aabb.cpp @@ -209,7 +209,7 @@ AABB::operator== (const AABB rhs) const //----------------------------------------------------------------------------- namespace util { namespace debug { template - struct validator { + struct validator> { static bool is_valid (const AABB &b) { for (size_t i = 0; i < S; ++i) @@ -235,7 +235,7 @@ util::geom::operator<< (std::ostream &os, util::geom::AABB b) //----------------------------------------------------------------------------- #define INSTANTIATE_S_T(S,T) \ namespace util { namespace geom { template struct AABB; } } \ -template bool util::debug::valid (const AABB&); \ +template bool util::debug::is_valid (const AABB&); \ template std::ostream& util::geom::operator<< (std::ostream&, AABB); #define INSTANTIATE(T) \ diff --git a/region.cpp b/region.cpp index 162d989b..72369252 100644 --- a/region.cpp +++ b/region.cpp @@ -388,7 +388,7 @@ namespace util { namespace debug { #define INSTANTIATE_S_T(S,T) \ template struct util::region; \ template std::ostream& util::operator<< (std::ostream&, const region&); \ -template struct util::debug::validator; +template struct util::debug::validator>; #define INSTANTIATE(T) \ INSTANTIATE_S_T(2,T) \