[PATCH] D95611: [ADT][NFC] Add extra typedefs to `ArrayRef` and `MutableArrayRef`

Vladislav Vinogradov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 28 06:05:59 PST 2021


vinograd47 created this revision.
vinograd47 added a reviewer: lattner.
Herald added a subscriber: dexonsmith.
vinograd47 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- `value_type`
- `pointer`
- `const_pointer`
- `reference`
- `const_reference`
- `const_reverse_iterator`
- `size_type`
- `difference_type`

It makes `ArrayRef` and `MutableArrayRef` types fully compliant with STL Container concept.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95611

Files:
  llvm/include/llvm/ADT/ArrayRef.h


Index: llvm/include/llvm/ADT/ArrayRef.h
===================================================================
--- llvm/include/llvm/ADT/ArrayRef.h
+++ llvm/include/llvm/ADT/ArrayRef.h
@@ -40,10 +40,17 @@
   template<typename T>
   class LLVM_GSL_POINTER LLVM_NODISCARD ArrayRef {
   public:
-    using iterator = const T *;
-    using const_iterator = const T *;
-    using size_type = size_t;
+    using value_type = const T;
+    using pointer = value_type *;
+    using const_pointer = const value_type *;
+    using reference = value_type &;
+    using const_reference = const value_type &;
+    using iterator = pointer;
+    using const_iterator = const_pointer;
     using reverse_iterator = std::reverse_iterator<iterator>;
+    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+    using size_type = std::size_t;
+    using difference_type = std::ptrdiff_t;
 
   private:
     /// The start of the array, in an external buffer.
@@ -297,8 +304,17 @@
   template<typename T>
   class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
   public:
-    using iterator = T *;
+    using value_type = T;
+    using pointer = value_type *;
+    using const_pointer = const value_type *;
+    using reference = value_type &;
+    using const_reference = const value_type &;
+    using iterator = pointer;
+    using const_iterator = const_pointer;
     using reverse_iterator = std::reverse_iterator<iterator>;
+    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+    using size_type = std::size_t;
+    using difference_type = std::ptrdiff_t;
 
     /// Construct an empty MutableArrayRef.
     /*implicit*/ MutableArrayRef() = default;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95611.319847.patch
Type: text/x-patch
Size: 1684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210128/113c4c79/attachment.bin>


More information about the llvm-commits mailing list