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:
1.2 KB
|
Line | |
---|
1 | // bll_and_function.cpp - The Boost Lambda Library ----------------------- |
---|
2 | // |
---|
3 | // Copyright (C) 2000-2003 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) |
---|
4 | // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com) |
---|
5 | // |
---|
6 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
7 | // accompanying file LICENSE_1_0.txt or copy at |
---|
8 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | // |
---|
10 | // For more information, see www.boost.org |
---|
11 | |
---|
12 | // test using BLL and boost::function |
---|
13 | |
---|
14 | #include <boost/test/minimal.hpp> // see "Header Implementation Option" |
---|
15 | |
---|
16 | #include "boost/lambda/lambda.hpp" |
---|
17 | |
---|
18 | #include "boost/function.hpp" |
---|
19 | |
---|
20 | #include <vector> |
---|
21 | #include <map> |
---|
22 | #include <set> |
---|
23 | #include <string> |
---|
24 | |
---|
25 | |
---|
26 | using namespace boost::lambda; |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | void test_function() { |
---|
31 | |
---|
32 | boost::function<int (int, int)> f; |
---|
33 | f = _1 + _2; |
---|
34 | |
---|
35 | BOOST_CHECK(f(1, 2)== 3); |
---|
36 | |
---|
37 | int i=1; int j=2; |
---|
38 | boost::function<int& (int&, int)> g = _1 += _2; |
---|
39 | g(i, j); |
---|
40 | BOOST_CHECK(i==3); |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | int* sum = new int(); |
---|
45 | *sum = 0; |
---|
46 | boost::function<int& (int)> counter = *sum += _1; |
---|
47 | counter(5); // ok, sum* = 5; |
---|
48 | BOOST_CHECK(*sum == 5); |
---|
49 | delete sum; |
---|
50 | |
---|
51 | // The next statement would lead to a dangling reference |
---|
52 | // counter(3); // error, *sum does not exist anymore |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | int test_main(int, char *[]) { |
---|
58 | |
---|
59 | test_function(); |
---|
60 | |
---|
61 | return 0; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | |
---|
Note: See
TracBrowser
for help on using the repository browser.