[llvm] 3677ee6 - Move from llvm::makeArrayRef to ArrayRef deduction guides

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 3 23:20:36 PST 2023


Author: serge-sans-paille
Date: 2023-01-04T08:18:29+01:00
New Revision: 3677ee65d192ae9a6a0b6037b7ec476f08c4918d

URL: https://github.com/llvm/llvm-project/commit/3677ee65d192ae9a6a0b6037b7ec476f08c4918d
DIFF: https://github.com/llvm/llvm-project/commit/3677ee65d192ae9a6a0b6037b7ec476f08c4918d.diff

LOG: Move from llvm::makeArrayRef to ArrayRef deduction guides

Since we're now requiring C++17, Let's get rid of makeXXX functions like
makeArrayRef, and use deduction guides instead.

This is a first step: Introduce the deduction guide. Following steps
will be a) use them and b) deprecate makeArrayRef.

Apart from codebase modernization, there isn't much benefit from that
move, but I can still mention that it would slightly (probably
negligibly) decrease the number of symbols / debug info, as deduction
guides don't generate new code.

Differential Revision: https://reviews.llvm.org/D140896

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 6f23de9a7136f..793fffa428641 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -466,9 +466,44 @@ namespace llvm {
     ~OwningArrayRef() { delete[] this->data(); }
   };
 
-  /// @name ArrayRef Convenience constructors
+  /// @name ArrayRef Deduction guides
   /// @{
+  /// Deduction guide to construct an ArrayRef from a single element.
+  template <typename T> ArrayRef(const T &OneElt) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a pointer and length
+  template <typename T> ArrayRef(const T *data, size_t length) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a range
+  template <typename T> ArrayRef(const T *data, const T *end) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a SmallVector
+  template <typename T> ArrayRef(const SmallVectorImpl<T> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a SmallVector
+  template <typename T, unsigned N>
+  ArrayRef(const SmallVector<T, N> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a std::vector
+  template <typename T> ArrayRef(const std::vector<T> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a std::array
+  template <typename T, std::size_t N>
+  ArrayRef(const std::array<T, N> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from an ArrayRef (no-op) (const)
+  template <typename T> ArrayRef(const ArrayRef<T> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from an ArrayRef (no-op)
+  template <typename T> ArrayRef(ArrayRef<T> &Vec) -> ArrayRef<T>;
+
+  /// Deduction guide to construct an ArrayRef from a C array.
+  template <typename T, size_t N> ArrayRef(const T (&Arr)[N]) -> ArrayRef<T>;
 
+  /// @}
+
+  /// @name ArrayRef Convenience constructors
+  /// @{
   /// Construct an ArrayRef from a single element.
   template<typename T>
   ArrayRef<T> makeArrayRef(const T &OneElt) {


        


More information about the llvm-commits mailing list