]> git.lyx.org Git - lyx.git/blob - boost/boost/last_value.hpp
Boost 1.31.0
[lyx.git] / boost / boost / last_value.hpp
1 // last_value function object (documented as part of Boost.Signals)
2
3 // Copyright Doug 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
15 namespace boost {
16   template<typename T>
17   struct last_value {
18     typedef T result_type;
19
20     template<typename InputIterator>
21     T operator()(InputIterator first, InputIterator last) const
22     {
23       assert(first != last);
24       T value = *first++;
25       while (first != last)
26         value = *first++;
27       return value;
28     }
29   };
30
31   template<>
32   struct last_value<void> {
33     struct unusable {};
34
35   public:
36     typedef unusable result_type;
37
38     template<typename InputIterator>
39     result_type
40     operator()(InputIterator first, InputIterator last) const
41     {
42       while (first != last)
43         *first++;
44       return result_type();
45     }
46   };
47 }
48 #endif // BOOST_SIGNALS_LAST_VALUE_HPP