1 // last_value function object (documented as part of Boost.Signals)
3 // Copyright Frank Mori Hess 2007.
4 // Copyright Douglas Gregor 2001-2003. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org
11 #ifndef BOOST_SIGNALS2_LAST_VALUE_HPP
12 #define BOOST_SIGNALS2_LAST_VALUE_HPP
14 #include <boost/optional.hpp>
15 #include <boost/signals2/expired_slot.hpp>
21 // no_slots_error is thrown when we are unable to generate a return value
22 // due to no slots being connected to the signal.
23 class no_slots_error: public std::exception
26 virtual const char* what() const throw() {return "boost::signals2::no_slots_error";}
32 typedef T result_type;
34 template<typename InputIterator>
35 T operator()(InputIterator first, InputIterator last) const
39 throw no_slots_error();
48 catch(const expired_slot &) {}
51 if(value) return value.get();
52 throw no_slots_error();
57 class last_value<void> {
59 typedef void result_type;
60 template<typename InputIterator>
61 result_type operator()(InputIterator first, InputIterator last) const
69 catch(const expired_slot &) {}
75 } // namespace signals2
77 #endif // BOOST_SIGNALS2_LAST_VALUE_HPP