From 65fe870596a2f27fc0dd30552b43bd7ddf934758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20J=C3=A4rvi?= Date: Thu, 21 Feb 2002 16:03:12 +0000 Subject: [PATCH] test file for using boost::function and BLL together [SVN r12877] --- test/bll_and_function.cpp | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/bll_and_function.cpp diff --git a/test/bll_and_function.cpp b/test/bll_and_function.cpp new file mode 100644 index 0000000..e6e4fb1 --- /dev/null +++ b/test/bll_and_function.cpp @@ -0,0 +1,64 @@ +// bll_and_function.cpp -------------------------------- + +// test using BLL and boost::function + +#define BOOST_INCLUDE_MAIN // for testing, include rather than link +#include // see "Header Implementation Option" + +#include "boost/lambda/lambda.hpp" + +#include "boost/function.hpp" + +#include +#include +#include +#include + + +using namespace boost::lambda; + +using namespace std; + +void test_function() { + + boost::function f; + f = unlambda(_1 + _2); + + // unlambda must be used, because boost::function tries to take the + // address of the function object that is assigned. However, the + // operator& is overloaded for lambda functors, which creates a conflict + + BOOST_TEST(f(1, 2)== 3); + + int i=1; int j=2; + boost::function g = unlambda(_1 += _2); + g(i, j); + BOOST_TEST(i==3); + + + + int* sum = new int(); + *sum = 0; + boost::function counter = unlambda(*sum += _1); + counter(5); // ok, sum* = 5; + BOOST_TEST(*sum == 5); + delete sum; + + // The next statement would lead to a dangling reference + // counter(3); // error, *sum does not exist anymore + +} + + +int test_main(int, char *[]) { + + test_function(); + + return 0; +} + + + + + +