[llvm] 08669fb - [NFC][STLExtras] Add make_first_range(), similar to existing make_second_range()

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 23:58:24 PDT 2020


Author: Roman Lebedev
Date: 2020-08-29T09:58:07+03:00
New Revision: 08669fbb439d139e2a66d2ae120a4b5be4fb4f28

URL: https://github.com/llvm/llvm-project/commit/08669fbb439d139e2a66d2ae120a4b5be4fb4f28
DIFF: https://github.com/llvm/llvm-project/commit/08669fbb439d139e2a66d2ae120a4b5be4fb4f28.diff

LOG: [NFC][STLExtras] Add make_first_range(), similar to existing make_second_range()

Having just one of the two seens weird.
I wanted to use it a few times, but it wasn't there.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/STLExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index b9b5e175f50e..4be016b795a0 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1237,6 +1237,15 @@ class indexed_accessor_range
   }
 };
 
+/// Given a container of pairs, return a range over the first elements.
+template <typename ContainerTy> auto make_first_range(ContainerTy &&c) {
+  return llvm::map_range(
+      std::forward<ContainerTy>(c),
+      [](decltype((*std::begin(c))) elt) -> decltype((elt.first)) {
+        return elt.first;
+      });
+}
+
 /// Given a container of pairs, return a range over the second elements.
 template <typename ContainerTy> auto make_second_range(ContainerTy &&c) {
   return llvm::map_range(


        


More information about the llvm-commits mailing list