[llvm] r220231 - Add const version of OwningBinary::getBinary
Alexey Samsonov
vonosmas at gmail.com
Mon Oct 20 15:22:20 PDT 2014
On Mon, Oct 20, 2014 at 1:48 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Mon, Oct 20, 2014 at 1:32 PM, Alexey Samsonov <vonosmas at gmail.com>
> wrote:
>
>> Author: samsonov
>> Date: Mon Oct 20 15:32:47 2014
>> New Revision: 220231
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=220231&view=rev
>> Log:
>> Add const version of OwningBinary::getBinary
>>
>> Modified:
>> llvm/trunk/include/llvm/Object/Binary.h
>>
>> Modified: llvm/trunk/include/llvm/Object/Binary.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Binary.h?rev=220231&r1=220230&r2=220231&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Object/Binary.h (original)
>> +++ llvm/trunk/include/llvm/Object/Binary.h Mon Oct 20 15:32:47 2014
>> @@ -140,6 +140,7 @@ public:
>> OwningBinary<T> &operator=(OwningBinary<T> &&Other);
>>
>> std::unique_ptr<T> &getBinary();
>> + const std::unique_ptr<T> &getBinary() const;
>> std::unique_ptr<MemoryBuffer> &getBuffer();
>> };
>>
>> @@ -165,6 +166,11 @@ template <typename T> std::unique_ptr<T>
>> return Bin;
>> }
>>
>> +template <typename T>
>> +const std::unique_ptr<T> &OwningBinary<T>::getBinary() const {
>>
>
> Slightly curious thing to have a const version of, though it's probably
> the best thing for symmetry (since ownership can't be transferred, it could
> just return T* or, if it's always non-null, a T& - but it'd be weirdly
> asymmetric). What's it for?
>
In a new code, I wanted to fetch raw Binary* from OwningBinary<Binary>
(because I wanted to retain ownership in a callee). The straightfoward way
to do this was:
static Binary *getPtr(const OwningBinary &Bin) {
return Bin.getBinary().get();
}
OwningBinary OB = ....; // create owningBinary
// store OB somewhere
return getPtr(OB);
but the code fails to compile because of the missing overload I added here.
>
>> + return Bin;
>> +}
>> +
>> template <typename T>
>> std::unique_ptr<MemoryBuffer> &OwningBinary<T>::getBuffer() {
>> return Buf;
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
--
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141020/8dcf019c/attachment.html>
More information about the llvm-commits
mailing list