summaryrefslogtreecommitdiff
path: root/boost/safe_numerics/checked_default.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/safe_numerics/checked_default.hpp')
-rw-r--r--boost/safe_numerics/checked_default.hpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/boost/safe_numerics/checked_default.hpp b/boost/safe_numerics/checked_default.hpp
index 5a5bb44d24..07699c4fca 100644
--- a/boost/safe_numerics/checked_default.hpp
+++ b/boost/safe_numerics/checked_default.hpp
@@ -1,11 +1,6 @@
#ifndef BOOST_NUMERIC_CHECKED_DEFAULT_HPP
#define BOOST_NUMERIC_CHECKED_DEFAULT_HPP
-// MS compatible compilers support #pragma once
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-# pragma once
-#endif
-
// Copyright (c) 2017 Robert Ramey
//
// Distributed under the Boost Software License, Version 1.0. (See
@@ -49,14 +44,27 @@ namespace safe_numerics {
// it should trap with a static_assert. This occurs at compile time while
// calculating result interval. This needs more investigation.
-template<typename R, typename T = void, class Default = void>
-struct checked_operation{
+template<
+ typename R,
+ typename T,
+ class F = make_checked_result<R>,
+ class Default = void
+>
+struct heterogeneous_checked_operation {
constexpr static checked_result<R>
cast(const T & t) /* noexcept */ {
return static_cast<R>(t);
}
- constexpr static checked_result<T>
- minus(const T & t) noexcept {
+};
+
+template<
+ typename R,
+ class F = make_checked_result<R>,
+ class Default = void
+>
+struct checked_operation{
+ constexpr static checked_result<R>
+ minus(const R & t) noexcept {
return - t;
}
constexpr static checked_result<R>
@@ -124,7 +132,7 @@ namespace checked {
template<typename R, typename T>
constexpr checked_result<R> cast(const T & t) /* noexcept */ {
- return checked_operation<R, T>::cast(t);
+ return heterogeneous_checked_operation<R, T>::cast(t);
}
template<typename R>
constexpr checked_result<R> minus(const R & t) noexcept {
@@ -184,7 +192,7 @@ constexpr checked_result<R> bitwise_or(const R & t, const R & u) noexcept {
}
template<typename R>
constexpr checked_result<R> bitwise_xor(const R & t, const R & u) noexcept {
- return checked_operation<R>::bitwise_or(t, u);
+ return checked_operation<R>::bitwise_xor(t, u);
}
template<typename R>
constexpr checked_result<R> bitwise_and(const R & t, const R & u) noexcept {
@@ -200,4 +208,3 @@ constexpr checked_result<R> bitwise_not(const R & t) noexcept {
} // boost
#endif // BOOST_NUMERIC_CHECKED_DEFAULT_HPP
-