Files
boost_function/test/lambda_test.cpp

41 lines
1.0 KiB
C++
Raw Permalink Normal View History

// Boost.Function library
// Copyright Douglas Gregor 2002-2003. Use, modification and
// distribution is subject to 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 http://www.boost.org
2018-09-24 19:23:58 +03:00
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <cstdlib>
static unsigned
func_impl(int arg1, bool arg2, double arg3)
{
Merge various function changes from trunk. Merged revisions 49571,50064,51743,51745,53722,54616-54619 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r49571 | noel_belcourt | 2008-11-03 18:37:49 +0000 (Mon, 03 Nov 2008) | 9 lines Both Sun and Pgi on Linux correctly put typeinfo into the std namespace, but function_base keys off the BOOST_NO_EXCEPTION_STD_NAMESPACE macro instead of the BOOST_NO_STD_TYPEINFO macro. The attached patch changes function_base to use the typeinfo macro. Because eVC 4.2 doesn't put typeinfo into the std namespace, I need to define BOOST_NO_STD_TYPEINFO only for this eVC version. ........ r50064 | johnmaddock | 2008-12-02 10:10:46 +0000 (Tue, 02 Dec 2008) | 1 line Fix -Wundef warning and suspect usage of BOOST_STRICT_CONFIG. ........ r51743 | dgregor | 2009-03-13 05:23:53 +0000 (Fri, 13 Mar 2009) | 11 lines Implement an optimization that David Abrahams and myself came up with, where Boost.Function uses a bit in the vtable pointer to indicate when the target function object has a trivial copy constructor, trivial destructor, and fits within the small object buffer. In this case, we just copy the bits of the function object rather than performing an indirect call to the manager. This results in a 60% speedup on a micro-benchmark that copies and calls such function objects repeatedly. ........ r51745 | dgregor | 2009-03-13 05:49:02 +0000 (Fri, 13 Mar 2009) | 7 lines Make Boost.Function compile under BOOST_NO_EXCEPTIONS. Fixes #2499 Fixes #2494 Fixes #2469 Fixes #2466 ........ r53722 | vladimir_prus | 2009-06-07 16:44:50 +0100 (Sun, 07 Jun 2009) | 4 lines Make Boost.Function compile with disabled exceptions. Closes #2900. Patch from Gabi Davar. ........ r54616 | danieljames | 2009-07-03 23:20:26 +0100 (Fri, 03 Jul 2009) | 3 lines When copying boost::ref, copy even when the referenced function is empty. Fixes #2642 Patch by Steven Watanabe ........ r54617 | danieljames | 2009-07-03 23:20:52 +0100 (Fri, 03 Jul 2009) | 6 lines Add 'and later versions' to support info for GCC and Visual C++. Fixes #2847. I didn't explicitly specify the versions since no one's updating this list and it's highly unlikely that a future version will break this. The same could probably be done for the other compilers but I don't know them very well so I'm leaving them alone. ........ r54618 | danieljames | 2009-07-03 23:21:40 +0100 (Fri, 03 Jul 2009) | 4 lines Fix Boost.Function unit tests for C++0x. Fixes #3012 Based on a patch from Richard Webb. Changed a bit so that it also works for the Visual C++ 10 beta. ........ r54619 | danieljames | 2009-07-03 23:22:03 +0100 (Fri, 03 Jul 2009) | 3 lines Work around Visual C++ copy constructor bug. Fixes #2929. Based on the patch by Steven Watanabe. ........ [SVN r54824]
2009-07-08 23:23:52 +00:00
using namespace std;
return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
}
2018-09-24 19:23:58 +03:00
int main()
{
Merge various function changes from trunk. Merged revisions 49571,50064,51743,51745,53722,54616-54619 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r49571 | noel_belcourt | 2008-11-03 18:37:49 +0000 (Mon, 03 Nov 2008) | 9 lines Both Sun and Pgi on Linux correctly put typeinfo into the std namespace, but function_base keys off the BOOST_NO_EXCEPTION_STD_NAMESPACE macro instead of the BOOST_NO_STD_TYPEINFO macro. The attached patch changes function_base to use the typeinfo macro. Because eVC 4.2 doesn't put typeinfo into the std namespace, I need to define BOOST_NO_STD_TYPEINFO only for this eVC version. ........ r50064 | johnmaddock | 2008-12-02 10:10:46 +0000 (Tue, 02 Dec 2008) | 1 line Fix -Wundef warning and suspect usage of BOOST_STRICT_CONFIG. ........ r51743 | dgregor | 2009-03-13 05:23:53 +0000 (Fri, 13 Mar 2009) | 11 lines Implement an optimization that David Abrahams and myself came up with, where Boost.Function uses a bit in the vtable pointer to indicate when the target function object has a trivial copy constructor, trivial destructor, and fits within the small object buffer. In this case, we just copy the bits of the function object rather than performing an indirect call to the manager. This results in a 60% speedup on a micro-benchmark that copies and calls such function objects repeatedly. ........ r51745 | dgregor | 2009-03-13 05:49:02 +0000 (Fri, 13 Mar 2009) | 7 lines Make Boost.Function compile under BOOST_NO_EXCEPTIONS. Fixes #2499 Fixes #2494 Fixes #2469 Fixes #2466 ........ r53722 | vladimir_prus | 2009-06-07 16:44:50 +0100 (Sun, 07 Jun 2009) | 4 lines Make Boost.Function compile with disabled exceptions. Closes #2900. Patch from Gabi Davar. ........ r54616 | danieljames | 2009-07-03 23:20:26 +0100 (Fri, 03 Jul 2009) | 3 lines When copying boost::ref, copy even when the referenced function is empty. Fixes #2642 Patch by Steven Watanabe ........ r54617 | danieljames | 2009-07-03 23:20:52 +0100 (Fri, 03 Jul 2009) | 6 lines Add 'and later versions' to support info for GCC and Visual C++. Fixes #2847. I didn't explicitly specify the versions since no one's updating this list and it's highly unlikely that a future version will break this. The same could probably be done for the other compilers but I don't know them very well so I'm leaving them alone. ........ r54618 | danieljames | 2009-07-03 23:21:40 +0100 (Fri, 03 Jul 2009) | 4 lines Fix Boost.Function unit tests for C++0x. Fixes #3012 Based on a patch from Richard Webb. Changed a bit so that it also works for the Visual C++ 10 beta. ........ r54619 | danieljames | 2009-07-03 23:22:03 +0100 (Fri, 03 Jul 2009) | 3 lines Work around Visual C++ copy constructor bug. Fixes #2929. Based on the patch by Steven Watanabe. ........ [SVN r54824]
2009-07-08 23:23:52 +00:00
using boost::function;
using namespace boost::lambda;
function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
2018-09-24 19:23:58 +03:00
BOOST_TEST_EQ( f1(true, 2.0), 30 );
Merge various function changes from trunk. Merged revisions 49571,50064,51743,51745,53722,54616-54619 via svnmerge from https://svn.boost.org/svn/boost/trunk ........ r49571 | noel_belcourt | 2008-11-03 18:37:49 +0000 (Mon, 03 Nov 2008) | 9 lines Both Sun and Pgi on Linux correctly put typeinfo into the std namespace, but function_base keys off the BOOST_NO_EXCEPTION_STD_NAMESPACE macro instead of the BOOST_NO_STD_TYPEINFO macro. The attached patch changes function_base to use the typeinfo macro. Because eVC 4.2 doesn't put typeinfo into the std namespace, I need to define BOOST_NO_STD_TYPEINFO only for this eVC version. ........ r50064 | johnmaddock | 2008-12-02 10:10:46 +0000 (Tue, 02 Dec 2008) | 1 line Fix -Wundef warning and suspect usage of BOOST_STRICT_CONFIG. ........ r51743 | dgregor | 2009-03-13 05:23:53 +0000 (Fri, 13 Mar 2009) | 11 lines Implement an optimization that David Abrahams and myself came up with, where Boost.Function uses a bit in the vtable pointer to indicate when the target function object has a trivial copy constructor, trivial destructor, and fits within the small object buffer. In this case, we just copy the bits of the function object rather than performing an indirect call to the manager. This results in a 60% speedup on a micro-benchmark that copies and calls such function objects repeatedly. ........ r51745 | dgregor | 2009-03-13 05:49:02 +0000 (Fri, 13 Mar 2009) | 7 lines Make Boost.Function compile under BOOST_NO_EXCEPTIONS. Fixes #2499 Fixes #2494 Fixes #2469 Fixes #2466 ........ r53722 | vladimir_prus | 2009-06-07 16:44:50 +0100 (Sun, 07 Jun 2009) | 4 lines Make Boost.Function compile with disabled exceptions. Closes #2900. Patch from Gabi Davar. ........ r54616 | danieljames | 2009-07-03 23:20:26 +0100 (Fri, 03 Jul 2009) | 3 lines When copying boost::ref, copy even when the referenced function is empty. Fixes #2642 Patch by Steven Watanabe ........ r54617 | danieljames | 2009-07-03 23:20:52 +0100 (Fri, 03 Jul 2009) | 6 lines Add 'and later versions' to support info for GCC and Visual C++. Fixes #2847. I didn't explicitly specify the versions since no one's updating this list and it's highly unlikely that a future version will break this. The same could probably be done for the other compilers but I don't know them very well so I'm leaving them alone. ........ r54618 | danieljames | 2009-07-03 23:21:40 +0100 (Fri, 03 Jul 2009) | 4 lines Fix Boost.Function unit tests for C++0x. Fixes #3012 Based on a patch from Richard Webb. Changed a bit so that it also works for the Visual C++ 10 beta. ........ r54619 | danieljames | 2009-07-03 23:22:03 +0100 (Fri, 03 Jul 2009) | 3 lines Work around Visual C++ copy constructor bug. Fixes #2929. Based on the patch by Steven Watanabe. ........ [SVN r54824]
2009-07-08 23:23:52 +00:00
function <unsigned(double)> f2 = boost::lambda::bind(f1, false, _1);
2018-09-24 19:23:58 +03:00
BOOST_TEST_EQ( f2(2.0), 60 );
2018-09-24 19:23:58 +03:00
function <unsigned()> f3 = boost::lambda::bind(f2, 4.0);
BOOST_TEST_EQ( f3(), 120 );
2018-09-24 19:23:58 +03:00
return boost::report_errors();
}