|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75196 - in trunk/boost/math: distributions policies
From: john_at_[hidden]
Date: 2011-10-31 12:38:17
Author: johnmaddock
Date: 2011-10-31 12:38:16 EDT (Mon, 31 Oct 2011)
New Revision: 75196
URL: http://svn.boost.org/trac/boost/changeset/75196
Log:
Allow distribution parameter checking to be eluded if it's already taken place.
Text files modified:
trunk/boost/math/distributions/bernoulli.hpp | 17 ++++++++++++++---
trunk/boost/math/policies/policy.hpp | 23 +++++++++++++++++++++++
2 files changed, 37 insertions(+), 3 deletions(-)
Modified: trunk/boost/math/distributions/bernoulli.hpp
==============================================================================
--- trunk/boost/math/distributions/bernoulli.hpp (original)
+++ trunk/boost/math/distributions/bernoulli.hpp 2011-10-31 12:38:16 EDT (Mon, 31 Oct 2011)
@@ -55,14 +55,25 @@
return true;
}
template <class RealType, class Policy>
- inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
+ inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */, const mpl::true_&)
{
return check_success_fraction(function, p, result, Policy());
}
template <class RealType, class Policy>
+ inline bool check_dist(const char* , const RealType& , RealType* , const Policy& /* pol */, const mpl::false_&)
+ {
+ return true;
+ }
+ template <class RealType, class Policy>
+ inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
+ {
+ return check_dist(function, p, result, Policy(), typename policies::constructor_error_check<Policy>::type());
+ }
+
+ template <class RealType, class Policy>
inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol)
{
- if(check_dist(function, p, result, Policy()) == false)
+ if(check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) == false)
{
return false;
}
@@ -78,7 +89,7 @@
template <class RealType, class Policy>
inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result, const Policy& /* pol */)
{
- if(check_dist(function, p, result, Policy()) && detail::check_probability(function, prob, result, Policy()) == false)
+ if(check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) && detail::check_probability(function, prob, result, Policy()) == false)
{
return false;
}
Modified: trunk/boost/math/policies/policy.hpp
==============================================================================
--- trunk/boost/math/policies/policy.hpp (original)
+++ trunk/boost/math/policies/policy.hpp 2011-10-31 12:38:16 EDT (Mon, 31 Oct 2011)
@@ -951,6 +951,29 @@
template <class P>
struct is_policy : public mpl::bool_< ::boost::math::policies::detail::is_policy_imp<P>::value> {};
+//
+// Helper traits class for distribution error handling:
+//
+template <class Policy>
+struct constructor_error_check
+{
+ typedef typename Policy::domain_error_type domain_error_type;
+ typedef typename mpl::if_c<
+ (domain_error_type::value == throw_on_error) || (domain_error_type::value == user_error),
+ mpl::true_,
+ mpl::false_>::type type;
+};
+
+template <class Policy>
+struct method_error_check
+{
+ typedef typename Policy::domain_error_type domain_error_type;
+ typedef typename mpl::if_c<
+ (domain_error_type::value == throw_on_error) && (domain_error_type::value != user_error),
+ mpl::false_,
+ mpl::true_>::type type;
+};
+
}}} // namespaces
#endif // BOOST_MATH_POLICY_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk