[llvm] r216709 - Add conversion constructor to convert ArrayRef<T*> to ArrayRef<const T*>. Reviewed with Chandler and David Blaikie.

Craig Topper craig.topper at gmail.com
Fri Aug 29 08:18:59 PDT 2014


I'll try to put together a test case this weekend. As converting the rest
of the places that can take advantage of this.


On Fri, Aug 29, 2014 at 1:58 AM, Chandler Carruth <chandlerc at google.com>
wrote:

> Any reason not to add a simple unit test so compilation problems are
> caught earlier rather than later?
>
> Also, I think LLVM would prefer 'const T *' ... because, you know, its
> important. ;]
>
>
> On Thu, Aug 28, 2014 at 11:01 PM, Craig Topper <craig.topper at gmail.com>
> wrote:
>
>> Author: ctopper
>> Date: Fri Aug 29 01:01:43 2014
>> New Revision: 216709
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=216709&view=rev
>> Log:
>> Add conversion constructor to convert ArrayRef<T*> to ArrayRef<const T*>.
>> Reviewed with Chandler and David Blaikie.
>>
>> Modified:
>>     llvm/trunk/include/llvm/ADT/ArrayRef.h
>>
>> Modified: llvm/trunk/include/llvm/ADT/ArrayRef.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ArrayRef.h?rev=216709&r1=216708&r2=216709&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ADT/ArrayRef.h (original)
>> +++ llvm/trunk/include/llvm/ADT/ArrayRef.h Fri Aug 29 01:01:43 2014
>> @@ -104,6 +104,14 @@ namespace llvm {
>>        Length(Vec.size()) {}
>>  #endif
>>
>> +    /// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses
>> SFINAE to
>> +    /// ensure that only ArrayRefs of pointers can be converted.
>> +    template <typename U>
>> +    ArrayRef(const ArrayRef<U *> &A,
>> +             typename std::enable_if<
>> +                 std::is_convertible<U *const *, T const
>> *>::value>::type* = 0)
>> +      : Data(A.data()), Length(A.size()) {}
>> +
>>      /// @}
>>      /// @name Simple Operations
>>      /// @{
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>


-- 
~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140829/0ea23d2c/attachment.html>


More information about the llvm-commits mailing list