diff options
author | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2013-08-26 08:15:55 -0400 |
commit | bb4dd8289b351fae6b55e303f189127a394a1edd (patch) | |
tree | 77c9c35a31b1459dd7988c2448e797d142530c41 /libs/local_function/test/return_inc.cpp | |
parent | 1a78a62555be32868418fe52f8e330c9d0f95d5a (diff) | |
download | boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.gz boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.bz2 boost-bb4dd8289b351fae6b55e303f189127a394a1edd.zip |
Imported Upstream version 1.51.0upstream/1.51.0
Diffstat (limited to 'libs/local_function/test/return_inc.cpp')
-rw-r--r-- | libs/local_function/test/return_inc.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/local_function/test/return_inc.cpp b/libs/local_function/test/return_inc.cpp new file mode 100644 index 0000000000..4be2d01933 --- /dev/null +++ b/libs/local_function/test/return_inc.cpp @@ -0,0 +1,38 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/local_function + +#include <boost/config.hpp> +#ifdef BOOST_NO_VARIADIC_MACROS +# error "variadic macros required" +#else + +#include <boost/local_function.hpp> +#include <boost/function.hpp> +#include <boost/detail/lightweight_test.hpp> + +boost::function<int (void)> inc(int& value) { + int BOOST_LOCAL_FUNCTION(bind& value) { + return ++value; + } BOOST_LOCAL_FUNCTION_NAME(i) + return i; +} + +int main(void) { + int value1 = 0; // Reference valid in scope where closure is used. + boost::function<int (void)> inc1 = inc(value1); + int value2 = 0; + boost::function<int (void)> inc2 = inc(value2); + + BOOST_TEST(inc1() == 1); + BOOST_TEST(inc1() == 2); + BOOST_TEST(inc2() == 1); + BOOST_TEST(inc1() == 3); + return boost::report_errors(); +} + +#endif // VARIADIC_MACROS + |