From d7ae9eb09e3e58ce02a385289e2df85d76ece301 Mon Sep 17 00:00:00 2001 From: Robert Ramey Date: Wed, 24 Jun 2015 09:08:40 -0700 Subject: [PATCH] fixed modulus and test_modulus --- include/safe_base.hpp | 13 ++++++++++--- include/safe_base_operations.hpp | 11 ++++++----- test/test_modulus.cpp | 6 +++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/safe_base.hpp b/include/safe_base.hpp index a0ff378..ed891ef 100644 --- a/include/safe_base.hpp +++ b/include/safe_base.hpp @@ -40,8 +40,15 @@ class safe_base { template SAFE_NUMERIC_CONSTEXPR bool validate(const T & t) const { return ! ( - boost::numeric::checked::greater_than(t, base_value(Derived::max())) - && boost::numeric::checked::less_than(t, base_value(Derived::min())) + boost::numeric::checked::greater_than( + base_value(t), + base_value(Derived::max()) + ) + && + boost::numeric::checked::less_than( + base_value(t), + base_value(Derived::min()) + ) ); } Stored m_t; @@ -92,7 +99,7 @@ public: // modification binary operators template Derived & operator=(const T & rhs){ - if(! derived().validate(rhs)){ + if(! validate(rhs)){ E::range_error( "Invalid value passed on assignment" ); diff --git a/include/safe_base_operations.hpp b/include/safe_base_operations.hpp index d596b69..9dd0044 100644 --- a/include/safe_base_operations.hpp +++ b/include/safe_base_operations.hpp @@ -402,8 +402,9 @@ typename boost::lazy_enable_if< inline operator%(const T & t, const U & u){ // argument dependent lookup should guarentee that we only get here // only if one of the types is a safe type. Verify this here - typedef modulus_result ar; - typedef typename ar::type result_type; + typedef modulus_result mr; + typedef typename mr::P::exception_policy exception_policy; + typedef typename mr::type result_type; static_assert( boost::numeric::is_safe::value, "Promotion failed to return safe type" @@ -438,9 +439,9 @@ inline operator%(const T & t, const U & u){ base_value(u) ); - r.template dispatch(); - - return static_cast(r); + r.template dispatch(); + + return result_type(static_cast(r)); } ///////////////////////////////////////////////////////////////// diff --git a/test/test_modulus.cpp b/test/test_modulus.cpp index 37f31a0..237fc91 100644 --- a/test/test_modulus.cpp +++ b/test/test_modulus.cpp @@ -24,7 +24,7 @@ bool test_modulus( { boost::numeric::safe t1 = v1; // presuming native policy - boost::numeric::safe result; + boost::numeric::safe result; try{ result = t1 % v2; @@ -41,7 +41,7 @@ bool test_modulus( << " ! = "<< av1 << " % " << av2 << std::endl; try{ - result = t1 % v2; + t1 % v2; } catch(std::exception){} return false; @@ -67,7 +67,7 @@ bool test_modulus( boost::numeric::safe t2 = v2; // presuming native policy - boost::numeric::safe result; + boost::numeric::safe result; try{ result = t1 % t2;