Small fix

This commit is contained in:
Nekotekina 2015-06-22 03:03:11 +03:00
parent 317417d541
commit c0fdef7a12
2 changed files with 20 additions and 2 deletions

View file

@ -68,14 +68,16 @@ namespace vm
return m_addr != 0; return m_addr != 0;
} }
// test address alignment using alignof(T)
bool aligned() const bool aligned() const
{ {
return m_addr % alignof32(T) == 0; return m_addr % alignof32(T) == 0;
} }
bool operator %(to_ne_t<AT> alignment) // test address for arbitrary alignment or something
force_inline explicit_bool_t operator %(to_ne_t<AT> right) const
{ {
return m_addr % alignment != 0; return m_addr % right;
} }
_ptr_base& operator =(const _ptr_base&) = default; _ptr_base& operator =(const _ptr_base&) = default;

View file

@ -61,6 +61,22 @@ template<typename T, typename = std::enable_if_t<std::is_integral<T>::value>> in
return static_cast<T>((value + (align - 1)) & ~(align - 1)); return static_cast<T>((value + (align - 1)) & ~(align - 1));
} }
// bool wrapper for restricting bool result conversions
struct explicit_bool_t
{
const bool value;
explicit_bool_t(bool value)
: value(value)
{
}
explicit operator bool() const
{
return value;
}
};
// return 32 bit sizeof() to avoid widening/narrowing conversions with size_t // return 32 bit sizeof() to avoid widening/narrowing conversions with size_t
#define sizeof32(type) sizeof32_t<sizeof(type)>::value #define sizeof32(type) sizeof32_t<sizeof(type)>::value