48 #ifndef COMMON_OFFSET_TYPE_H 49 #define COMMON_OFFSET_TYPE_H 53 #define DEFINE_OFFSET_TYPE(TYPE, UNDERLYING) \ 54 enum class TYPE : UNDERLYING {}; \ 55 void is_offset_type (TYPE) 76 #define DEFINE_OFFSET_REL_OP(OP) \ 77 template<typename E, \ 78 typename = decltype (is_offset_type (std::declval<E> ()))> \ 80 operator OP (E lhs, E rhs) \ 82 using underlying = typename std::underlying_type<E>::type; \ 83 return (static_cast<underlying> (lhs) \ 84 OP static_cast<underlying> (lhs)); \ 95 #define DEFINE_OFFSET_ARITHM_OP(OP) \ 96 template<typename E, \ 97 typename = decltype (is_offset_type (std::declval<E> ()))> \ 99 operator OP (E lhs, typename std::underlying_type<E>::type rhs) \ 101 using underlying = typename std::underlying_type<E>::type; \ 102 return (E) (static_cast<underlying> (lhs) OP rhs); \ 105 template<typename E, \ 106 typename = decltype (is_offset_type (std::declval<E> ()))> \ 108 operator OP (typename std::underlying_type<E>::type lhs, E rhs) \ 110 using underlying = typename std::underlying_type<E>::type; \ 111 return (E) (lhs OP static_cast<underlying> (rhs)); \ 114 template<typename E, \ 115 typename = decltype (is_offset_type (std::declval<E> ()))> \ 117 operator OP ## = (E &lhs, typename std::underlying_type<E>::type rhs) \ 119 using underlying = typename std::underlying_type<E>::type; \ 120 lhs = (E) (static_cast<underlying> (lhs) OP rhs); \ 132 typename = decltype (is_offset_type (std::declval<E> ()))>
133 constexpr typename std::underlying_type<E>::
type 134 operator+ (E lhs, E rhs) = delete;
141 typename = decltype (is_offset_type (std::declval<E> ()))>
142 constexpr typename std::underlying_type<E>::
type 143 operator- (E lhs, E rhs)
146 return static_cast<underlying
> (lhs) - static_cast<underlying> (rhs);
#define DEFINE_OFFSET_REL_OP(OP)
#define DEFINE_OFFSET_ARITHM_OP(OP)