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;