From 569cd6e38817aa1d4560900f60f2f07c02d13e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 29 Nov 2014 16:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=85=A8=E9=83=A8=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/List.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/TinySTL/List.h b/TinySTL/List.h index 9b5c688..caac360 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -94,6 +94,13 @@ namespace TinySTL{ head.p = newNode();//add a dummy node tail.p = head.p; } + explicit list(size_type n, const value_type& val = value_type()){ + ctorAux(n, val, std::is_integral()); + } + template + list(InputIterator first, InputIterator last){ + ctorAux(first, last, std::is_integral()); + } list(const list& l){ head.p = newNode();//add a dummy node tail.p = head.p; @@ -161,6 +168,19 @@ namespace TinySTL{ //void sort(Compare comp); void reverse(); private: + void ctorAux(size_type n, const value_type& val, std::true_type){ + head.p = newNode();//add a dummy node + tail.p = head.p; + while (n--) + push_back(val); + } + template + void ctorAux(InputIterator first, InputIterator last, std::false_type){ + head.p = newNode();//add a dummy node + tail.p = head.p; + for (; first != last; ++first) + push_back(*first); + } nodePtr newNode(const T& val = T()){ nodePtr res = nodeAllocator::allocate(); res->container = this;