
I thought about using a Null object but I think that would be too much of a burden. Given that the stub functions would need to be non-trivial in may cases because of the return types. And because my platform support cooperative multi threading not preemptive multi threading i can get away only locking when I call the function. I have my own non-boost smart pointers and function objects and i can call Func<>.isNull() on them and it does what I want. However I long for the convenience of bind. So I am left with a dilemma should I add more functionality to Func or add what I need to boost::function. Thanks On 12/13/06, Peter Dimov <pdimov@mmltd.net> wrote:
Theodore Witkamp wrote:
If you notice it's my_weak_ptr not boost::weak_ptr. Which can be used in this way due to the implementation of get_pointer for that type.
This is dangerous since you may be left with a dangling this if something invalidates the weak pointer while you're inside f, but you probably knew that. (This is the reason why boost::weak_ptr can't be used in this way.)
The "no exceptions" constraint makes it harder than it needs to be. In this situation I would probably use a null X object:
struct Xb { virtual void f() = 0; };
struct Xn: Xb { void f() {} // stub };
Xn nx;
struct X: Xb { void f(); // do real work };
Xb * lock( my_weak_ptr<Xb> px ) { return px? get_pointer( px ): &nx; }
int main() { my_shared_ptr<Xb> px( new X ); my_weak_ptr<Xb> wp( px );
function<void()> f = bind( &Xb::f, bind( lock, wp ) );
f();
px.reset();
f(); }
or something like that. Obviously untested. :-)
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Theodore Witkamp CTO RiffWare LLC 107 S Holliston Ave Apt 308 Pasadena, CA 91106 Mb. 626-372-0931