From c540a8e6bd3b9e92978835478f87245cba2fa37c Mon Sep 17 00:00:00 2001
From: Markus Blatt <mblatt@dune-project.org>
Date: Wed, 17 Nov 2004 17:00:04 +0000
Subject: [PATCH] Some additional functions and tests. Removed compiler
 warning.

[[Imported from SVN: r1118]]
---
 common/sllist.hh          | 18 ++++++++++++++----
 common/test/sllisttest.cc | 32 ++++++++++++++++++++++++++------
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/common/sllist.hh b/common/sllist.hh
index 1ce1d1266..d6310114f 100644
--- a/common/sllist.hh
+++ b/common/sllist.hh
@@ -79,10 +79,7 @@ namespace Dune
      */
     inline void pop_front();
 
-    /**
-     * @brief Remove the first item in the list.
-     * @return The last item in the list or 0 if the list is empty.
-       /** @brief Remove all elements from the list. */
+    /** @brief Remove all elements from the list. */
     inline void clear();
 
     /**
@@ -118,6 +115,13 @@ namespace Dune
      */
     inline const_iterator end() const;
 
+    /**
+     * @brief Check whether the list is empty.
+     *
+     * @return True if the list is empty;
+     */
+    inline bool empty() const;
+
   private:
     struct Element
     {
@@ -326,6 +330,12 @@ namespace Dune
     tail_ = head_;
   }
 
+  template<typename T, class A>
+  inline bool SLList<T,A>::empty() const
+  {
+    return head_==0;
+  }
+
   template<typename T, class A>
   inline SLListIterator<T,A> SLList<T,A>::begin()
   {
diff --git a/common/test/sllisttest.cc b/common/test/sllisttest.cc
index ff8a64540..c02869e40 100644
--- a/common/test/sllisttest.cc
+++ b/common/test/sllisttest.cc
@@ -5,8 +5,25 @@
 #include <dune/common/poolallocator.hh>
 #include <iostream>
 
-template<class A>
-void randomizeListBack(Dune::SLList<double,A>& alist){
+class DoubleWrapper
+{
+public:
+  DoubleWrapper(double b)
+    : d(b)
+  {}
+
+  operator double()
+  {
+    return d;
+  }
+
+private:
+  double d;
+};
+
+
+template<typename T,class A>
+void randomizeListBack(Dune::SLList<T,A>& alist){
   using namespace Dune;
 
   srand((unsigned)time(0));
@@ -14,11 +31,11 @@ void randomizeListBack(Dune::SLList<double,A>& alist){
   int lowest=0, highest=1000, range=(highest-lowest)+1;
 
   for(int i=0; i < 10; i++)
-    alist.push_back((range*(rand()/(RAND_MAX+1.0))));
+    alist.push_back(T(range*(rand()/(RAND_MAX+1.0))));
 }
 
-template<class A>
-void randomizeListFront(Dune::SLList<double,A>& alist){
+template<typename T,class A>
+void randomizeListFront(Dune::SLList<T,A>& alist){
   using namespace Dune;
 
   srand((unsigned)time(0));
@@ -73,9 +90,11 @@ int main()
 
   Dune::SLList<double> list;
   Dune::SLList<double,Dune::PoolAllocator<double, 8*1024-20> > list1;
-
+  Dune::SLList<DoubleWrapper, Dune::PoolAllocator<DoubleWrapper, 8*1024-20> > list2;
   randomizeListBack(list1);
   randomizeListFront(list);
+  randomizeListFront(list2);
+
 
   ret+=testIterator(list);
   ret+=testIterator(list1);
@@ -83,6 +102,7 @@ int main()
 
   list.clear();
   list1.clear();
+  list2.clear();
   randomizeListBack(list);
   randomizeListFront(list1);
   exit(ret);
-- 
GitLab