From 905bb72a0514587e5c15df9e39e0a3159829fd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sun, 12 Oct 2014 15:00:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0min=E3=80=81max?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Algorithm.h | 18 ++++++++++++++++++ TinySTL/String.h | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/TinySTL/Algorithm.h b/TinySTL/Algorithm.h index 661e5bd..412be08 100644 --- a/TinySTL/Algorithm.h +++ b/TinySTL/Algorithm.h @@ -48,6 +48,24 @@ namespace TinySTL{ } return first; } + //*********** [min] ******************** + template + const T& min(const T& a, const T& b){ + return !(b < a) ? a : b; + } + template + const T& min(const T& a, const T& b, Compare comp){ + return !comp(b, a) ? a : b; + } + //*********** [max] ******************** + template + const T& max(const T& a, const T& b){ + return (a < b) ? b : a; + } + template + const T& max(const T& a, const T& b, Compare comp){ + return (copm(a, b)) ? b : a; + } } #endif \ No newline at end of file diff --git a/TinySTL/String.h b/TinySTL/String.h index ff5ee9f..fadb0de 100644 --- a/TinySTL/String.h +++ b/TinySTL/String.h @@ -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; }