1
0
mirror of https://github.com/sendyne/cppreg.git synced 2025-05-09 15:14:05 +00:00

REVISED OVERFLOW IMPLEMENTATION USING INTEGRAL CONSTANT

The check_overflow implementation now relies on std::integral_constant.
This avoids the definition of a constexpr bool member.
This commit is contained in:
Nicolas Clauvelin 2018-03-13 17:28:38 -04:00
parent ee48bbd261
commit 8ce22c666d
4 changed files with 10 additions and 16 deletions

View File

@ -79,14 +79,11 @@ namespace cppreg {
* This is only used for the template form of the write method.
*/
template <type value>
struct check_overflow {
constexpr static const bool result =
internals::check_overflow<
parent_register::size,
value,
(mask >> offset)
>::result::value;
};
struct check_overflow : internals::check_overflow<
parent_register::size,
value,
(mask >> offset)
> {};
//!@ Field read method.
/**
@ -147,7 +144,7 @@ namespace cppreg {
typename std::enable_if<
!has_shadow
&&
check_overflow<value>::result,
check_overflow<value>::value,
T
>::type
write() noexcept {
@ -168,7 +165,7 @@ namespace cppreg {
typename std::enable_if<
has_shadow
&&
check_overflow<value>::result,
check_overflow<value>::value,
T
>::type
write() noexcept {

View File

@ -131,7 +131,7 @@ namespace cppreg {
typename std::enable_if<
(internals::check_overflow<
Register::size, new_value, (F::mask >> F::offset)
>::result::value),
>::value),
T
>::type&&
with() const && noexcept {

View File

@ -34,10 +34,7 @@ namespace internals {
typename RegisterType<W>::type value,
typename RegisterType<W>::type limit
>
struct check_overflow {
using result =
typename std::integral_constant<bool, value <= limit>::type;
};
struct check_overflow : std::integral_constant<bool, value <= limit> {};
}

View File

@ -110,7 +110,7 @@ namespace cppreg {
typename std::enable_if<
internals::check_overflow<
size, value, (F::mask >> F::offset)
>::result::value,
>::value,
T
>::type&&
merge_write() noexcept {