constexpr implies inline, generalise iabs, work around lack of C++14 constexpr in VS2015 (nw)

This commit is contained in:
Vas Crabb 2017-12-01 23:45:11 +11:00
parent 3917627494
commit f88769555b
3 changed files with 5 additions and 7 deletions

View File

@ -433,12 +433,10 @@ inline u64 d2u(double d)
// constexpr absolute value of an integer
inline constexpr int iabs(int v)
template <typename T>
constexpr std::enable_if_t<std::is_signed<T>::value, T> iabs(T v)
{
if(v < 0)
return -v;
else
return v;
return (v < T(0)) ? -v : v;
}
#endif /* MAME_EMU_EMUCORE_H */

View File

@ -894,7 +894,7 @@ class address_space_specific : public address_space
u32 write_lookup(offs_t address) const { return Large ? m_write.lookup_live_large(address) : m_write.lookup_live_small(address); }
u32 setoffset_lookup(offs_t address) const { return Large ? m_setoffset.lookup_live_large(address) : m_setoffset.lookup_live_small(address); }
static inline constexpr offs_t offset_to_byte(offs_t offset) { return AddrShift < 0 ? offset << iabs(AddrShift) : offset >> iabs(AddrShift); }
static constexpr offs_t offset_to_byte(offs_t offset) { return AddrShift < 0 ? offset << iabs(AddrShift) : offset >> iabs(AddrShift); }
public:
// construction/destruction

View File

@ -162,7 +162,7 @@ public:
void remove_intersecting_ranges(offs_t start, offs_t end);
static inline constexpr offs_t offset_to_byte(offs_t offset) { return AddrShift < 0 ? offset << iabs(AddrShift) : offset >> iabs(AddrShift); }
static constexpr offs_t offset_to_byte(offs_t offset) { return AddrShift < 0 ? offset << iabs(AddrShift) : offset >> iabs(AddrShift); }
private:
// internal helpers