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/detail/result_type_wrapper.hpp>
16 #include <boost/throw_exception.hpp>
23 // no_slots_error is thrown when we are unable to generate a return value
24 // due to no slots being connected to the signal.
25 class no_slots_error
: public std::exception
28 virtual const char* what() const throw() {return "boost::signals2::no_slots_error";}
34 typedef T result_type
;
36 template<typename InputIterator
>
37 T
operator()(InputIterator first
, InputIterator last
) const
42 boost::throw_exception(no_slots_error());
51 catch(const expired_slot
&) {}
54 if(value
) return value
.get();
55 boost::throw_exception(no_slots_error());
60 class last_value
<void> {
62 typedef detail::result_type_wrapper
<void>::type result_type
;
63 template<typename InputIterator
>
64 result_type
operator()(InputIterator first
, InputIterator last
) const
72 catch(const expired_slot
&) {}
78 } // namespace signals2
80 #endif // BOOST_SIGNALS2_LAST_VALUE_HPP