Line data Source code
1 : // optional_last_value function object (documented as part of Boost.Signals2) 2 : 3 : // Copyright Frank Mori Hess 2007-2008. 4 : // Copyright Douglas Gregor 2001-2003. 5 : // Distributed under 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) 8 : 9 : // See http://www.boost.org/libs/signals2 for library home page. 10 : 11 : #ifndef BOOST_SIGNALS2_OPTIONAL_LAST_VALUE_HPP 12 : #define BOOST_SIGNALS2_OPTIONAL_LAST_VALUE_HPP 13 : 14 : #include <boost/core/no_exceptions_support.hpp> 15 : #include <boost/move/utility_core.hpp> 16 : #include <boost/optional.hpp> 17 : #include <boost/signals2/expired_slot.hpp> 18 : 19 : namespace boost { 20 : namespace signals2 { 21 : 22 : template<typename T> 23 : class optional_last_value 24 : { 25 : public: 26 : typedef optional<T> result_type; 27 : 28 : template<typename InputIterator> 29 351 : optional<T> operator()(InputIterator first, InputIterator last) const 30 : { 31 351 : optional<T> value; 32 702 : while (first != last) 33 : { 34 : BOOST_TRY 35 : { 36 351 : value = boost::move_if_not_lvalue_reference<T>(*first); 37 351 : } 38 0 : BOOST_CATCH(const expired_slot &) {} 39 : BOOST_CATCH_END 40 351 : ++first; 41 : } 42 351 : return value; 43 0 : } 44 : }; 45 : 46 : template<> 47 : class optional_last_value<void> 48 : { 49 : public: 50 : typedef void result_type; 51 : template<typename InputIterator> 52 1044630 : result_type operator()(InputIterator first, InputIterator last) const 53 : { 54 1419812 : while (first != last) 55 : { 56 : BOOST_TRY 57 : { 58 375182 : *first; 59 375182 : } 60 0 : BOOST_CATCH(const expired_slot &) {} 61 : BOOST_CATCH_END 62 375182 : ++first; 63 : } 64 1044630 : return; 65 0 : } 66 : }; 67 : } // namespace signals2 68 : } // namespace boost 69 : #endif // BOOST_SIGNALS2_OPTIONAL_LAST_VALUE_HPP