From: <man...@us...> - 2013-04-11 21:32:58
|
Revision: 1850 http://sourceforge.net/p/modplug/code/1850 Author: manxorist Date: 2013-04-11 21:32:52 +0000 (Thu, 11 Apr 2013) Log Message: ----------- [Ref] Replace ArrayCopy with std::copy [Ref] Remove all references to tr1. It was just used for static assertions which are now disabled for older compilers (VS2008) which do not support c++11 type_traits. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/soundlib/ModSequence.cpp Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-04-11 21:08:35 UTC (rev 1849) +++ trunk/OpenMPT/common/misc_util.h 2013-04-11 21:32:52 UTC (rev 1850) @@ -17,33 +17,9 @@ #include "typedefs.h" #include <io.h> // for _taccess -#if(_MSC_VER < 1600) -#if defined(_HAS_TR1) -// vs2008sp1 has tr1 +#if defined(HAS_TYPE_TRAITS) #include <type_traits> -#else - // has_trivial_assign for VS2008 - namespace std - { - namespace tr1 - { - template <class T> struct has_trivial_assign {static const bool value = false;}; - #define SPECIALIZE_TRIVIAL_ASSIGN(type) template <> struct has_trivial_assign<type> {static const bool value = true;} - SPECIALIZE_TRIVIAL_ASSIGN(int8); - SPECIALIZE_TRIVIAL_ASSIGN(uint8); - SPECIALIZE_TRIVIAL_ASSIGN(int16); - SPECIALIZE_TRIVIAL_ASSIGN(uint16); - SPECIALIZE_TRIVIAL_ASSIGN(int32); - SPECIALIZE_TRIVIAL_ASSIGN(uint32); - SPECIALIZE_TRIVIAL_ASSIGN(int64); - SPECIALIZE_TRIVIAL_ASSIGN(uint64); - #undef SPECIALIZE_TRIVIAL_ASSIGN - }; - }; #endif -#else -#include <type_traits> -#endif //Convert object(typically number) to string template<class T> @@ -60,8 +36,8 @@ inline T ConvertStrTo(const char *str) //------------------------------------ { - #if _HAS_TR1 - static_assert(std::tr1::is_const<T>::value == false && std::tr1::is_volatile<T>::value == false, "Const and volatile types are not handled correctly."); + #ifdef HAS_TYPE_TRAITS + static_assert(std::is_const<T>::value == false && std::is_volatile<T>::value == false, "Const and volatile types are not handled correctly."); #endif if(std::numeric_limits<T>::is_integer) return static_cast<T>(atoi(str)); @@ -79,9 +55,9 @@ inline void MemsetZero(T &a) //-------------------------- { -#if _HAS_TR1 - static_assert(std::tr1::is_pointer<T>::value == false, "Won't memset pointers."); - static_assert(std::tr1::is_pod<T>::value == true, "Won't memset non-pods."); +#ifdef HAS_TYPE_TRAITS + static_assert(std::is_pointer<T>::value == false, "Won't memset pointers."); + static_assert(std::is_pod<T>::value == true, "Won't memset non-pods."); #endif memset(&a, 0, sizeof(T)); } @@ -92,9 +68,9 @@ inline T &MemCopy(T &destination, const T &source) //------------------------------------------------ { -#if _HAS_TR1 - static_assert(std::tr1::is_pointer<T>::value == false, "Won't copy pointers."); - static_assert(std::tr1::is_pod<T>::value == true, "Won't copy non-pods."); +#ifdef HAS_TYPE_TRAITS + static_assert(std::is_pointer<T>::value == false, "Won't copy pointers."); + static_assert(std::is_pod<T>::value == true, "Won't copy non-pods."); #endif return *static_cast<T *>(memcpy(&destination, &source, sizeof(T))); } @@ -145,37 +121,7 @@ std::string GetErrorMessage(DWORD nErrorCode); #endif // MODPLUG_TRACKER -namespace utilImpl -{ - template <bool bMemcpy> - struct ArrayCopyImpl {}; - template <> - struct ArrayCopyImpl<true> - { - template <class T> - static void Do(T* pDst, const T* pSrc, const size_t n) {memcpy(pDst, pSrc, sizeof(T) * n);} - }; - - template <> - struct ArrayCopyImpl<false> - { - template <class T> - static void Do(T* pDst, const T* pSrc, const size_t n) {std::copy(pSrc, pSrc + n, pDst);} - }; -} // namespace utilImpl - - -// Copies n elements from array pSrc to array pDst. -// If the source and destination arrays overlap, behaviour is undefined. -template <class T> -void ArrayCopy(T* pDst, const T* pSrc, const size_t n) -//---------------------------------------------------- -{ - utilImpl::ArrayCopyImpl<std::tr1::has_trivial_assign<T>::value>::Do(pDst, pSrc, n); -} - - // Sanitize a filename (remove special chars) template <size_t size> void SanitizeFilename(char (&buffer)[size]) Modified: trunk/OpenMPT/soundlib/ModSequence.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-11 21:08:35 UTC (rev 1849) +++ trunk/OpenMPT/soundlib/ModSequence.cpp 2013-04-11 21:32:52 UTC (rev 1850) @@ -244,7 +244,7 @@ const PATTERNINDEX* const pOld = m_pArray; m_nCapacity = nNewSize + 100; m_pArray = new PATTERNINDEX[m_nCapacity]; - ArrayCopy(m_pArray, pOld, m_nSize); + std::copy(pOld, pOld+m_nSize, m_pArray); std::fill(m_pArray + m_nSize, m_pArray + nNewSize, nFill); m_nSize = nNewSize; if (m_bDeletableArray) @@ -269,7 +269,7 @@ m_nIgnoreIndex = seq.m_nIgnoreIndex; m_nInvalidIndex = seq.m_nInvalidIndex; resize(seq.GetLength()); - ArrayCopy(begin(), seq.begin(), m_nSize); + std::copy(seq.begin(), seq.end(), begin()); m_sName = seq.m_sName; return *this; } @@ -354,7 +354,7 @@ m_nSize = rSeq.GetLength(); m_nCapacity = s_nCacheSize; m_sName = rSeq.m_sName; - ArrayCopy(m_pArray, rSeq.m_pArray, m_nSize); + std::copy(rSeq.m_pArray, rSeq.m_pArray+m_nSize, m_pArray); if (m_bDeletableArray) delete[] pOld; m_bDeletableArray = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |