[PATCH] D51525: [ADT] Add a new class OwnedOrBorrowed<T>

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 30 22:08:38 PDT 2018


Yep, I'll ask for the explanation - at least at Google there's been some
pushback on adding such a general purpose construct to the core library on
the premise that there's often/usually a better design. Equally I've
certainly seen some places it felt kind of right, for sure.

On Thu, Aug 30, 2018 at 9:07 PM Zachary Turner via Phabricator <
reviews at reviews.llvm.org> wrote:

> zturner created this revision.
> zturner added reviewers: rnk, chandlerc, timshen, dblaikie.
> Herald added subscribers: dexonsmith, mgorny.
>
> This might be controversial, but this class is essentially a
> `variant<unique_ptr<T>, T&>`.  I can go into great detail about why I need
> this, but it's a huge wall of text, so unless anyone asks, I'll spare you
> the details.  The idea, however, is simple.  You can construct this class
> with a `unique_ptr<T>` or with a `T&`.  In the former case, the class owns
> the object, in the latter it doesn't.  Aside from that, it's a simple smart
> pointer with all the overloaded operators, structors, and other
> functionality you'd expect.
>
>
> https://reviews.llvm.org/D51525
>
> Files:
>   llvm/include/llvm/ADT/OwnedOrBorrowed.h
>   llvm/unittests/ADT/CMakeLists.txt
>   llvm/unittests/ADT/OwnedOrBorrowedTest.cpp
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180830/64aabda6/attachment.html>


More information about the llvm-commits mailing list