diff --git a/public/tier1/convar.h b/public/tier1/convar.h index 38bdb337..fba48ed2 100644 --- a/public/tier1/convar.h +++ b/public/tier1/convar.h @@ -17,6 +17,7 @@ #endif #include "tier0/dbg.h" +#include "utlcommon.h" #include "tier1/utlvector.h" #include "tier1/utlstring.h" #include "mathlib/vector4d.h" @@ -27,7 +28,6 @@ #include #include -#include //----------------------------------------------------------------------------- // Forward declarations @@ -742,7 +742,7 @@ struct CVarTypeTraits { m_TypeName = name; m_ByteSize = sizeof( T ); - m_IsPrimitive = std::is_pod_v; + m_IsPrimitive = CTypePOD; Construct = &CvarTypeTrait_ConstructFn; Copy = &CvarTypeTrait_CopyFn; @@ -1085,7 +1085,7 @@ public: // (which will happen in callbacks), so the solution is to do a static_cast to // CConVarRef yourself on the cvar you receive in a callback and call .Set() on it template - void SetAs( T value, CSplitScreenSlot slot = -1 ); + void SetAs( const T &value, CSplitScreenSlot slot = -1 ); // Attempts to set value as a bool, does type conversion if possible, // if no such action is available for CvarType/bool combo, no action would be done @@ -1135,7 +1135,7 @@ protected: T ConvertFromPrimitiveTo( CSplitScreenSlot slot ) const; // Does type conversion from type T to CvarType, only valid for primitive types template - void ConvertToPrimitiveFrom( CSplitScreenSlot slot, T value ) const; + void ConvertToPrimitiveFrom( CSplitScreenSlot slot, const T &value ) const; // Initialises this cvar, if ref is invalid, ConVarData would be initialised to invalid convar data of a set type void Init( ConVarRef ref, EConVarType type = EConVarType_Invalid ); @@ -1298,7 +1298,7 @@ inline CUtlString ConVarRefAbstract::GetString( CSplitScreenSlot slot ) const template inline T ConVarRefAbstract::ConvertFromPrimitiveTo( CSplitScreenSlot slot ) const { - if constexpr(std::is_pod_v) + if constexpr(CTypePOD) { CVValue_t *value = m_ConVarData->ValueOrDefault( slot ); @@ -1337,7 +1337,7 @@ inline void CConVarRef::Set( const T &value, CSplitScreenSlot slot ) } template -inline void ConVarRefAbstract::SetAs( T value, CSplitScreenSlot slot ) +inline void ConVarRefAbstract::SetAs( const T &value, CSplitScreenSlot slot ) { if(GetType() == TranslateConVarType()) { @@ -1357,15 +1357,15 @@ inline void ConVarRefAbstract::SetAs( T value, CSplitScreenSlot slot ) } } -template<> inline void ConVarRefAbstract::SetAs( CUtlString value, CSplitScreenSlot slot ) +template<> inline void ConVarRefAbstract::SetAs( const CUtlString &value, CSplitScreenSlot slot ) { SetString( value, slot ); } template -inline void ConVarRefAbstract::ConvertToPrimitiveFrom( CSplitScreenSlot slot, T value ) const +inline void ConVarRefAbstract::ConvertToPrimitiveFrom( CSplitScreenSlot slot, const T &value ) const { - if constexpr(std::is_pod_v) + if constexpr(CTypePOD) { switch(GetType()) { diff --git a/public/tier1/utlcommon.h b/public/tier1/utlcommon.h index 977c42d9..e75f7e16 100644 --- a/public/tier1/utlcommon.h +++ b/public/tier1/utlcommon.h @@ -11,6 +11,7 @@ #pragma once #include "utlstring.h" +#include "type_traits" //----------------------------------------------------------------------------- // Henry Goffin (henryg) was here. Questions? Bugs? Go slap him around a bit. @@ -47,6 +48,9 @@ struct CTypeEquals : CTypeEquals< const volatile A, const vol template struct CTypeEquals : CTypeEquals< A&, B& > {}; +template +constexpr bool CTypePOD = std::is_standard_layout_v && std::is_trivial_v; + // CUtlKeyValuePair is intended for use with key-lookup containers. // Because it is specialized for "empty_t" values, one container can // function as either a set of keys OR a key-value dictionary while