1 | // last_value function object (documented as part of Boost.Signals) |
2 | |
3 | // Copyright Douglas Gregor 2001-2003. Use, modification and |
4 | // distribution is subject to the Boost Software License, Version |
5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
6 | // http://www.boost.org/LICENSE_1_0.txt) |
7 | |
8 | // For more information, see http://www.boost.org/libs/signals |
9 | |
10 | #ifndef BOOST_LAST_VALUE_HPP |
11 | #define BOOST_LAST_VALUE_HPP |
12 | |
13 | #include <cassert> |
14 | #include <boost/config.hpp> |
15 | |
16 | namespace boost { |
17 | template<typename T> |
18 | struct last_value { |
19 | typedef T result_type; |
20 | |
21 | template<typename InputIterator> |
22 | T operator()(InputIterator first, InputIterator last) const |
23 | { |
24 | assert(first != last); |
25 | T value = *first++; |
26 | while (first != last) |
27 | value = *first++; |
28 | return value; |
29 | } |
30 | }; |
31 | |
32 | template<> |
33 | struct last_value<void> { |
34 | #ifdef BOOST_NO_VOID_RETURNS |
35 | struct unusable {}; |
36 | |
37 | public: |
38 | typedef unusable result_type; |
39 | #else |
40 | public: |
41 | typedef void result_type; |
42 | #endif // BOOST_NO_VOID_RETURNS |
43 | |
44 | template<typename InputIterator> |
45 | result_type |
46 | operator()(InputIterator first, InputIterator last) const |
47 | { |
48 | while (first != last) |
49 | *first++; |
50 | return result_type(); |
51 | } |
52 | }; |
53 | } |
54 | #endif // BOOST_SIGNALS_LAST_VALUE_HPP |
55 | |