Improve vacpp support.
[boost.git] / boost / libs / signals / example / first_positive.cpp
blob1d6cfacd234db090020c5d6c250668a8324d55cc
1 // Boost.Signals library
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)
8 // For more information, see http://www.boost.org
10 #include <boost/signals/signal2.hpp>
11 #include <iostream>
13 template<typename T>
14 struct first_positive {
15 typedef T result_type;
17 template<typename InputIterator>
18 T operator()(InputIterator first, InputIterator last) const
20 while (first != last && !(*first > 0)) { ++first; }
21 return (first == last) ? 0
22 : *first;
26 template<typename T>
27 struct noisy_divide {
28 typedef T result_type;
30 T operator()(const T& x, const T& y) const
32 std::cout << "Dividing " << x << " and " << y << std::endl;
33 return x/y;
37 int main()
39 boost::signal2<int, int, int, first_positive<int> > sig_positive;
40 sig_positive.connect(std::plus<int>());
41 sig_positive.connect(std::multiplies<int>());
42 sig_positive.connect(std::minus<int>());
43 sig_positive.connect(noisy_divide<int>());
45 assert(sig_positive(3, -5) == 8); // returns 8, but prints nothing
47 return 0;