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#include "boost/lambda/bind.hpp"
18#include "boost/lambda/algorithm.hpp"
19
20#include <vector>
21#include <map>
22#include <set>
23#include <string>
24
25#include <iostream>
26
27
28
29void test_foreach() {
30 using namespace boost::lambda;
31
32 int a[10][20];
33 int sum = 0;
34
35 std::for_each(first: a, last: a + 10,
36 f: bind(a1: ll::for_each(), a2: _1, a3: _1 + 20,
37 a4: protect(a1: (_1 = var(t&: sum), ++var(t&: sum)))));
38
39 sum = 0;
40 std::for_each(first: a, last: a + 10,
41 f: bind(a1: ll::for_each(), a2: _1, a3: _1 + 20,
42 a4: protect(a1: (sum += _1))));
43
44 BOOST_CHECK(sum == (199 + 1)/ 2 * 199);
45}
46
47// More tests needed (for all algorithms)
48
49int test_main(int, char *[]) {
50
51 test_foreach();
52
53 return 0;
54}
55
56
57
58
59
60
61

source code of boost/libs/lambda/test/algorithm_test.cpp