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