Actually qSwap doesn't use memcpy directly (4.3 beta):
template <typename T>
inline void qSwap(T &value1, T &value2)
{
if (!QTypeInfo<T>::isComplex || QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
T t = value1;
value1 = value2;
value2 = t;
} else {
const void * const t = reinterpret_cast<const void * const &>(value1);
const_cast<const void *&>(reinterpret_cast<const void * const &>(value1)) =
reinterpret_cast<const void * const &>(value2);
const_cast<const void *&>(reinterpret_cast<const void * const &>(value2)) = t;
}
}
template <typename T>
inline void qSwap(T &value1, T &value2)
{
if (!QTypeInfo<T>::isComplex || QTypeInfo<T>::isLarge || QTypeInfo<T>::isStatic) {
T t = value1;
value1 = value2;
value2 = t;
} else {
const void * const t = reinterpret_cast<const void * const &>(value1);
const_cast<const void *&>(reinterpret_cast<const void * const &>(value1)) =
reinterpret_cast<const void * const &>(value2);
const_cast<const void *&>(reinterpret_cast<const void * const &>(value2)) = t;
}
}
To copy to clipboard, switch view to plain text mode
I admit I don't understand those spells with casting, but they look smart 
It's not that qSwap is thread safe, it's that you can use such classes with it. You have to care about locking your class on your own. It's a general assumption about using operator=(), not about swapping items.
Anyway we're highly offtopic here
It doesn't really matter if you use qSwap or swap for sorting QVector.
Bookmarks