Hi,

I've been working awhile with smart pointers both from OpenSG and Boost, and found that the latter have a neat feature which is quite useful, namely that they can be implicitly converted to true/false. They also have solved this in a robust way. (There are some non-trivialities implementing this, which is why I assume this isn't available in OpenSG. I believe Boost returns a ptr-to-member or somesuch to get around this).

This allows for the quite common construct:

if(SmartPtr<T> p = f()){
  // do stuff
}

I like this as it is one less line than the usual:

SmartPtr<T> p = f();
if (p != nullfc) {
  // do stuff
}
// I don't want p in this scope

And as there are a lot of common usage where a field pointer might be null (fields not set & dynamic_cast) a nicer way to code this would be greatly appreciated. (I readily admint toa weakness for 'cute' code though.)

Unless it's been fixed or is planned (or if you've decided for other resons to not allow this), I could look into it and post some code. I believe it to be quite simple (copy-paste-edit from boost's smart_ptr :).

Best regards
/Marcus


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to