[llvm-commits] [Review request] arrayRef helper function for explicit ArrayRef<T> construction.
Chris Lattner
clattner at apple.com
Sun Jul 17 21:57:37 PDT 2011
On Jul 17, 2011, at 6:34 AM, Frits van Bommel wrote:
> I find the current way of explicitly constructing an ArrayRef, which
> requires specifying an explicit template parameter, to be a bit ugly.
>
> I figured it should be perfectly possible to auto-deduce that from the
> parameters. Since deducing it from the parameters doesn't work for
> constructors (you have to spell out what type you're constructing when
> calling one, after all) I introduced an 'arrayRef(...)' family of
> functions which fill a similar role for ArrayRef<> as std::make_pair()
> fills for std::pair<>: they return the right instantiation of
> ArrayRef<T> based on the types of the parameters.
> These can be found in the first attached patch (arrayRef.patch).
> They mostly mirror the ArrayRef constructors, with two exceptions:
> * There's no function mirroring the default constructor because it
> wouldn't have any parameters to deduce the right ArrayRef<T> from.
> * There's an explicit SmallVector<T> overload in addition to the
> SmallVectorImpl<T> overload. Without it, the single-element overload
> would try to create an ArrayRef<Smallvector<T> > because it's a better
> match according to the overloading rules. (And both overloads are used
> in the current tree, so neither is redundant)
>
> The second attached patch (arrayRef-use.patch) migrates LLVM and Clang
> to use the new arrayRef(...) functions where previously explicit
> non-default constructors were used.
> It's mostly mechanical with some manual reformatting.
Sounds great to me, but as Chandler suggested, please name the function 'makeArrayRef'.
-Chris
More information about the llvm-commits
mailing list