documentation updates inspired by ACCU Overload

This commit is contained in:
Robert Ramey
2017-02-03 14:24:05 -08:00
parent 621d2cbe30
commit d0ca1634fc
43 changed files with 601 additions and 494 deletions

View File

@@ -253,15 +253,17 @@ public:
--(*this);
return old_t;
}
safe_base operator-(){ // unary minus
return *this = 0 - *this; // this will check for overflow
// return a safe type. This guarantees that result will
// be checked upon return
constexpr safe_base operator-() const { // unary minus
return 0 - *this; // this will check for overflow
}
safe_base operator~(){
constexpr safe_base operator~() const {
static_assert(
std::numeric_limits<Stored>::is_signed,
"Bitwise inversion of signed value is an error"
);
return *this = ~(m_t);
return ~(m_t);
}
};

View File

@@ -183,12 +183,6 @@ struct common_policies {
"if the promotion policies are different, one must be void!"
);
static_assert(
! std::is_same<t_promotion_policy, void>::value
|| !std::is_same<void, u_promotion_policy>::value,
"at least one promotion polcy must be non void"
);
static_assert(
! (std::is_same<t_promotion_policy, void>::value
&& std::is_same<void, u_promotion_policy>::value),

View File

@@ -13,6 +13,8 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include <cstdint> // for intmax_t/uintmax_t
#include <boost/mpl/if.hpp>
#include "utility.hpp"
#include "safe_base.hpp"
#include "safe_base_operations.hpp"
@@ -94,6 +96,18 @@ public:
constexpr operator R () const {
return N;
}
// return a safe type. This guarantees that result will
// be checked upon return
constexpr safe_literal_impl<decltype(-N), -N, P, E> operator-() const { // unary minus
return 0 - N; // this will check for overflow
}
constexpr safe_literal_impl<decltype(~N), -N, P, E> operator~() const {
static_assert(
std::numeric_limits<T>::is_signed,
"Bitwise inversion of signed value is an error"
);
return ~N;
}
};
template<
@@ -108,7 +122,7 @@ using safe_signed_literal = safe_literal_impl<
E
>;
template <
template<
std::uintmax_t N,
class P = native,
class E = throw_exception
@@ -120,6 +134,13 @@ using safe_unsigned_literal = safe_literal_impl<
E
>;
#define safe_literal(n) \
boost::mpl::if_c< \
std::numeric_limits<decltype<n>>::is_signed>. \
safe_unsigned_literal<n, void, void>, \
safe_signed_literal<n, void, void> \
>::type
} // numeric
} // boost