diff --git a/common/sllist.hh b/common/sllist.hh index 250df27618ceaf9c99e125eff94c8558ea02ea20..c0f5a4633ddec01c04b5c0b4a9ffec9d74167a82 100644 --- a/common/sllist.hh +++ b/common/sllist.hh @@ -101,6 +101,12 @@ namespace Dune */ typedef SLListModifyIterator<T,A> ModifyIterator; + /** + * @brief Assignment operator. + */ + SLList<T,A>& operator=(const SLList<T,A>& other); + + /** * @brief Add a new entry to the end of the list. * @param item The item to add. @@ -205,17 +211,6 @@ namespace Dune }; - template<typename T1, typename A1> - SLList<T,A>& operator=(SLList<T1,A1>& other) - { - return *this; - } - - SLList<T,A>& operator=(SLList<T,A>& other) - { - return *this; - } - /** * @brief Delete the next element in the list. * @param current Element whose next element should be deleted. @@ -226,8 +221,7 @@ namespace Dune * @brief Copy the elements from another list. * @param other The other list. */ - template<class T1, class A1> - void copyElements(const SLList<T1,A1>& other); + void copyElements(const SLList<T,A>& other); /** * @brief Delete the next element in the list. @@ -598,8 +592,7 @@ namespace Dune } template<typename T, typename A> - template<typename T1, class A1> - void SLList<T,A>::copyElements(const SLList<T1,A1>& other) + void SLList<T,A>::copyElements(const SLList<T,A>& other) { assert(tail_==&beforeHead_); assert(size_==0); @@ -617,6 +610,14 @@ namespace Dune clear(); } + template<typename T, class A> + SLList<T,A>& SLList<T,A>::operator=(const SLList<T,A>& other) + { + clear(); + copyElements(other); + return *this; + } + template<typename T, class A> inline void SLList<T,A>::push_back(const T& item) { @@ -721,9 +722,6 @@ namespace Dune this->template deleteNext<false>(&beforeHead_); } -#ifdef NDEBUG - size_=0; -#endif assert(size_==0); // update the tail! tail_ = &beforeHead_; diff --git a/common/test/sllisttest.cc b/common/test/sllisttest.cc index 3b00d7dba393f653000b119ccce1d654e9a7d2e5..79a72f37be5349bd998994a10879401cb02fca36 100644 --- a/common/test/sllisttest.cc +++ b/common/test/sllisttest.cc @@ -122,6 +122,26 @@ void randomizeListFront(Dune::SLList<T,A>& alist){ check(alist, vals); } +int testAssign() +{ + typedef Dune::SLList<int,IntAllocator> List; + List alist, blist; + + alist.push_back(3); + alist.push_back(4); + alist.push_back(5); + + blist.push_back(-1); + + blist=alist; + List::iterator biter=blist.begin(), aiter=alist.begin(); + for(; aiter!=alist.end(); ++aiter, ++biter) + if(*aiter!=*biter) { + std::cerr<<"Asignment failed "<<__FILE__<<":"<<__LINE__<<std::endl; + return 1; + } + return 0; +} int testDelete() { @@ -293,29 +313,6 @@ int testInsert() return ret; } -template<typename T> -int testOneBeforeBegin(T& alist) -{ - typename T::iterator iterBefore = alist.oneBeforeBegin(), - iter = alist.begin(); - typename T::const_iterator citerBefore = alist.oneBeforeBegin(); - - int ret=0; - ++iterBefore; - ++citerBefore; - - if(iterBefore!=iter || &(*iterBefore) != &(*iter)) { - std::cerr<<"one before iterator incremented once should point to begin()! "<<__FILE__<<":"<<__LINE__<<std::endl; - ret++; - } - if(citerBefore!=iter || &(*citerBefore) != &(*iter)) { - std::cerr<<"one before iterator incremented once should point to begin()! "<<__FILE__<<":"<<__LINE__<<std::endl; - ret++; - } - return ret; -} - - int testPushPop(){ using namespace Dune; int ret=0; @@ -392,45 +389,46 @@ int main() } } - //randomizeListFront(list2); - /* - Printer<std::iterator_traits<Dune::SLList<double,DoubleAllocator>::ModifyIterator>::value_type> print; + randomizeListFront(list2); + + Printer<std::iterator_traits<Dune::SLList<double,DoubleAllocator>::ModifyIterator>::value_type> print; + + Dune::SLList<double,DoubleAllocator>::ModifyIterator lbegin = list.beginModify(), lend = list.endModify(); - Dune::SLList<double,DoubleAllocator>::ModifyIterator lbegin = list.beginModify(), lend = list.endModify(); + double& d = lbegin.dereference(); - double& d = lbegin.dereference(); + d= 2.0; - d= 2.0; + double& d1 = lbegin.dereference(); - double& d1 = lbegin.dereference(); + lbegin.dereference()=5.0; - lbegin.dereference()=5.0; + lbegin.operator*()=5.0; - lbegin.operator*()=5.0; + *lbegin=5.0; - *lbegin=5.0; + std::cout << "Testing ConstIterator "<<std::endl; + ret+=testConstIterator(lbegin, lend, print); + std::cout << "Testing Iterator "<<std::endl; + ret+=testIterator(list); + std::cout << "Testing Iterator "<<std::endl; + ret+=testIterator(list1); - std::cout << "Testing ConstIterator "<<std::endl; - ret+=testConstIterator(lbegin, lend, print); - std::cout << "Testing Iterator "<<std::endl; - ret+=testIterator(list); - std::cout << "Testing Iterator "<<std::endl; - ret+=testIterator(list1); + std::cout<< " Test PushPop "<<std::endl; + ret+=testPushPop(); + std::cout<<" Test OneBeforeBegin"<<std::endl; - std::cout<< " Test PushPop "<<std::endl; - ret+=testPushPop(); - std::cout<<" Test OneBeforeBegin"<<std::endl; + //ret+=testOneBeforeBegin(list1); - ret+=testOneBeforeBegin(list1); + std::cout<< "test empty"<<std::endl; + ret+=testEmpty(); + std::cout<< "test insert"<<std::endl; - std::cout<< "test empty"<<std::endl; - ret+=testEmpty(); - std::cout<< "test insert"<<std::endl; + ret+=testInsert(); + std::cout<< "test delete"<<std::endl; + ret+=testDelete(); - ret+=testInsert(); - std::cout<< "test delete"<<std::endl; - ret+=testDelete(); - */ + ret+=testAssign(); list.clear(); list1.clear(); list2.clear();