diff --git a/src/public/tier0/platform.h b/src/public/tier0/platform.h index 8b0997b..2be6b08 100644 --- a/src/public/tier0/platform.h +++ b/src/public/tier0/platform.h @@ -99,48 +99,11 @@ inline T* ValueInitializeConstruct( T* pMemory ) return ::new( pMemory ) T{}; } -template -inline void CopyConstruct( T* pMemory, T const& src ) +template +inline T* Construct( T* pMemory, ConstructorArgs&&... args ) { HINT( pMemory != 0 ); - ::new( pMemory ) T(src); -} - -#ifdef VALVE_RVALUE_REFS -template -inline void CopyConstruct( T* pMemory, T&& src ) -{ - HINT( pMemory != 0 ); - ::new(pMemory)T( std::forward(src) ); -} -#endif - -template -inline void ConstructOneArg( T* pMemory, P const& arg) -{ - HINT( pMemory != 0 ); - ::new( pMemory ) T(arg); -} - -template -inline void ConstructTwoArg( T* pMemory, P const& arg1, P2 const &arg2 ) -{ - HINT( pMemory != 0 ); - ::new( pMemory ) T(arg1, arg2); -} - -template -inline void ConstructTwoArgNoConst( T* pMemory, P& arg1, P2& arg2 ) -{ - HINT( pMemory != 0 ); - ::new( pMemory ) T( arg1, arg2 ); -} - -template -inline void ConstructSevenArg( T* pMemory, P const& arg1, P2 const &arg2, P3 const &arg3, P4 const &arg4, P5 const &arg5, P6 const &arg6, P7 const &arg7 ) -{ - HINT( pMemory != 0 ); - ::new( pMemory ) T(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + return ::new( pMemory ) T( std::forward(args)... ); } template diff --git a/src/public/tier1/utlhashmap.h b/src/public/tier1/utlhashmap.h index 292f4e8..de06add 100644 --- a/src/public/tier1/utlhashmap.h +++ b/src/public/tier1/utlhashmap.h @@ -476,7 +476,7 @@ inline int CUtlHashMap::InsertUnconstructed( KeyType_universal_ref &&ke // make an item int iNewNode = AllocNode(); m_memNodes[iNewNode].m_iNextNode = kInvalidIndex; - CopyConstruct( &m_memNodes[iNewNode].m_key, std::forward( key ) ); + Construct( &m_memNodes[iNewNode].m_key, std::forward( key ) ); // Note: m_elem remains intentionally unconstructed here // Note: key may have been moved depending on which constructor was called. @@ -534,11 +534,11 @@ inline int CUtlHashMap::FindOrInsert_Internal( pf_key &&key, pf_elem && if ( bReplace && iNodeExisting != kInvalidIndex ) { Destruct( &m_memNodes[ iNodeExisting ].m_elem ); - CopyConstruct( &m_memNodes[ iNodeExisting ].m_elem, std::forward( elem ) ); + Construct( &m_memNodes[ iNodeExisting ].m_elem, std::forward( elem ) ); } else if ( iNodeInserted != kInvalidIndex ) { - CopyConstruct( &m_memNodes[ iNodeInserted ].m_elem, std::forward( elem ) ); + Construct( &m_memNodes[ iNodeInserted ].m_elem, std::forward( elem ) ); return iNodeInserted; } return iNodeExisting; @@ -554,7 +554,7 @@ inline int CUtlHashMap::InsertWithDupes_Internal( pf_key &&key, pf_elem int iNodeInserted = InsertUnconstructed( std::forward( key ), NULL, true /*duplicates allowed!*/ ); // copies key if ( iNodeInserted != kInvalidIndex ) { - CopyConstruct( &m_memNodes[ iNodeInserted ].m_elem, std::forward( insert ) ); + Construct( &m_memNodes[ iNodeInserted ].m_elem, std::forward( insert ) ); } return iNodeInserted; } diff --git a/src/public/tier1/utlvector.h b/src/public/tier1/utlvector.h index 1393e84..020ca1c 100644 --- a/src/public/tier1/utlvector.h +++ b/src/public/tier1/utlvector.h @@ -596,7 +596,7 @@ inline int CUtlVector::SortedInsert( const T& src, bool (__cdecl *pfnLessF int pos = SortedFindLessOrEqual( src, pfnLessFunc, pLessContext ) + 1; GrowVector(); ShiftElementsRight(pos); - CopyConstruct( &Element(pos), src ); + Construct( &Element(pos), src ); return pos; } @@ -746,7 +746,7 @@ inline int CUtlVector::SortedInsert( const T& src, bool (__cdecl *pfnLessF int pos = SortedFindLessOrEqual( src, pfnLessFunc ) + 1; GrowVector(); ShiftElementsRight(pos); - CopyConstruct( &Element(pos), src ); + Construct( &Element(pos), src ); return pos; } @@ -1046,7 +1046,7 @@ inline int CUtlVector::InsertBefore( int elem, const T& src ) GrowVector(); ShiftElementsRight(elem); - CopyConstruct( &Element(elem), src ); + Construct( &Element(elem), src ); return elem; } @@ -1059,7 +1059,7 @@ inline int CUtlVector::AddToTail( T&& src ) Assert( (&src < Base()) || (&src >= (Base() + Count())) ); int elem = m_Size; GrowVector(); - CopyConstruct( &Element( elem ), std::forward( src ) ); + Construct( &Element( elem ), std::forward( src ) ); return elem; } #endif