From ea21b740b2e3b2d049b6c823a7bd0df6bc06140e Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 17 Jan 2025 14:14:01 -0800 Subject: [PATCH] use the move modern syntax for std::enable_if and friends e.g. std::enable_if::type is replaced by std::enable_if_t remove some unneeded typename keywords --- filament/backend/include/backend/Handle.h | 2 +- .../include/private/backend/HandleAllocator.h | 14 ++++----- .../src/vulkan/memory/ResourcePointer.h | 4 +-- libs/utils/include/utils/Allocator.h | 6 ++-- libs/utils/include/utils/BinaryTreeArray.h | 2 +- libs/utils/include/utils/BitmaskEnum.h | 30 +++++++++---------- libs/utils/include/utils/JobSystem.h | 6 ++-- libs/utils/include/utils/QuadTree.h | 10 +++---- libs/utils/include/utils/StructureOfArrays.h | 16 +++++----- libs/utils/include/utils/algorithm.h | 6 ++-- libs/utils/include/utils/bitset.h | 4 +-- 11 files changed, 50 insertions(+), 50 deletions(-) diff --git a/filament/backend/include/backend/Handle.h b/filament/backend/include/backend/Handle.h index 5b03df2150..9a96e38939 100644 --- a/filament/backend/include/backend/Handle.h +++ b/filament/backend/include/backend/Handle.h @@ -130,7 +130,7 @@ struct Handle : public HandleBase { bool operator>=(const Handle& rhs) const noexcept { return getId() >= rhs.getId(); } // type-safe Handle cast - template::value> > + template> > Handle(Handle const& base) noexcept : HandleBase(base) { } // NOLINT(hicpp-explicit-conversions,google-explicit-constructor) private: diff --git a/filament/backend/include/private/backend/HandleAllocator.h b/filament/backend/include/private/backend/HandleAllocator.h index 97ce6feeb4..a1c727ecbe 100644 --- a/filament/backend/include/private/backend/HandleAllocator.h +++ b/filament/backend/include/private/backend/HandleAllocator.h @@ -113,7 +113,7 @@ public: * ConcreteTexture* p = reconstruct(h, w, h); */ template - typename std::enable_if_t, D>* + std::enable_if_t, D>* destroyAndConstruct(Handle const& handle, ARGS&& ... args) { assert_invariant(handle); D* addr = handle_cast(const_cast&>(handle)); @@ -132,7 +132,7 @@ public: * ConcreteTexture* p = construct(h, w, h); */ template - typename std::enable_if_t, D>* + std::enable_if_t, D>* construct(Handle const& handle, ARGS&& ... args) noexcept { assert_invariant(handle); D* addr = handle_cast(const_cast&>(handle)); @@ -149,7 +149,7 @@ public: * deallocate(h, p); */ template , D>> + typename = std::enable_if_t, D>> void deallocate(Handle& handle, D const* p) noexcept { // allow to destroy the nullptr, similarly to operator delete if (p) { @@ -177,9 +177,9 @@ public: * ConcreteTexture* p = handle_cast(h); */ template - inline typename std::enable_if_t< + inline std::enable_if_t< std::is_pointer_v && - std::is_base_of_v>, Dp> + std::is_base_of_v>, Dp> handle_cast(Handle& handle) { assert_invariant(handle); auto [p, tag] = handleToPointer(handle.getId()); @@ -235,9 +235,9 @@ public: } template - inline typename std::enable_if_t< + inline std::enable_if_t< std::is_pointer_v && - std::is_base_of_v>, Dp> + std::is_base_of_v>, Dp> handle_cast(Handle const& handle) { return handle_cast(const_cast&>(handle)); } diff --git a/filament/backend/src/vulkan/memory/ResourcePointer.h b/filament/backend/src/vulkan/memory/ResourcePointer.h index 25b9737bf7..f6f3578dde 100644 --- a/filament/backend/src/vulkan/memory/ResourcePointer.h +++ b/filament/backend/src/vulkan/memory/ResourcePointer.h @@ -81,7 +81,7 @@ public: inline resource_ptr() = default; // move constructor operator - inline resource_ptr(resource_ptr&& rhs) { + inline resource_ptr(resource_ptr&& rhs) noexcept { (*this) = std::move(rhs); } @@ -98,7 +98,7 @@ public: } // move operator - inline resource_ptr& operator=(resource_ptr && rhs) { + inline resource_ptr& operator=(resource_ptr && rhs) noexcept { std::swap(mRef, rhs.mRef); return *this; } diff --git a/libs/utils/include/utils/Allocator.h b/libs/utils/include/utils/Allocator.h index a3aaf3439e..300034af48 100644 --- a/libs/utils/include/utils/Allocator.h +++ b/libs/utils/include/utils/Allocator.h @@ -717,13 +717,13 @@ public: // trivially destructible, since free() won't call the destructor and this is allocating // an array. template ::value>::type> + typename = std::enable_if_t>> T* alloc(size_t count, size_t alignment, size_t extra) noexcept { return (T*)alloc(count * sizeof(T), alignment, extra); } template ::value>::type> + typename = std::enable_if_t>> T* alloc(size_t count, size_t alignment = alignof(T)) noexcept { return (T*)alloc(count * sizeof(T), alignment); } @@ -879,7 +879,7 @@ public: template T* make(ARGS&& ... args) noexcept { T* o = nullptr; - if (std::is_trivially_destructible::value) { + if (std::is_trivially_destructible_v) { o = mArena.template make(std::forward(args)...); } else { void* const p = (Finalizer*)mArena.alloc(sizeof(T), ALIGN, sizeof(Finalizer)); diff --git a/libs/utils/include/utils/BinaryTreeArray.h b/libs/utils/include/utils/BinaryTreeArray.h index b4e2b1913d..c2f70deaf4 100644 --- a/libs/utils/include/utils/BinaryTreeArray.h +++ b/libs/utils/include/utils/BinaryTreeArray.h @@ -31,7 +31,7 @@ class BinaryTreeArray { // Simple fixed capacity stack template::value>::type> + typename = std::enable_if_t>> class stack { TYPE mElements[CAPACITY]; size_t mSize = 0; diff --git a/libs/utils/include/utils/BitmaskEnum.h b/libs/utils/include/utils/BitmaskEnum.h index 17f94d215b..ae4122046c 100644 --- a/libs/utils/include/utils/BitmaskEnum.h +++ b/libs/utils/include/utils/BitmaskEnum.h @@ -41,32 +41,32 @@ size_t count(); // ------------------------------------------------------------------------------------------------ template::value && utils::EnableIntegerOperators::value, int> = 0> + std::is_enum_v && utils::EnableIntegerOperators::value, int> = 0> inline constexpr int operator+(Enum value) noexcept { return int(value); } template::value && utils::EnableIntegerOperators::value, int> = 0> + std::is_enum_v && utils::EnableIntegerOperators::value, int> = 0> inline constexpr bool operator==(Enum lhs, size_t rhs) noexcept { using underlying_t = std::underlying_type_t; return underlying_t(lhs) == rhs; } template::value && utils::EnableIntegerOperators::value, int> = 0> + std::is_enum_v && utils::EnableIntegerOperators::value, int> = 0> inline constexpr bool operator==(size_t lhs, Enum rhs) noexcept { return rhs == lhs; } template::value && utils::EnableIntegerOperators::value, int> = 0> + std::is_enum_v && utils::EnableIntegerOperators::value, int> = 0> inline constexpr bool operator!=(Enum lhs, size_t rhs) noexcept { return !(rhs == lhs); } template::value && utils::EnableIntegerOperators::value, int> = 0> + std::is_enum_v && utils::EnableIntegerOperators::value, int> = 0> inline constexpr bool operator!=(size_t lhs, Enum rhs) noexcept { return rhs != lhs; } @@ -74,66 +74,66 @@ inline constexpr bool operator!=(size_t lhs, Enum rhs) noexcept { // ------------------------------------------------------------------------------------------------ template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr bool operator!(Enum rhs) noexcept { using underlying = std::underlying_type_t; return underlying(rhs) == 0; } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator~(Enum rhs) noexcept { using underlying = std::underlying_type_t; return Enum(~underlying(rhs)); } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator|(Enum lhs, Enum rhs) noexcept { using underlying = std::underlying_type_t; return Enum(underlying(lhs) | underlying(rhs)); } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator&(Enum lhs, Enum rhs) noexcept { using underlying = std::underlying_type_t; return Enum(underlying(lhs) & underlying(rhs)); } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator^(Enum lhs, Enum rhs) noexcept { using underlying = std::underlying_type_t; return Enum(underlying(lhs) ^ underlying(rhs)); } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator|=(Enum& lhs, Enum rhs) noexcept { return lhs = lhs | rhs; } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator&=(Enum& lhs, Enum rhs) noexcept { return lhs = lhs & rhs; } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr Enum operator^=(Enum& lhs, Enum rhs) noexcept { return lhs = lhs ^ rhs; } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr bool none(Enum lhs) noexcept { return !lhs; } template::value && utils::EnableBitMaskOperators::value, int> = 0> + std::is_enum_v && utils::EnableBitMaskOperators::value, int> = 0> inline constexpr bool any(Enum lhs) noexcept { return !none(lhs); } diff --git a/libs/utils/include/utils/JobSystem.h b/libs/utils/include/utils/JobSystem.h index a2131b4738..1e424e4c5b 100644 --- a/libs/utils/include/utils/JobSystem.h +++ b/libs/utils/include/utils/JobSystem.h @@ -494,9 +494,9 @@ JobSystem::Job* createJob(JobSystem& js, JobSystem::Job* parent, } template::type>::value - >::type + typename = std::enable_if_t< + std::is_member_function_pointer_v> + > > JobSystem::Job* createJob(JobSystem& js, JobSystem::Job* parent, CALLABLE&& func, T&& o, ARGS&&... args) noexcept { diff --git a/libs/utils/include/utils/QuadTree.h b/libs/utils/include/utils/QuadTree.h index 036aadf6cc..3e7c6dba08 100644 --- a/libs/utils/include/utils/QuadTree.h +++ b/libs/utils/include/utils/QuadTree.h @@ -97,7 +97,7 @@ class QuadTreeArray : public std::array { // Simple fixed capacity stack template::value>::type> + typename = std::enable_if_t>> class stack { TYPE mElements[CAPACITY]; size_t mSize = 0; @@ -147,8 +147,8 @@ public: * @param process closure to process each visited node */ template>::type> + typename = std::enable_if_t< + std::is_invocable_r_v>> static void traverse(int8_t l, code_t code, size_t maxHeight, Process&& process) noexcept { assert_invariant(maxHeight < height()); const int8_t h = int8_t(maxHeight); @@ -173,8 +173,8 @@ public: } template>::type> + typename = std::enable_if_t< + std::is_invocable_r_v>> static void traverse(int8_t l, code_t code, Node&& process) noexcept { traverse(l, code, height() - 1, std::forward(process)); } diff --git a/libs/utils/include/utils/StructureOfArrays.h b/libs/utils/include/utils/StructureOfArrays.h index b7fccd6cbc..b5d56c79bf 100644 --- a/libs/utils/include/utils/StructureOfArrays.h +++ b/libs/utils/include/utils/StructureOfArrays.h @@ -130,7 +130,7 @@ public: friend class IteratorValueRef; friend iterator; friend const_iterator; - using Type = std::tuple::type...>; + using Type = std::tuple...>; Type elements; template @@ -535,22 +535,22 @@ public: private: template - inline typename std::enable_if::type + inline std::enable_if_t for_each(std::tuple&, FuncT) {} template - inline typename std::enable_if::type + inline std::enable_if_t for_each(std::tuple& t, FuncT f) { f(I, std::get(t)); for_each(t, f); } template - inline typename std::enable_if::type + inline std::enable_if_t for_each_index(std::tuple&, FuncT) {} template - inline typename std::enable_if::type + inline std::enable_if_t for_each_index(std::tuple& t, FuncT f) { f.template operator()(std::get(t)); for_each_index(t, f); @@ -597,7 +597,7 @@ private: void construct_each(size_t from, size_t to) noexcept { forEach([from, to](auto p) { - using T = typename std::decay::type; + using T = std::decay_t; // note: scalar types like int/float get initialized to zero if constexpr (!std::is_trivially_default_constructible_v) { for (size_t i = from; i < to; i++) { @@ -609,7 +609,7 @@ private: void destroy_each(size_t from, size_t to) noexcept { forEach([from, to](auto p) { - using T = typename std::decay::type; + using T = std::decay_t; if constexpr (!std::is_trivially_destructible_v) { for (size_t i = from; i < to; i++) { p[i].~T(); @@ -624,7 +624,7 @@ private: if (mSize) { auto size = mSize; // placate a compiler warning forEach([buffer, &index, &offsets, size](auto p) { - using T = typename std::decay::type; + using T = std::decay_t; T* UTILS_RESTRICT b = static_cast(buffer); // go through each element and move them from the old array to the new diff --git a/libs/utils/include/utils/algorithm.h b/libs/utils/include/utils/algorithm.h index 7a747b84ce..c4f400f4b7 100644 --- a/libs/utils/include/utils/algorithm.h +++ b/libs/utils/include/utils/algorithm.h @@ -39,7 +39,7 @@ constexpr inline T popcount(T v) noexcept { return (T) (v * (ONES / 255)) >> (sizeof(T) - 1) * CHAR_BIT; } -template::value>> +template>> constexpr inline T clz(T x) noexcept { static_assert(sizeof(T) * CHAR_BIT <= 128, "details::clz() only support up to 128 bits"); x |= (x >> 1u); @@ -62,7 +62,7 @@ constexpr inline T clz(T x) noexcept { return T(sizeof(T) * CHAR_BIT) - details::popcount(x); } -template::value>> +template>> constexpr inline T ctz(T x) noexcept { static_assert(sizeof(T) * CHAR_BIT <= 64, "details::ctz() only support up to 64 bits"); T c = sizeof(T) * CHAR_BIT; @@ -227,7 +227,7 @@ unsigned long long UTILS_ALWAYS_INLINE popcount(unsigned long long x) noexcept { } template::value && std::is_unsigned::value>> + typename = std::enable_if_t && std::is_unsigned_v>> constexpr inline UTILS_PUBLIC UTILS_PURE T log2i(T x) noexcept { return (sizeof(x) * 8 - 1u) - clz(x); diff --git a/libs/utils/include/utils/bitset.h b/libs/utils/include/utils/bitset.h index 8844fdb80a..4afba3955c 100644 --- a/libs/utils/include/utils/bitset.h +++ b/libs/utils/include/utils/bitset.h @@ -45,8 +45,8 @@ namespace utils { */ template::value && - std::is_unsigned::value>::type> + typename = std::enable_if_t && + std::is_unsigned_v>> class UTILS_PUBLIC bitset { T storage[N];