<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:aestes&#64;apple.com" title="Andy Estes &lt;aestes&#64;apple.com&gt;"> <span class="fn">Andy Estes</span></a>
</span> changed
              <a class="bz_bug_link 
          bz_status_ASSIGNED "
   title="ASSIGNED - Add a variadic function template for creating new RefCounted objects and use it instead of the numerous per-class create() functions"
   href="https://bugs.webkit.org/show_bug.cgi?id=153617">bug 153617</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>ASSIGNED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Assignee</td>
           <td>webkit-unassigned&#64;lists.webkit.org
           </td>
           <td>aestes&#64;apple.com
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_ASSIGNED "
   title="ASSIGNED - Add a variadic function template for creating new RefCounted objects and use it instead of the numerous per-class create() functions"
   href="https://bugs.webkit.org/show_bug.cgi?id=153617#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_ASSIGNED "
   title="ASSIGNED - Add a variadic function template for creating new RefCounted objects and use it instead of the numerous per-class create() functions"
   href="https://bugs.webkit.org/show_bug.cgi?id=153617">bug 153617</a>
              from <span class="vcard"><a class="email" href="mailto:aestes&#64;apple.com" title="Andy Estes &lt;aestes&#64;apple.com&gt;"> <span class="fn">Andy Estes</span></a>
</span></b>
        <pre>Created <span class=""><a href="attachment.cgi?id=270876&amp;action=diff" name="attach_270876" title="Proof of concept">attachment 270876</a> <a href="attachment.cgi?id=270876&amp;action=edit" title="Proof of concept">[details]</a></span>
Proof of concept

I took a stab at this over the weekend. Here's a proof of concept with a few examples of how this would be adopted.

I ended up adding a static create function in WTF::Ref. It's not possible to do this correctly in RefCounted, since the RefCounted template is not always instantiated with the class that needs to be constructed. I like the way this ended up looking, since it plays really nicely with auto, e.g.:

    auto stopwatch = Ref&lt;Stopwatch&gt;::create();

There are a few things I don't love about this approach, though:

1. Classes that wish to use this function need to become friends with WTF::Ref so that it can call their private/protected constructors. Making constructors public would defeat the point of this exercise, so this is probably an acceptable trade-off.
2. Some classes have non-trivial create functions, where extra work needs to be done before or after calling constructors, and some classes even return a null RefPtr in some cases. Those classes should be ineligible for using Ref::create() (even though they might choose to use that function internally). I'd like to add some enforcement at compile time that prevents callers from using Ref::create if a per-class create function exists. It might make sense to add a trait to classes that wish to retain a custom create function that Ref::create can static_assert() on.

I'd welcome any feedback on how to make this better!</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>