2008/11/8 Robert Osfield <[EMAIL PROTECTED]>:
> Hi Poitr,
>
> Why do you use a typedef in this context? Which not just define a
> operator T* const()?
>
> Also the valid() check is redundant.
>
> Robert.
Hi Robert,
Please notice that following code doesn't add conversion to T*
it adds conversion to member pointer of class ref_ptr<T> happends to
be of type T*.
typedef T* ref_ptr<T>::*unspecified_type_bool;
//should be read :
unspecifed_type_bool is name of pointer to member of ref_ptr<T> of type T*.
so type unspecified_type_bool can contain address of any member of
ref_ptr which is of type T*.
I could be address of any arbitrary member of ref_ptr<> or infact even
member function pointer.
if we had member field 'XYZ _dummy'; it could be:
typedef XYZ ref_ptr::*unspecified_type_bool;
I don't want to introduce implicit conversion ref_ptr<T> to T*
so code like:
class T;
void foo (T*) {}
void bar ()
{
ref_ptr<T> ptr;
foo (ptr); //illegal no conversion to T* from pointer to some member
if (!! ptr) {}// still legal, will call operator! () which is
redundant infact, but i left it alone for
OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION case
}
works as it did without OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION defined;
but now following becomes legal:
if (ptr) {} // woot !
Check valid() is needed since address of member _ptr is always
positive for ref_ptr somehere in memory, ofcourse.
Whole technique I used is 'safe bool idiom',
described in few textbooks (do not remember which, but can check that
after weekend).
Describtion online found here (and many other places):
http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool
For sure better then I did ;-)
I dont want to use member function pointer like showed there, since it
is less effective than pointer to member. For more information about
this issue, please see
http://lists.boost.org/Archives/boost/2003/09/52856.php
Probably I should have reference to this resources in code before.
Hope this explains bit, those few lines code I have added :)
Cheers, Piotr
> On Fri, Nov 7, 2008 at 9:35 PM, Piotr Rak <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Attached contains small, yet useful addition:
>> bool conversion for ref_ptr, when no implicit conversion to T* is used.
>> Was surprised, it wasn't there already!
>>
>> Cheers,
>> Piotr
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org