last_value.hpp 1.2 KB

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