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

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 09:52:43 PDT 2018


zturner abandoned this revision.
zturner added a comment.

I can just abandon it.  It's no big deal really, because I can work around it in my project with like a few lines of code:

  struct Foo {
    Foo(std::unique_ptr<Bar> B) : Borrowed(B.get()), Owned(std::move(B)) {}
    Foo(Bar &B) : Borrowed(&B) {}
    Bar *Borrowed;
    std::unique_ptr<Bar> Owned;
  };

Another idea to fix it "for real" is to use a `shared_ptr<>`, and then in my cache instead of storing `unique_ptr` store `shared_ptr`, so it's properly ref-counted.  Yet another way would be in the borrowed case to construct the `shared_ptr<>` with a custom deleter that does nothing.  So there are several approaches.  I mainly just wanted to throw this out there in case it was like "yea, even though it's lame we've needed this enough times that we might as well generalize it".  But if we're not there, I'll just abandon it.


https://reviews.llvm.org/D51525





More information about the llvm-commits mailing list