Boost logo

Boost-Commit :

From: fmhess_at_[hidden]
Date: 2008-02-27 15:04:24


Author: fmhess
Date: 2008-02-27 15:04:23 EST (Wed, 27 Feb 2008)
New Revision: 43426
URL: http://svn.boost.org/trac/boost/changeset/43426

Log:
Modified track_test to correctly test automatic disconnection of
signal used as slot, without explicit tracking.

Text files modified:
   sandbox/thread_safe_signals/libs/thread_safe_signals/test/track_test.cpp | 30 +++++++++++++++++++++---------
   1 files changed, 21 insertions(+), 9 deletions(-)

Modified: sandbox/thread_safe_signals/libs/thread_safe_signals/test/track_test.cpp
==============================================================================
--- sandbox/thread_safe_signals/libs/thread_safe_signals/test/track_test.cpp (original)
+++ sandbox/thread_safe_signals/libs/thread_safe_signals/test/track_test.cpp 2008-02-27 15:04:23 EST (Wed, 27 Feb 2008)
@@ -9,6 +9,7 @@
 
 // For more information, see http://www.boost.org
 
+#include <boost/optional.hpp>
 #include <boost/ref.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/test/minimal.hpp>
@@ -27,14 +28,25 @@
   template<typename InputIterator>
   T operator()(InputIterator first, InputIterator last) const
   {
- if (first == last)
- return T();
-
- T max = *first++;
- for (; first != last; ++first)
- max = (*first > max)? *first : max;
-
- return max;
+ boost::optional<T> max;
+ for(; first != last; ++first)
+ {
+ try
+ {
+ T value = *first;
+ if(max == false)
+ {
+ max = value;
+ }else if(value > *max)
+ {
+ max = value;
+ }
+ }
+ catch(const boost::expired_slot &)
+ {}
+ }
+ if(max) return *max;
+ else return T();
   }
 };
 
@@ -88,7 +100,7 @@
   // Test binding of a signal as a slot
   {
     sig_type s2;
- s1.connect(sig_type::slot_type(s2).track(s2));
+ s1.connect(s2);
     s2.connect(sig_type::slot_type(&myfunc, _1, 0.7));
     BOOST_CHECK(s1(4) == 4);
   }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk