mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-24 01:55:41 +01:00
Merge pull request #966 from lioncash/modernize
common: Convert type traits templates over to variable template versions where applicable
This commit is contained in:
commit
d224eb7c39
@ -9,13 +9,13 @@ namespace Common {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignUp(T value, size_t size) {
|
constexpr T AlignUp(T value, size_t size) {
|
||||||
static_assert(std::is_unsigned<T>::value, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return static_cast<T>(value + (size - value % size) % size);
|
return static_cast<T>(value + (size - value % size) % size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignDown(T value, size_t size) {
|
constexpr T AlignDown(T value, size_t size) {
|
||||||
static_assert(std::is_unsigned<T>::value, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return static_cast<T>(value - value % size);
|
return static_cast<T>(value - value % size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ static inline int LeastSignificantSetBit(u64 val) {
|
|||||||
|
|
||||||
template <typename IntTy>
|
template <typename IntTy>
|
||||||
class BitSet {
|
class BitSet {
|
||||||
static_assert(!std::is_signed<IntTy>::value, "BitSet should not be used with signed types");
|
static_assert(!std::is_signed_v<IntTy>, "BitSet should not be used with signed types");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// A reference to a particular bit, returned from operator[].
|
// A reference to a particular bit, returned from operator[].
|
||||||
|
@ -208,7 +208,7 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t ReadArray(T* data, size_t length) const {
|
size_t ReadArray(T* data, size_t length) const {
|
||||||
static_assert(std::is_trivially_copyable<T>(),
|
static_assert(std::is_trivially_copyable_v<T>,
|
||||||
"Given array does not consist of trivially copyable objects");
|
"Given array does not consist of trivially copyable objects");
|
||||||
|
|
||||||
if (!IsOpen()) {
|
if (!IsOpen()) {
|
||||||
@ -220,7 +220,7 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t WriteArray(const T* data, size_t length) {
|
size_t WriteArray(const T* data, size_t length) {
|
||||||
static_assert(std::is_trivially_copyable<T>(),
|
static_assert(std::is_trivially_copyable_v<T>,
|
||||||
"Given array does not consist of trivially copyable objects");
|
"Given array does not consist of trivially copyable objects");
|
||||||
if (!IsOpen()) {
|
if (!IsOpen()) {
|
||||||
return std::numeric_limits<size_t>::max();
|
return std::numeric_limits<size_t>::max();
|
||||||
@ -231,19 +231,19 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t ReadBytes(T* data, size_t length) const {
|
size_t ReadBytes(T* data, size_t length) const {
|
||||||
static_assert(std::is_trivially_copyable<T>(), "T must be trivially copyable");
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
|
||||||
return ReadArray(reinterpret_cast<char*>(data), length);
|
return ReadArray(reinterpret_cast<char*>(data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t WriteBytes(const T* data, size_t length) {
|
size_t WriteBytes(const T* data, size_t length) {
|
||||||
static_assert(std::is_trivially_copyable<T>(), "T must be trivially copyable");
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
|
||||||
return WriteArray(reinterpret_cast<const char*>(data), length);
|
return WriteArray(reinterpret_cast<const char*>(data), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t WriteObject(const T& object) {
|
size_t WriteObject(const T& object) {
|
||||||
static_assert(!std::is_pointer<T>::value, "Given object is a pointer");
|
static_assert(!std::is_pointer_v<T>, "WriteObject arguments must not be a pointer");
|
||||||
return WriteArray(&object, 1);
|
return WriteArray(&object, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ static inline u64 ComputeHash64(const void* data, size_t len) {
|
|||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static inline u64 ComputeStructHash64(const T& data) {
|
static inline u64 ComputeStructHash64(const T& data) {
|
||||||
static_assert(std::is_trivially_copyable<T>(),
|
static_assert(std::is_trivially_copyable_v<T>,
|
||||||
"Type passed to ComputeStructHash64 must be trivially copyable");
|
"Type passed to ComputeStructHash64 must be trivially copyable");
|
||||||
return ComputeHash64(&data, sizeof(data));
|
return ComputeHash64(&data, sizeof(data));
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ template <typename T>
|
|||||||
struct HashableStruct {
|
struct HashableStruct {
|
||||||
// In addition to being trivially copyable, T must also have a trivial default constructor,
|
// In addition to being trivially copyable, T must also have a trivial default constructor,
|
||||||
// because any member initialization would be overridden by memset
|
// because any member initialization would be overridden by memset
|
||||||
static_assert(std::is_trivial<T>(), "Type passed to HashableStruct must be trivial");
|
static_assert(std::is_trivial_v<T>, "Type passed to HashableStruct must be trivial");
|
||||||
/*
|
/*
|
||||||
* We use a union because "implicitly-defined copy/move constructor for a union X copies the
|
* We use a union because "implicitly-defined copy/move constructor for a union X copies the
|
||||||
* object representation of X." and "implicitly-defined copy assignment operator for a union X
|
* object representation of X." and "implicitly-defined copy assignment operator for a union X
|
||||||
|
@ -34,7 +34,7 @@ inline bool IsWithin2G(const Xbyak::CodeGenerator& code, uintptr_t target) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) {
|
inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) {
|
||||||
static_assert(std::is_pointer<T>(), "Argument must be a (function) pointer.");
|
static_assert(std::is_pointer_v<T>, "Argument must be a (function) pointer.");
|
||||||
size_t addr = reinterpret_cast<size_t>(f);
|
size_t addr = reinterpret_cast<size_t>(f);
|
||||||
if (IsWithin2G(code, addr)) {
|
if (IsWithin2G(code, addr)) {
|
||||||
code.call(f);
|
code.call(f);
|
||||||
|
Loading…
Reference in New Issue
Block a user