<div dir="ltr">Yep, sounds good to me!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 11, 2021 at 5:40 AM Nathan James via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
How would people feel about including a factory function for creating<br>
IntrusiveRefCntPtr objects, akin to how std::make_unique and its<br>
variants work. For the most part this change would just be code sugar,<br>
however it will clean up definitions and remove the need to duplicate<br>
the type name. I can also see this as a stepping stone to gradually<br>
making the constructor `IntrusiveRefCntPtr(T*)` explicit, preventing<br>
some accidental conversions which can easily result in undefined<br>
behaviour if say the object lives on the stack or is already owned by<br>
another object.<br>
<br>
Take this which is an example seen often throught the code base,<br>
appologies in advance if email formatting is kaput.<br>
>IntrusiveRefCntPtr<OverlayFileSystem> OFS(<br>
>    new OverlayFileSystem(getRealFileSystem()));<br>
>IntrusiveRefCntPtr<InMemoryFileSystem> IMFS(new InMemoryFileSystem);<br>
>OFS->pushOverlay(IMFS);<br>
<br>
Using A factory these could be cleaned up a lot.<br>
>auto OFS = makeIntrusive<OverlayFileSystem>(getRealFileSystem());<br>
>auto IMFS = makeIntrusive<InMemoryFileSystem>();<br>
>OFS->pushOverlay(IMFS);<br>
<br>
This wouldn't be in violation of the rules on using `auto` for<br>
declarations as the type is spelt in the initialisation.<br>
<br>
Thanks for reading,<br>
Nathan James<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>