STLExtras: Add some more algorithm wrappers
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 13 Sep 2018 00:02:03 +0000 (00:02 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 13 Sep 2018 00:02:03 +0000 (00:02 +0000)
llvm-svn: 342102

llvm/include/llvm/ADT/STLExtras.h

index 8b8a355..4c73a55 100644 (file)
@@ -977,6 +977,10 @@ inline void sort(IteratorTy Start, IteratorTy End) {
   std::sort(Start, End);
 }
 
+template <typename Container> inline void sort(Container &&C) {
+  llvm::sort(adl_begin(C), adl_end(C));
+}
+
 template <typename IteratorTy, typename Compare>
 inline void sort(IteratorTy Start, IteratorTy End, Compare Comp) {
 #ifdef EXPENSIVE_CHECKS
@@ -986,6 +990,11 @@ inline void sort(IteratorTy Start, IteratorTy End, Compare Comp) {
   std::sort(Start, End, Comp);
 }
 
+template <typename Container, typename Compare>
+inline void sort(Container &&C, Compare Comp) {
+  llvm::sort(adl_begin(C), adl_end(C), Comp);
+}
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <algorithm>
 //===----------------------------------------------------------------------===//
@@ -1137,6 +1146,11 @@ auto upper_bound(R &&Range, ForwardIt I) -> decltype(adl_begin(Range)) {
   return std::upper_bound(adl_begin(Range), adl_end(Range), I);
 }
 
+template <typename R, typename ForwardIt, typename Compare>
+auto upper_bound(R &&Range, ForwardIt I, Compare C)
+    -> decltype(adl_begin(Range)) {
+  return std::upper_bound(adl_begin(Range), adl_end(Range), I, C);
+}
 /// Wrapper function around std::equal to detect if all elements
 /// in a container are same.
 template <typename R>