|
Last change
on this file since 29 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
1.2 KB
|
| 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 <boost/signals/signal2.hpp> |
|---|
| 11 | #include <iostream> |
|---|
| 12 | |
|---|
| 13 | template<typename T> |
|---|
| 14 | struct first_positive { |
|---|
| 15 | typedef T result_type; |
|---|
| 16 | |
|---|
| 17 | template<typename InputIterator> |
|---|
| 18 | T operator()(InputIterator first, InputIterator last) const |
|---|
| 19 | { |
|---|
| 20 | while (first != last && !(*first > 0)) { ++first; } |
|---|
| 21 | return (first == last) ? 0 |
|---|
| 22 | : *first; |
|---|
| 23 | } |
|---|
| 24 | }; |
|---|
| 25 | |
|---|
| 26 | template<typename T> |
|---|
| 27 | struct noisy_divide { |
|---|
| 28 | typedef T result_type; |
|---|
| 29 | |
|---|
| 30 | T operator()(const T& x, const T& y) const |
|---|
| 31 | { |
|---|
| 32 | std::cout << "Dividing " << x << " and " << y << std::endl; |
|---|
| 33 | return x/y; |
|---|
| 34 | } |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | int main() |
|---|
| 38 | { |
|---|
| 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>()); |
|---|
| 44 | |
|---|
| 45 | assert(sig_positive(3, -5) == 8); // returns 8, but prints nothing |
|---|
| 46 | |
|---|
| 47 | return 0; |
|---|
| 48 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.