From 3677ee65d192ae9a6a0b6037b7ec476f08c4918d Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Wed, 4 Jan 2023 08:14:42 +0100 Subject: [PATCH] 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 --- llvm/include/llvm/ADT/ArrayRef.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h index 6f23de9..793fffa 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 ArrayRef(const T &OneElt) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a pointer and length + template ArrayRef(const T *data, size_t length) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a range + template ArrayRef(const T *data, const T *end) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a SmallVector + template ArrayRef(const SmallVectorImpl &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a SmallVector + template + ArrayRef(const SmallVector &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a std::vector + template ArrayRef(const std::vector &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a std::array + template + ArrayRef(const std::array &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from an ArrayRef (no-op) (const) + template ArrayRef(const ArrayRef &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from an ArrayRef (no-op) + template ArrayRef(ArrayRef &Vec) -> ArrayRef; + + /// Deduction guide to construct an ArrayRef from a C array. + template ArrayRef(const T (&Arr)[N]) -> ArrayRef; + /// @} + + /// @name ArrayRef Convenience constructors + /// @{ /// Construct an ArrayRef from a single element. template ArrayRef makeArrayRef(const T &OneElt) { -- 2.7.4