- Added sig member template support for Boost.Lambda, with testcase (Michael Hohmuth)

- Removed the assignment-to-zero attempt

- Added bad_function_call exception (using boost::throw_exception)


[SVN r16102]
This commit is contained in:
Douglas Gregor
2002-11-04 18:19:01 +00:00
parent 9a09d9e044
commit 17ded4b8bf
6 changed files with 148 additions and 80 deletions

View File

@ -76,7 +76,7 @@ test_zero_args()
// clear() method
v1.clear();
BOOST_TEST(v1.empty());
BOOST_TEST(v1 == 0);
// Assignment to an empty function
v1 = three;

View File

@ -20,6 +20,7 @@
#include <functional>
#include <cassert>
#include <string>
#include <utility>
using namespace boost;
using namespace std;
@ -98,7 +99,7 @@ test_zero_args()
BOOST_TEST(global_int == 5);
// clear
v1 = 0;
v1.clear();
BOOST_TEST(0 == v1);
// Assignment to an empty function from a free function
@ -696,6 +697,43 @@ static void test_allocator()
#endif // ndef BOOST_NO_STD_ALLOCATOR
}
static void test_exception()
{
boost::function<int (int, int)> f;
try {
f(5, 4);
BOOST_TEST(false);
}
catch(boost::bad_function_call) {
// okay
}
}
typedef boost::function< void * (void * reader) > reader_type;
typedef std::pair<int, reader_type> mapped_type;
static void test_implicit()
{
mapped_type m;
m = mapped_type();
}
static void test_call_obj(boost::function<int (int, int)> f)
{
assert(!f.empty());
}
static void test_call_cref(const boost::function<int (int, int)>& f)
{
assert(!f.empty());
}
static void test_call()
{
test_call_obj(std::plus<int>());
test_call_cref(std::plus<int>());
}
int test_main(int, char* [])
{
test_zero_args();
@ -705,6 +743,9 @@ int test_main(int, char* [])
test_member_functions();
test_ref();
test_allocator();
test_exception();
test_implicit();
test_call();
return 0;
}

29
test/lambda_test.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#include <cstdlib>
#include <boost/test/test_tools.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/function.hpp>
using namespace std;
using namespace boost;
using namespace boost::lambda;
static unsigned
func_impl(int arg1, bool arg2, double arg3)
{
return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
}
int test_main(int, char*[])
{
function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
function <unsigned(double)> f2 = bind(f1, false, _1);
function <unsigned()> f3 = bind(f2, 4.0);
unsigned result = f3();
return 0;
}