On Aug 7, 2010, at 8:59 PM, Eric Seidel wrote:

> How about we add a Ptr<T> (or WeakPtr<T> or AutoNull<T> or whatever)

I worked on another project years ago where they had a template like this. The 
issue is with a variety of built-in data types, not specific to pointers. Any 
built-in data type such as a pointer, integer, or floating point number where 
it's not initialized by default can instead be initialized like this:

    , m_member()

That syntax will zero-initialize it. So if you have a template like this you 
can use it to take care of zero-initialization for any of these types. (For 
integers you can even go further and have the template specify the initial 
value which means you won’t have to repeat that value in multiple constructors.)

So much for the up-side of a template like this.

The downside is that the object does not have the type we might think it does. 
Even if we add assignment operators, conversion constructors and operators in 
both directions, it can still give us an unpleasant result in any context where 
overloading is involved, such as calling an overloaded function, and we might 
need an explicit function to get the actual scalar value, analogous to the get 
function we use on smart pointer.

I’m not sure if in practice this “initialize me” template will improve things 
much; remembering to use it is not all that much easier than remembering to 
initialize in constructors, but I don’t object strongly to the notion.

    -- Darin

_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to