optimize piSwap and c++11 improvments
This commit is contained in:
@@ -538,5 +538,7 @@ inline PICout operator <<(PICout s, const PIDeque<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T> inline void piSwap(PIDeque<T> & f, PIDeque<T> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIDEQUE_H
|
||||
|
||||
@@ -57,7 +57,7 @@ void piQuickSort(T * a, ssize_t N) {
|
||||
if (i <= j) {
|
||||
if (i != j) {
|
||||
//piCout << "swap" << i << j << a[i] << a[j];
|
||||
piSwapBinary<T>(a[i], a[j]);
|
||||
piSwap<T>(a[i], a[j]);
|
||||
}
|
||||
i++; j--;
|
||||
}
|
||||
@@ -216,8 +216,8 @@ public:
|
||||
PIMap<Key, T> & clear() {pim_content.clear(); pim_index.clear(); return *this;}
|
||||
|
||||
void swap(PIMap<Key, T> & other) {
|
||||
piSwapBinary<PIVector<T> >(pim_content, other.pim_content);
|
||||
piSwapBinary<PIDeque<MapIndex> >(pim_index, other.pim_index);
|
||||
pim_content.swap(other.pim_content);
|
||||
pim_index.swap(other.pim_index);
|
||||
}
|
||||
|
||||
PIMap<Key, T> & insert(const Key & key, const T & value) {
|
||||
@@ -292,7 +292,7 @@ protected:
|
||||
pim_index[i].index = ci;
|
||||
break;
|
||||
}
|
||||
piSwapBinary<T>(pim_content[ci], pim_content.back());
|
||||
piSwap<T>(pim_content[ci], pim_content.back());
|
||||
pim_content.resize(pim_index.size());
|
||||
}
|
||||
const value_type _pair(ssize_t index) const {
|
||||
@@ -342,5 +342,7 @@ inline PICout operator <<(PICout s, const PIMap<Key, Type> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename Key, typename Type> inline void piSwap(PIMap<Key, Type> & f, PIMap<Key, Type> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIMAP_H
|
||||
|
||||
@@ -487,5 +487,7 @@ inline PICout operator <<(PICout s, const PIVector<T> & v) {
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename T> inline void piSwap(PIVector<T> & f, PIVector<T> & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIVECTOR_H
|
||||
|
||||
@@ -255,9 +255,15 @@ typedef unsigned long long ullong;
|
||||
typedef long long llong;
|
||||
typedef long double ldouble;
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
#define piMove(v) std::move(v)
|
||||
#else
|
||||
#define piMove(v) v
|
||||
#endif
|
||||
|
||||
/*! \brief Templated function for swap two values
|
||||
* \details Example:\n \snippet piincludes.cpp swap */
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t(piMove(f)); f = piMove(s); s = piMove(t);}
|
||||
|
||||
/*! \brief Templated function for swap two values without "="
|
||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||
@@ -294,6 +300,10 @@ template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
||||
}
|
||||
}
|
||||
|
||||
template<> inline void piSwap(double & f, double & s) {piSwapBinary<double>(f, s);}
|
||||
template<> inline void piSwap(ldouble & f, ldouble & s) {piSwapBinary<ldouble>(f, s);}
|
||||
|
||||
|
||||
/*! \brief Function for compare two values without "=" by raw content
|
||||
* \details Example:\n \snippet piincludes.cpp compareBinary */
|
||||
inline bool piCompareBinary(const void * f, const void * s, size_t size) {
|
||||
|
||||
@@ -316,6 +316,7 @@ __PIBYTEARRAY_SIMPLE_TYPE__(PIChar)
|
||||
|
||||
|
||||
template<> inline uint piHash(const PIByteArray & ba) {return ba.hash();}
|
||||
template<> inline void piSwap(PIByteArray & f, PIByteArray & s) {f.swap(s);}
|
||||
|
||||
|
||||
#endif // PIBYTEARRAY_H
|
||||
|
||||
@@ -504,13 +504,19 @@ public:
|
||||
explicit PIObject(const PIString & name = PIString());
|
||||
|
||||
virtual ~PIObject();
|
||||
|
||||
|
||||
#ifdef PIP_CXX11_SUPPORT
|
||||
explicit PIObject(const PIObject & ) = delete;
|
||||
void operator =(const PIObject & ) = delete;
|
||||
#else
|
||||
private:
|
||||
explicit PIObject(const PIObject & );
|
||||
void operator =(const PIObject & );
|
||||
#endif
|
||||
|
||||
private:
|
||||
uint _signature_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//! Returns object name
|
||||
|
||||
@@ -770,5 +770,6 @@ PIString versionNormalize(const PIString & v);
|
||||
|
||||
|
||||
template<> inline uint piHash(const PIString & s) {return s.hash();}
|
||||
template<> inline void piSwap(PIString & f, PIString & s) {f.swap(s);}
|
||||
|
||||
#endif // PISTRING_H
|
||||
|
||||
Reference in New Issue
Block a user