PageRenderTime 40ms CodeModel.GetById 31ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/bll_compatibility/bll_and_function.cpp

http://hadesmem.googlecode.com/
C++ | 68 lines | 28 code | 27 blank | 13 comment | 1 complexity | 0cc30d91d153e79a951dddbf8a7a6d3d MD5 | raw file
 1//  bll_and_function.cpp  - The Boost Lambda Library -----------------------
 2//
 3// Copyright (C) 2000-2003 Jaakko Jarvi (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
26using namespace boost::lambda;
27
28using namespace std;
29
30void 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
57int test_main(int, char *[]) {
58
59  test_function();
60
61  return 0;
62}
63
64
65
66
67
68