Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-04-09 16:51:13


1) I tried it with CodeWarrior 6.1 on the Mac and it seemed to work
without any problems. The only change I had to make was to make the
functions in the test file static.

2) I think there should be a few more tests. Something like the following:
static int sum_ints(int x, int y) { return x+y; }
static int sub_ints(int x = 0, int y = 0, int z = 0) { return x-y-z; }
static std::string identity(const std::string& s) { return s; }

   // compatible types
   any_function<int, short, short> sum(sum_ints);
   assert(sum(2, 3) == 5);

   any_function<std::string, char*> ident(identity);
   assert(ident("foo") == "foo");

   // default arguments
   any_function<int, int, int> sub(sub_ints);
   assert(sub(10, 2) == 8);

   any_function<int> sub2(sub_ints);
   assert(sub2() == 0);

   // cases which should fail to compile
// assert(sub(10) == 10);
// assert(sub(1, 2, 3, 4) == 10);

3) It may be desirable to be able to assign a function that returns a
result to an any_function that returns void.

4) Pointing an any_function at a member function is going to be an
awfully common operation. IMO this is common enough that it's worth
adding another ctor: ie "any_function(this, &MyObject::Method)"
instead of "any_function(bind(this, &MyObject::Method))".

5) I agree with Peter that boost::function is a better name.

6) Trying to invoke an empty function seems like a precondition
violation to me. Asserting instead of throwing seems preferable.

9) The void* conversion operator allows for comparisons. This sounds
OK to me, but the current implementation won't produce meaningful
results.

10) It's good that you're trying to make any_function's behave like
normal function pointers, but I think the int assignment operator
carries this to far.

   -- Jesse


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk