[llvm-commits] [Review request] arrayRef helper function for explicit ArrayRef<T> construction.

Frits van Bommel fvbommel at gmail.com
Sun Jul 17 06:34:55 PDT 2011


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.

Are these okay to commit?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arrayRef.patch
Type: application/octet-stream
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110717/349414a6/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: arrayRef-use.patch
Type: application/octet-stream
Size: 15460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110717/349414a6/attachment-0001.obj>


More information about the llvm-commits mailing list