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;