Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/signals2/last_value.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // last_value function object (documented as part of Boost.Signals) | |
2 | |
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) | |
8 | |
9 // For more information, see http://www.boost.org | |
10 | |
11 #ifndef BOOST_SIGNALS2_LAST_VALUE_HPP | |
12 #define BOOST_SIGNALS2_LAST_VALUE_HPP | |
13 | |
14 #include <boost/optional.hpp> | |
15 #include <boost/signals2/expired_slot.hpp> | |
16 #include <boost/throw_exception.hpp> | |
17 #include <stdexcept> | |
18 | |
19 namespace boost { | |
20 namespace signals2 { | |
21 | |
22 // no_slots_error is thrown when we are unable to generate a return value | |
23 // due to no slots being connected to the signal. | |
24 class no_slots_error: public std::exception | |
25 { | |
26 public: | |
27 virtual const char* what() const throw() {return "boost::signals2::no_slots_error";} | |
28 }; | |
29 | |
30 template<typename T> | |
31 class last_value { | |
32 public: | |
33 typedef T result_type; | |
34 | |
35 template<typename InputIterator> | |
36 T operator()(InputIterator first, InputIterator last) const | |
37 { | |
38 if(first == last) | |
39 { | |
40 boost::throw_exception(no_slots_error()); | |
41 } | |
42 optional<T> value; | |
43 while (first != last) | |
44 { | |
45 try | |
46 { | |
47 value = *first; | |
48 } | |
49 catch(const expired_slot &) {} | |
50 ++first; | |
51 } | |
52 if(value) return value.get(); | |
53 boost::throw_exception(no_slots_error()); | |
54 } | |
55 }; | |
56 | |
57 template<> | |
58 class last_value<void> { | |
59 public: | |
60 typedef void result_type; | |
61 template<typename InputIterator> | |
62 result_type operator()(InputIterator first, InputIterator last) const | |
63 { | |
64 while (first != last) | |
65 { | |
66 try | |
67 { | |
68 *first; | |
69 } | |
70 catch(const expired_slot &) {} | |
71 ++first; | |
72 } | |
73 return; | |
74 } | |
75 }; | |
76 } // namespace signals2 | |
77 } // namespace boost | |
78 #endif // BOOST_SIGNALS2_LAST_VALUE_HPP |