From 7d0ebc8e8e969911049bf83ce4102d86aa36ce2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Tue, 13 Jan 2015 20:28:08 +0800 Subject: [PATCH] bug fix --- TinySTL/Detail/List.impl.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/TinySTL/Detail/List.impl.h b/TinySTL/Detail/List.impl.h index 57241f6..d52b1b2 100644 --- a/TinySTL/Detail/List.impl.h +++ b/TinySTL/Detail/List.impl.h @@ -44,9 +44,14 @@ namespace TinySTL{ template template void list::insert_aux(iterator position, InputIterator first, InputIterator last, std::false_type){ - for (; first != last; ++first){ - insert(position, *first); + //for (; first != last; ++first){ + // insert(position, *first); + // position = insert(position, *first); + //} + for (--last; first != last; --last){ + position = insert(position, *last); } + insert(position, *last); } template typename list::nodePtr list::newNode(const T& val = T()){ @@ -156,6 +161,14 @@ namespace TinySTL{ } template typename list::iterator list::insert(iterator position, const value_type& val){ + if (position == begin()){ + push_front(val); + return begin(); + }else if (position == end()){ + auto ret = position; + push_back(val); + return ret; + } auto node = newNode(val); auto prev = position.p->prev; node->next = position.p;