From ea48257100c389315064693b55635e54cbc0db19 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 2 Mar 2024 12:48:17 +0100 Subject: [PATCH] Fix SonarCloud issues Replace the use of "::value" with "std::is_abstract_v" and similar issues --- lib/int3.h | 2 +- lib/serializer/BinaryDeserializer.h | 30 ++++++++-------- lib/serializer/BinarySerializer.h | 20 +++++------ lib/serializer/CSerializer.h | 2 +- mapeditor/StdInc.h | 4 +-- scripting/lua/LuaStack.h | 34 +++++++++---------- scripting/lua/LuaWrapper.h | 6 ++-- .../api/events/SubscriptionRegistryProxy.h | 2 +- 8 files changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/int3.h b/lib/int3.h index 7fe731d08..1307255d0 100644 --- a/lib/int3.h +++ b/lib/int3.h @@ -194,7 +194,7 @@ public: template int3 findClosestTile (Container & container, int3 dest) { - static_assert(std::is_same::value, + static_assert(std::is_same_v, "findClosestTile requires container."); int3 result(-1, -1, -1); diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index 222ed2364..5f702e190 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -96,7 +96,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase { static T *invoke(IGameCallback *cb) { - static_assert(!std::is_abstract::value, "Cannot call new upon abstract classes!"); + static_assert(!std::is_abstract_v, "Cannot call new upon abstract classes!"); return new T(cb); } }; @@ -171,21 +171,21 @@ public: return * this; } - template < class T, typename std::enable_if < std::is_fundamental::value && !std::is_same::value, int >::type = 0 > + template < class T, typename std::enable_if_t < std::is_fundamental_v && !std::is_same_v, int > = 0 > void load(T &data) { this->read(static_cast(&data), sizeof(data), reverseEndianess); } - template < typename T, typename std::enable_if < is_serializeable::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < is_serializeable::value, int > = 0 > void load(T &data) { ////that const cast is evil because it allows to implicitly overwrite const objects when deserializing - typedef typename std::remove_const::type nonConstT; + typedef typename std::remove_const_t nonConstT; auto & hlp = const_cast(data); hlp.serialize(*this); } - template < typename T, typename std::enable_if < std::is_array::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_array_v, int > = 0 > void load(T &data) { ui32 size = std::size(data); @@ -193,7 +193,7 @@ public: load(data[i]); } - template < typename T, typename std::enable_if < std::is_enum::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_enum_v, int > = 0 > void load(T &data) { si32 read; @@ -201,7 +201,7 @@ public: data = static_cast(read); } - template < typename T, typename std::enable_if < std::is_same::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_same_v, int > = 0 > void load(T &data) { ui8 read; @@ -209,7 +209,7 @@ public: data = static_cast(read); } - template ::value, int >::type = 0> + template , int > = 0> void load(std::vector &data) { ui32 length = readAndCheckLength(); @@ -218,7 +218,7 @@ public: load( data[i]); } - template < typename T, typename std::enable_if < std::is_pointer::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_pointer_v, int > = 0 > void load(T &data) { bool isNull; @@ -232,7 +232,7 @@ public: loadPointerImpl(data); } - template < typename T, typename std::enable_if < std::is_base_of_v>, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_base_of_v>, int > = 0 > void loadPointerImpl(T &data) { using DataType = std::remove_pointer_t; @@ -245,12 +245,12 @@ public: data = const_cast(constData); } - template < typename T, typename std::enable_if < !std::is_base_of_v>, int >::type = 0 > + template < typename T, typename std::enable_if_t < !std::is_base_of_v>, int > = 0 > void loadPointerImpl(T &data) { if(reader->smartVectorMembersSerialization) { - typedef typename std::remove_const::type>::type TObjectType; //eg: const CGHeroInstance * => CGHeroInstance + typedef typename std::remove_const_t> TObjectType; //eg: const CGHeroInstance * => CGHeroInstance typedef typename VectorizedTypeFor::type VType; //eg: CGHeroInstance -> CGobjectInstance typedef typename VectorizedIDType::type IDType; if(const auto *info = reader->getVectorizedTypeInfo()) @@ -292,8 +292,8 @@ public: if(!tid) { - typedef typename std::remove_pointer::type npT; - typedef typename std::remove_const::type ncpT; + typedef typename std::remove_pointer_t npT; + typedef typename std::remove_const_t ncpT; data = ClassObjectCreator::invoke(cb); ptrAllocated(data, pid); load(*data); @@ -326,7 +326,7 @@ public: template void load(std::shared_ptr &data) { - typedef typename std::remove_const::type NonConstT; + typedef typename std::remove_const_t NonConstT; NonConstT *internalPtr; load(internalPtr); diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index 07d152ad3..28da150eb 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -134,28 +134,28 @@ public: return * this; } - template < typename T, typename std::enable_if < std::is_same::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_same_v, int > = 0 > void save(const T &data) { ui8 writ = static_cast(data); save(writ); } - template < class T, typename std::enable_if < std::is_fundamental::value && !std::is_same::value, int >::type = 0 > + template < class T, typename std::enable_if_t < std::is_fundamental_v && !std::is_same_v, int > = 0 > void save(const T &data) { // save primitive - simply dump binary data to output this->write(static_cast(&data), sizeof(data)); } - template < typename T, typename std::enable_if < std::is_enum::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_enum_v, int > = 0 > void save(const T &data) { si32 writ = static_cast(data); *this & writ; } - template < typename T, typename std::enable_if < std::is_array::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_array_v, int > = 0 > void save(const T &data) { ui32 size = std::size(data); @@ -163,7 +163,7 @@ public: *this & data[i]; } - template < typename T, typename std::enable_if < std::is_pointer::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_pointer_v, int > = 0 > void save(const T &data) { //write if pointer is not nullptr @@ -177,17 +177,17 @@ public: savePointerImpl(data); } - template < typename T, typename std::enable_if < std::is_base_of_v>, int >::type = 0 > + template < typename T, typename std::enable_if_t < std::is_base_of_v>, int > = 0 > void savePointerImpl(const T &data) { auto index = data->getId(); save(index); } - template < typename T, typename std::enable_if < !std::is_base_of_v>, int >::type = 0 > + template < typename T, typename std::enable_if_t < !std::is_base_of_v>, int > = 0 > void savePointerImpl(const T &data) { - typedef typename std::remove_const::type>::type TObjectType; + typedef typename std::remove_const_t> TObjectType; if(writer->smartVectorMembersSerialization) { @@ -239,7 +239,7 @@ public: applier.getApplier(tid)->savePtr(*this, static_cast(data)); //call serializer specific for our real type } - template < typename T, typename std::enable_if < is_serializeable::value, int >::type = 0 > + template < typename T, typename std::enable_if_t < is_serializeable::value, int > = 0 > void save(const T &data) { const_cast(data).serialize(*this); @@ -268,7 +268,7 @@ public: T *internalPtr = data.get(); save(internalPtr); } - template ::value, int >::type = 0> + template , int > = 0> void save(const std::vector &data) { ui32 length = (ui32)data.size(); diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index d0f90c758..cc9392031 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -138,7 +138,7 @@ struct is_serializeable template static Yes test(U * data, S* arg1 = nullptr, typename std::enable_if_tserialize(*arg1))>> * = nullptr); static No test(...); - static const bool value = sizeof(Yes) == sizeof(is_serializeable::test((typename std::remove_reference::type>::type*)nullptr)); + static const bool value = sizeof(Yes) == sizeof(is_serializeable::test((typename std::remove_reference_t>*)nullptr)); }; template //metafunction returning CGObjectInstance if T is its derivate or T elsewise diff --git a/mapeditor/StdInc.h b/mapeditor/StdInc.h index 4dc45a2ef..f877c4191 100644 --- a/mapeditor/StdInc.h +++ b/mapeditor/StdInc.h @@ -15,8 +15,8 @@ VCMI_LIB_USING_NAMESPACE -using NumericPointer = typename std::conditional::type; +using NumericPointer = typename std::conditional_t; template NumericPointer data_cast(Type * _pointer) diff --git a/scripting/lua/LuaStack.h b/scripting/lua/LuaStack.h index 7963c1d77..3f615c0fe 100644 --- a/scripting/lua/LuaStack.h +++ b/scripting/lua/LuaStack.h @@ -26,13 +26,13 @@ namespace detail template struct IsRegularClass { - static constexpr auto value = std::is_class::value && !std::is_base_of::value; + static constexpr auto value = std::is_class_v && !std::is_base_of_v; }; template struct IsIdClass { - static constexpr auto value = std::is_class::value && std::is_base_of::value; + static constexpr auto value = std::is_class_v && std::is_base_of_v; }; } @@ -61,13 +61,13 @@ public: pushNil(); } - template::value && !std::is_same::value, int>::type = 0> + template && !std::is_same_v, int> = 0> void push(const T value) { pushInteger(static_cast(value)); } - template::value, int>::type = 0> + template, int> = 0> void push(const T value) { pushInteger(static_cast(value)); @@ -75,13 +75,13 @@ public: void push(const int3 & value); - template::value, int>::type = 0> + template::value, int> = 0> void push(const T & value) { pushInteger(static_cast(value.getNum())); } - template::value, int>::type = 0> + template::value, int> = 0> void push(T * value) { using UData = T *; @@ -107,7 +107,7 @@ public: lua_setmetatable(L, -2); } - template::value, int>::type = 0> + template::value, int> = 0> void push(std::shared_ptr value) { using UData = std::shared_ptr; @@ -133,7 +133,7 @@ public: lua_setmetatable(L, -2); } - template::value, int>::type = 0> + template::value, int> = 0> void push(std::unique_ptr && value) { using UData = std::unique_ptr; @@ -163,7 +163,7 @@ public: bool tryGet(int position, bool & value); - template::value && !std::is_same::value, int>::type = 0> + template && !std::is_same_v, int> = 0> bool tryGet(int position, T & value) { lua_Integer temp; @@ -178,7 +178,7 @@ public: } } - template::value, int>::type = 0> + template::value, int> = 0> bool tryGet(int position, T & value) { lua_Integer temp; @@ -193,7 +193,7 @@ public: } } - template::value, int>::type = 0> + template, int> = 0> bool tryGet(int position, T & value) { lua_Integer temp; @@ -213,10 +213,10 @@ public: bool tryGet(int position, double & value); bool tryGet(int position, std::string & value); - template::value && std::is_const::value, int>::type = 0> + template::value && std::is_const_v, int> = 0> STRONG_INLINE bool tryGet(int position, T * & value) { - using NCValue = typename std::remove_const::type; + using NCValue = typename std::remove_const_t; using UData = NCValue *; using CUData = T *; @@ -224,16 +224,16 @@ public: return tryGetCUData(position, value); } - template::value && !std::is_const::value, int>::type = 0> + template::value && !std::is_const_v, int> = 0> STRONG_INLINE bool tryGet(int position, T * & value) { return tryGetUData(position, value); } - template::value && std::is_const::value, int>::type = 0> + template::value && std::is_const_v, int> = 0> STRONG_INLINE bool tryGet(int position, std::shared_ptr & value) { - using NCValue = typename std::remove_const::type; + using NCValue = typename std::remove_const_t; using UData = std::shared_ptr; using CUData = std::shared_ptr; @@ -241,7 +241,7 @@ public: return tryGetCUData, UData, CUData>(position, value); } - template::value && !std::is_const::value, int>::type = 0> + template::value && !std::is_const_v, int> = 0> STRONG_INLINE bool tryGet(int position, std::shared_ptr & value) { return tryGetUData>(position, value); diff --git a/scripting/lua/LuaWrapper.h b/scripting/lua/LuaWrapper.h index 83071b3b3..a6911bb6d 100644 --- a/scripting/lua/LuaWrapper.h +++ b/scripting/lua/LuaWrapper.h @@ -124,7 +124,7 @@ template class OpaqueWrapper : public RegistarBase { public: - using ObjectType = typename std::remove_cv::type; + using ObjectType = typename std::remove_cv_t; using UDataType = ObjectType *; using CUDataType = const ObjectType *; @@ -163,7 +163,7 @@ template class SharedWrapper : public RegistarBase { public: - using ObjectType = typename std::remove_cv::type; + using ObjectType = typename std::remove_cv_t; using UDataType = std::shared_ptr; using CustomRegType = detail::CustomRegType; @@ -208,7 +208,7 @@ template class UniqueOpaqueWrapper : public api::Registar { public: - using ObjectType = typename std::remove_cv::type; + using ObjectType = typename std::remove_cv_t; using UDataType = std::unique_ptr; using CustomRegType = detail::CustomRegType; diff --git a/scripting/lua/api/events/SubscriptionRegistryProxy.h b/scripting/lua/api/events/SubscriptionRegistryProxy.h index b84002051..b4f34f93d 100644 --- a/scripting/lua/api/events/SubscriptionRegistryProxy.h +++ b/scripting/lua/api/events/SubscriptionRegistryProxy.h @@ -42,7 +42,7 @@ public: using EventType = typename EventProxy::ObjectType; using RegistryType = ::events::SubscriptionRegistry; - static_assert(std::is_base_of<::events::Event, EventType>::value, "Invalid template parameter"); + static_assert(std::is_base_of_v<::events::Event, EventType>, "Invalid template parameter"); static int subscribeBefore(lua_State * L) {