[PATCH] unique_ptr with ability to get a raw pointer after release.

Антон Ярцев anton.yartsev at gmail.com
Wed Sep 24 15:07:02 PDT 2014


> It also doesn't compose with other deleters, which is a little unfortunate.
All is needed to do to make an existing deleter work with unique_ptr_deferred_release is to inherit the deleter from a 'SwitchControlledDeleterBase' class ('Switch' class in the new patch).

> I'm wondering if this might be better approached by solving the more
> general problem of "conditional ownership" which has turned up in several
> places in LLVM and Clang. (ofter a T* and a boolean as members, the boolean
> indicating whether the T* is owning or non-owning)
In the current implementation I tried to realize the same idea with T* managed by an unique_ptr descendant and a boolean wrapped by the 'Switch' class. Now I tend towards a clearer and safer approach with T* and a boolean member. Just working on the new patch.

> But to help demonstrate the use of this API - could you include the example
> usage in this patch? (you mention a couple of code reviews where this came
> up & I can't quite swap all the context back in from there to remember
> exactly how this applies)
Added refactored TGParser.cpp to the patch. Please look at TGParser::ParseDef(), TGParser::InstantiateMulticlassDef() and TGParser::ParseSimpleValue().

http://reviews.llvm.org/D5443

Files:
  include/llvm/ADT/STLExtras.h
  lib/TableGen/TGParser.cpp
  unittests/ADT/CMakeLists.txt
  unittests/ADT/UniquePtrDeferredReleaseTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5443.14054.patch
Type: text/x-patch
Size: 12006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140924/3717bdef/attachment.bin>


More information about the llvm-commits mailing list