~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/last_value.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// last_value function object (documented as part of Boost.Signals)
 
2
//
 
3
// Copyright (C) 2001 Doug Gregor (gregod@cs.rpi.edu)
 
4
//
 
5
// Permission to copy, use, sell and distribute this software is granted
 
6
// provided this copyright notice appears in all copies.
 
7
// Permission to modify the code and to distribute modified code is granted
 
8
// provided this copyright notice appears in all copies, and a notice
 
9
// that the code was modified is included with the copyright notice.
 
10
//
 
11
// This software is provided "as is" without express or implied warranty,
 
12
// and with no claim as to its suitability for any purpose.
 
13
 
 
14
// For more information, see http://www.boost.org/libs/signals
 
15
 
 
16
#ifndef BOOST_LAST_VALUE_HPP
 
17
#define BOOST_LAST_VALUE_HPP
 
18
 
 
19
#include <cassert>
 
20
 
 
21
namespace boost {
 
22
  template<typename T>
 
23
  struct last_value {
 
24
    typedef T result_type;
 
25
    
 
26
    template<typename InputIterator>
 
27
    T operator()(InputIterator first, InputIterator last) const
 
28
    {
 
29
      assert(first != last);
 
30
      T value = *first++;
 
31
      while (first != last)
 
32
        value = *first++;
 
33
      return value;
 
34
    }
 
35
  };
 
36
  
 
37
  template<>
 
38
  struct last_value<void> {
 
39
    struct unusable {};
 
40
 
 
41
  public:
 
42
    typedef unusable result_type;
 
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