The following pattern is common in the llvm codebase, as well as in downstream projects:
llvm::to_vector(llvm::map_range(container, lambda))
This patch introduces a shortcut for this called map_to_vector.
This template depends on both llvm/ADT/SmallVector.h and llvm/ADT/STLExtras.h, and since these are both relatively large and do not depend on each other, the map_to_vector helper is placed in a new header under llvm/ADT/SmallVectorExtras.h. I am happy to change this if reviewers can suggest a better location.
Only a handful of use cases have been updated to use the new helper, but I'm happy to update across the codebase (either in this patch, or in subsequent diffs) if this patch is accepted.
I'd expect this to optionally accept small size, just like to_vector<N>(...) does. Is there a specific reason why only the default size is allowed?
Also, do you plan on adding map_to_vector_of? IIRC to_vector_of was required for some common mlir functions like DenseElementAttribute::getValues<T>()