diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-06-25 22:59:01 +0000 |
---|---|---|
committer | <> | 2013-09-27 11:49:28 +0000 |
commit | 8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch) | |
tree | c09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/lambda/test/bll_and_function.cpp | |
download | boost-tarball-baserock/morph.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/lambda/test/bll_and_function.cpp')
-rw-r--r-- | libs/lambda/test/bll_and_function.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libs/lambda/test/bll_and_function.cpp b/libs/lambda/test/bll_and_function.cpp new file mode 100644 index 000000000..03bcc3ec2 --- /dev/null +++ b/libs/lambda/test/bll_and_function.cpp @@ -0,0 +1,68 @@ +// bll_and_function.cpp - The Boost Lambda Library ----------------------- +// +// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi) +// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com) +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// For more information, see www.boost.org + +// test using BLL and boost::function + +#include <boost/test/minimal.hpp> // see "Header Implementation Option" + +#include "boost/lambda/lambda.hpp" + +#include "boost/function.hpp" + +#include <vector> +#include <map> +#include <set> +#include <string> + + +using namespace boost::lambda; + +using namespace std; + +void test_function() { + + boost::function<int (int, int)> f; + f = _1 + _2; + + BOOST_CHECK(f(1, 2)== 3); + + int i=1; int j=2; + boost::function<int& (int&, int)> g = _1 += _2; + g(i, j); + BOOST_CHECK(i==3); + + + + int* sum = new int(); + *sum = 0; + boost::function<int& (int)> counter = *sum += _1; + counter(5); // ok, sum* = 5; + BOOST_CHECK(*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; +} + + + + + + |