添加min、max

This commit is contained in:
邹晓航
2014-10-12 15:00:58 +08:00
parent 1c00451748
commit 905bb72a05
2 changed files with 19 additions and 1 deletions

View File

@@ -48,6 +48,24 @@ namespace TinySTL{
}
return first;
}
//*********** [min] ********************
template <class T>
const T& min(const T& a, const T& b){
return !(b < a) ? a : b;
}
template <class T, class Compare>
const T& min(const T& a, const T& b, Compare comp){
return !comp(b, a) ? a : b;
}
//*********** [max] ********************
template <class T>
const T& max(const T& a, const T& b){
return (a < b) ? b : a;
}
template <class T, class Compare>
const T& max(const T& a, const T& b, Compare comp){
return (copm(a, b)) ? b : a;
}
}
#endif

View File

@@ -183,7 +183,7 @@ namespace TinySTL{
iterator insert_aux_filln(iterator p, size_t n, value_type c);
size_type getNewCapacity(size_type len)const{
size_type oldCapacity = endOfStorage_ - start_;
auto res = std::max(oldCapacity, len);
auto res = TinySTL::max(oldCapacity, len);
size_type newCapacity = (oldCapacity != 0 ? (oldCapacity + res) : 1);
return newCapacity;
}