Update of /cvsroot/boost-sandbox/boost-sandbox/boost
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20359/boost
Modified Files:
last_value.hpp
Log Message:
Made slots throw bad_weak_ptr when called with expired tracked
objects. Combiners now have to catch bad_weak_ptr exceptions
thrown on slot iterator dereference. Tracking works automatically
now for slots that call other slots.
Index: last_value.hpp
===================================================================
RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/last_value.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- last_value.hpp 11 Feb 2007 23:02:50 -0000 1.2
+++ last_value.hpp 2 Mar 2007 22:04:46 -0000 1.3
@@ -13,11 +13,12 @@
#include <cassert>
#include <boost/optional.hpp>
+#include <boost/weak_ptr.hpp>
#include <stdexcept>
namespace boost {
// no_slots_error is thrown when we are unable to generate a return value
- // due to no slots being connected to the signal.
+ // due to no slots being connected to the signal.
class no_slots_error: public std::runtime_error
{
public:
@@ -43,15 +44,24 @@
template<typename InputIterator>
T operator()(InputIterator first, InputIterator last) const
{
+ T * resolver = 0;
if(first == last)
{
- T *resolver = 0;
return last_value_detail::default_construct(resolver);
}
- T value = *first++;
+ optional<T> value;
while (first != last)
- value = *first++;
- return value;
+ {
+ try
+ {
+ value = *first;
+ }
+ catch(const bad_weak_ptr &err)
+ {}
+ ++first;
+ }
+ if(value) return value.get();
+ return last_value_detail::default_construct(resolver);
}
};
@@ -67,7 +77,15 @@
operator()(InputIterator first, InputIterator last) const
{
while (first != last)
- *first++;
+ {
+ try
+ {
+ *first;
+ }
+ catch(const bad_weak_ptr &err)
+ {}
+ ++first;
+ }
return result_type();
}
};
|