Page MenuHomePhabricator

[ADT] Add is_splat overload accepting initializer_list

Authored by kuhar on Fri, Aug 5, 1:32 PM.



Allow for is_splat to be used inline, similar to is_contained, e.g.,

if (is_splat({type1, type2, type3, type4}))

which is much more concise and less typo-prone than an equivalent chain of equality comparisons.

My immediate motivation is to clean up some code in the SPIR-V dialect that currently needs to either construct a temporary container or use makeArrayRef before calling is_splat.

Diff Detail

Event Timeline

kuhar created this revision.Fri, Aug 5, 1:32 PM
Herald added a project: Restricted Project. · View Herald Transcript
kuhar requested review of this revision.Fri, Aug 5, 1:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Aug 5, 1:32 PM
dblaikie added inline comments.Fri, Aug 5, 4:08 PM

hmm, Values is already a valid range, so it's a bit awkward/unfortunate to make a new range from it.

could we make this add the template parameter explicitly?

return is_splat<std::initializer_list<T>>(std::move(Values));

(the move doesn't do much (since std::initializer_list is immutable, yeah?), but I think it's that or you have to make the parameter a reference type, to work with the universal reference stuff?)

kuhar updated this revision to Diff 450653.Sun, Aug 7, 10:55 AM
kuhar added inline comments.

This looked like an infinite recursion to me initially, but you are right, move does fix it. Thanks for the suggestion!

kuhar marked an inline comment as done.Sun, Aug 7, 10:56 AM
dblaikie accepted this revision.Sun, Aug 7, 11:02 AM

Looks good, thanks!

This revision is now accepted and ready to land.Sun, Aug 7, 11:02 AM
This revision was landed with ongoing or failed builds.Mon, Aug 8, 7:24 AM
This revision was automatically updated to reflect the committed changes.