1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 20:16:10 +08:00

Correct compile errors in CUtlLeanVector & CUtlLinkedList

This commit is contained in:
GAMMACASE
2025-08-02 15:20:35 +03:00
parent 7a9df1461f
commit 3709354673
2 changed files with 18 additions and 27 deletions

View File

@ -316,7 +316,7 @@ inline CUtlLeanVectorFixedGrowableBase<T, N, I, A>::CUtlLeanVectorFixedGrowableB
template< class T, size_t N, class I, class A > template< class T, size_t N, class I, class A >
inline CUtlLeanVectorFixedGrowableBase<T, N, I, A>::CUtlLeanVectorFixedGrowableBase( T *pMemory, I allocationCount, I numElements ) : inline CUtlLeanVectorFixedGrowableBase<T, N, I, A>::CUtlLeanVectorFixedGrowableBase( T *pMemory, I allocationCount, I numElements ) :
m_nCount( numElements ), m_nAllocated( allocationCount | EXTERNAL_BUFFER_MARKER ), m_pElements( pMemory ) m_nAllocCount( numElements ), m_nAllocAllocated( allocationCount | EXTERNAL_BUFFER_MARKER ), m_pElements( pMemory )
{ {
} }
@ -474,7 +474,10 @@ public:
// Is element index valid? // Is element index valid?
bool IsValidIndex( int i ) const; bool IsValidIndex( int i ) const;
static int InvalidIndex();
// Specify the invalid ('null') index that we'll only return on failure
static const I INVALID_INDEX = (I)-1; // For use with COMPILE_TIME_ASSERT
static I InvalidIndex() { return INVALID_INDEX; }
// Adds an element, uses default constructor // Adds an element, uses default constructor
T* AddToTailGetPtr(); T* AddToTailGetPtr();
@ -611,15 +614,6 @@ inline bool CUtlLeanVectorImpl<B, T, I>::IsValidIndex( int i ) const
return (i >= 0) && (i < this->m_nCount); return (i >= 0) && (i < this->m_nCount);
} }
//-----------------------------------------------------------------------------
// Returns in invalid index
//-----------------------------------------------------------------------------
template< class B, class T, class I >
inline int CUtlLeanVectorImpl<B, T, I>::InvalidIndex()
{
return -1;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Adds an element, uses default constructor // Adds an element, uses default constructor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -20,6 +20,8 @@
#include "utlblockmemory.h" #include "utlblockmemory.h"
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include <type_traits>
// define to enable asserts griping about things you shouldn't be doing with multilists // define to enable asserts griping about things you shouldn't be doing with multilists
// #define MULTILIST_PEDANTIC_ASSERTS 1 // #define MULTILIST_PEDANTIC_ASSERTS 1
@ -41,6 +43,8 @@
template <class T, class I> template <class T, class I>
struct UtlLinkedListElem_t struct UtlLinkedListElem_t
{ {
UtlLinkedListElem_t() {}
T m_Element; T m_Element;
I m_Previous; I m_Previous;
I m_Next; I m_Next;
@ -80,8 +84,6 @@ public:
// Make sure we have a particular amount of memory // Make sure we have a particular amount of memory
void EnsureCapacity( int num ); void EnsureCapacity( int num );
void SetGrowSize( int growSize );
// Memory deallocation // Memory deallocation
void Purge(); void Purge();
@ -159,7 +161,7 @@ protected:
ListElem_t const& InternalElement( I i ) const { return m_Memory[i]; } ListElem_t const& InternalElement( I i ) const { return m_Memory[i]; }
// copy constructors not allowed // copy constructors not allowed
CUtlLinkedList( CUtlLinkedList<T, S, ML, I, M> const& list ) { Assert(0); } CUtlLinkedList( CUtlLinkedList<T, S, ML, I, M> const& list ) : m_LastAlloc( 0 ) { Assert(0); }
M m_Memory; M m_Memory;
I m_Head; I m_Head;
@ -370,14 +372,6 @@ void CUtlLinkedList<T,S,ML,I,M>::EnsureCapacity( int num )
m_Memory.EnsureCapacity(num); m_Memory.EnsureCapacity(num);
} }
template< class T, class S, bool ML, class I, class M >
void CUtlLinkedList<T,S,ML,I,M>::SetGrowSize( int growSize )
{
RemoveAll();
m_Memory.Init( growSize );
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Deallocate memory // Deallocate memory
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -399,11 +393,14 @@ void CUtlLinkedList<T,S,ML,I,M>::Purge()
template<class T, class S, bool ML, class I, class M> template<class T, class S, bool ML, class I, class M>
void CUtlLinkedList<T,S,ML,I,M>::PurgeAndDeleteElements() void CUtlLinkedList<T,S,ML,I,M>::PurgeAndDeleteElements()
{ {
I iNext; if constexpr (std::is_pointer_v<T>)
for( I i=Head(); i != InvalidIndex(); i=iNext )
{ {
iNext = Next(i); I iNext;
delete Element(i); for(I i=Head(); i != InvalidIndex(); i=iNext)
{
iNext = Next( i );
delete Element( i );
}
} }
Purge(); Purge();
@ -432,7 +429,7 @@ I CUtlLinkedList<T,S,ML,I,M>::AllocInternal( bool multilist )
if ( !m_Memory.IsValidIterator( it ) ) if ( !m_Memory.IsValidIterator( it ) )
{ {
MEM_ALLOC_CREDIT_CLASS(); MEM_ALLOC_CREDIT_CLASS();
m_Memory.Grow(); m_Memory.AddToTailGetPtr();
it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First(); it = m_Memory.IsValidIterator( m_LastAlloc ) ? m_Memory.Next( m_LastAlloc ) : m_Memory.First();