From 0e70978fcc0887d2e247c5d74f0ddc270cb1664d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Thu, 27 Nov 2014 11:23:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90swap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/List.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/TinySTL/List.h b/TinySTL/List.h index 4d32d27..3e7a501 100644 --- a/TinySTL/List.h +++ b/TinySTL/List.h @@ -132,7 +132,7 @@ namespace TinySTL{ void insert(iterator position, InputIterator first, InputIterator last); iterator erase(iterator position); iterator erase(iterator first, iterator last); - //void swap(List& x); + void swap(List& x); void clear(); //void splice(iterator position, list& x); //void splice(iterator position, list& x, iterator i); @@ -175,6 +175,9 @@ namespace TinySTL{ insert(position, *first); } } + public: + template + friend void swap(List& x, List& y); }; template void List::push_front(const value_type& val){ @@ -284,6 +287,15 @@ namespace TinySTL{ ++it; } } + template + void List::swap(List& x){ + TinySTL::swap(head.p, x.head.p); + TinySTL::swap(tail.p, x.tail.p); + } + template + void swap(List& x, List& y){ + x.swap(y); + } } #endif \ No newline at end of file