Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:08:48

0001 // last_value function object (documented as part of Boost.Signals)
0002 
0003 // Copyright Frank Mori Hess 2007.
0004 // Copyright Douglas Gregor 2001-2003. Use, modification and
0005 // distribution is subject to the Boost Software License, Version
0006 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 // For more information, see http://www.boost.org
0010 
0011 #ifndef BOOST_SIGNALS2_LAST_VALUE_HPP
0012 #define BOOST_SIGNALS2_LAST_VALUE_HPP
0013 
0014 #include <boost/core/no_exceptions_support.hpp>
0015 #include <boost/move/utility_core.hpp>
0016 #include <boost/optional.hpp>
0017 #include <boost/signals2/expired_slot.hpp>
0018 #include <boost/throw_exception.hpp>
0019 #include <stdexcept>
0020 
0021 namespace boost {
0022   namespace signals2 {
0023 
0024     // no_slots_error is thrown when we are unable to generate a return value
0025     // due to no slots being connected to the signal.
0026     class no_slots_error: public std::exception
0027     {
0028     public:
0029       virtual const char* what() const throw() {return "boost::signals2::no_slots_error";}
0030     };
0031 
0032     template<typename T>
0033     class last_value {
0034     public:
0035       typedef T result_type;
0036 
0037       template<typename InputIterator>
0038       T operator()(InputIterator first, InputIterator last) const
0039       {
0040         if(first == last)
0041         {
0042           boost::throw_exception(no_slots_error());
0043         }
0044         optional<T> value;
0045         while (first != last)
0046         {
0047           BOOST_TRY
0048           {
0049             value = boost::move_if_not_lvalue_reference<T>(*first);
0050           }
0051           BOOST_CATCH(const expired_slot &) {}
0052           BOOST_CATCH_END
0053           ++first;
0054         }
0055         if(value) return value.get();
0056         boost::throw_exception(no_slots_error());
0057       }
0058     };
0059 
0060     template<>
0061     class last_value<void> {
0062     public:
0063       typedef void result_type;
0064       template<typename InputIterator>
0065         result_type operator()(InputIterator first, InputIterator last) const
0066       {
0067         while (first != last)
0068         {
0069           BOOST_TRY
0070           {
0071             *first;
0072           }
0073           BOOST_CATCH(const expired_slot &) {}
0074           BOOST_CATCH_END
0075           ++first;
0076         }
0077         return;
0078       }
0079     };
0080   } // namespace signals2
0081 } // namespace boost
0082 #endif // BOOST_SIGNALS2_LAST_VALUE_HPP