diff options
author | Martin Schulze <teebaum@cvs.gnome.org> | 2003-08-23 23:12:28 +0000 |
---|---|---|
committer | Martin Schulze <teebaum@src.gnome.org> | 2003-08-23 23:12:28 +0000 |
commit | 1cbddabbf67309fbb33719ccf8a9ffee944e4636 (patch) | |
tree | f689089845b3c03d75f6f937bc51026b37dd9b6b /tests/test_bind.cc | |
parent | 7a00468c240875e0e215f8bd8451d4eb0d02d187 (diff) | |
download | sigc++-1cbddabbf67309fbb33719ccf8a9ffee944e4636.tar.gz |
- Remove unnecessary void specializations. In fact, only the one for
2003-08-24 Martin Schulze <teebaum@cvs.gnome.org>
* sigc++/adaptors[/lambda]/*.h.m4:
- Remove unnecessary void specializations. In fact, only the one
for sigc::functor::exception_catch<> is needed and I don't really
understand why. For the lambda stuff the void specializatoins are
just commented out at the moment.
- Make typeof() optional. Surprisingly, I got the lambda stuff working
without typeof()! The test suite doesn't catch all cases yet, so maybe
some thing are still not working.
TODO: Implement configure check.
* tests/test_bind.cc, tests/test_compose.cc tests/test_exception_catch.cc,
tests/test_hide.cc, tests/test_lambda.cc:
Only test multiple functor return types if typeof() is supported.
Diffstat (limited to 'tests/test_bind.cc')
-rw-r--r-- | tests/test_bind.cc | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/tests/test_bind.cc b/tests/test_bind.cc index b4bca5e..ec1204d 100644 --- a/tests/test_bind.cc +++ b/tests/test_bind.cc @@ -10,26 +10,36 @@ using namespace sigc::functor; using sigc::trackable; -struct foo +struct foo : public sigc::functor::functor_base { +#ifdef SIGC_CXX_TYPEOF + // if the compiler supports typeof(), result_type must only match the + // return type of the operator() overload with 1 argument (cannot be auto-detected in C++). + typedef bool result_type; bool operator()(int i) {std::cout << "foo(int "<<i<<")" << std::endl; return (i>0);} int operator()(int i,int j) {std::cout << "foo(int "<<i<<",int "<<j<<")" << std::endl; return i+j;} void operator()(int i,int j,int k) {std::cout << "foo(int "<<i<<",int "<<j<<", int "<<k<<")" << std::endl;} +#else + // choose a type that can hold all return values + typedef int result_type; + int operator()(int i) + {std::cout << "foo(int "<<i<<")" << std::endl; return (i>0);} + int operator()(int i,int j) + {std::cout << "foo(int "<<i<<",int "<<j<<")" << std::endl; return i+j;} + int operator()(int i,int j,int k) + {std::cout << "foo(int "<<i<<",int "<<j<<", int "<<k<<")" << std::endl; return 0;} +#endif }; - -namespace sigc { -namespace functor { - -// explicitly specify the return type of foo's operator() overload with no arguments -// (cannot be auto-detected): -SIGC_FUNCTOR_TRAIT(foo,bool) - -} /* namespace functor */ -} /* namespace sigc */ +struct foo_void : public sigc::functor::functor_base +{ + typedef void result_type; + void operator()(int i) + {std::cout << "foo_void(int "<<i<<")" << std::endl;} +}; int bar(int i,int j) @@ -69,13 +79,14 @@ int main() bind<1>(bind<1>(foo(),7),8)(); // void return - bind<1>(foo(),9,10)(11); + bind<1>(foo(),9,10)(11); // (only returns void if typeof() is supported) + bind<0>(foo_void(),12)(); // function pointer instead of functor - bind<1>(&bar,12,13)(); + bind<1>(&bar,13,14)(); // test return type of bind_functor::operator() overload with no arguments - std::cout << bind<0>(foo(),14)() << std::endl; + std::cout << bind<0>(foo(),15)() << std::endl; std::cout << bind<0>(&simple, true)() << std::endl; // test references |