12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #ifndef BOOST_SIGNALS2_LAST_VALUE_HPP
- #define BOOST_SIGNALS2_LAST_VALUE_HPP
- #include <boost/core/no_exceptions_support.hpp>
- #include <boost/move/utility_core.hpp>
- #include <boost/optional.hpp>
- #include <boost/signals2/expired_slot.hpp>
- #include <boost/throw_exception.hpp>
- #include <stdexcept>
- namespace boost {
- namespace signals2 {
-
-
- class no_slots_error: public std::exception
- {
- public:
- virtual const char* what() const throw() {return "boost::signals2::no_slots_error";}
- };
- template<typename T>
- class last_value {
- public:
- typedef T result_type;
- template<typename InputIterator>
- T operator()(InputIterator first, InputIterator last) const
- {
- if(first == last)
- {
- boost::throw_exception(no_slots_error());
- }
- optional<T> value;
- while (first != last)
- {
- BOOST_TRY
- {
- value = boost::move_if_not_lvalue_reference<T>(*first);
- }
- BOOST_CATCH(const expired_slot &) {}
- BOOST_CATCH_END
- ++first;
- }
- if(value) return value.get();
- boost::throw_exception(no_slots_error());
- }
- };
- template<>
- class last_value<void> {
- public:
- typedef void result_type;
- template<typename InputIterator>
- result_type operator()(InputIterator first, InputIterator last) const
- {
- while (first != last)
- {
- BOOST_TRY
- {
- *first;
- }
- BOOST_CATCH(const expired_slot &) {}
- BOOST_CATCH_END
- ++first;
- }
- return;
- }
- };
- }
- }
- #endif
|