Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/signals/example/maximum.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 997 bytes
Line 
1// Boost.Signals library
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
9
10#include <algorithm>
11#include <iostream>
12#include <boost/signals/signal2.hpp>
13
14template<typename T>
15struct maximum {
16  typedef T result_type;
17
18  template<typename InputIterator>
19  T operator()(InputIterator first, InputIterator last) const
20  {
21    if (first == last)
22      throw std::runtime_error("Cannot compute maximum of zero elements!");
23    return *std::max_element(first, last);
24  }
25};
26
27int main()
28{
29  boost::signal2<int, int, int, maximum<int> > sig_max;
30  sig_max.connect(std::plus<int>());
31  sig_max.connect(std::multiplies<int>());
32  sig_max.connect(std::minus<int>());
33  sig_max.connect(std::divides<int>());
34
35  std::cout << sig_max(5, 3) << std::endl; // prints 15
36
37  return 0;
38}
Note: See TracBrowser for help on using the repository browser.