[PATCH] D58886: [ADT] Add llvm::binary_search to STLExtras
Kristóf Umann via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 3 08:59:29 PST 2019
Szelethus created this revision.
Szelethus added reviewers: aaron.ballman, dblaikie.
Szelethus added a project: LLVM.
Herald added subscribers: llvm-commits, jdoerfert, gamesh411, kristina, dexonsmith, dkrupp.
Repository:
rL LLVM
https://reviews.llvm.org/D58886
Files:
include/llvm/ADT/STLExtras.h
Index: include/llvm/ADT/STLExtras.h
===================================================================
--- include/llvm/ADT/STLExtras.h
+++ include/llvm/ADT/STLExtras.h
@@ -1300,6 +1300,19 @@
-> decltype(adl_begin(Range)) {
return std::upper_bound(adl_begin(Range), adl_end(Range), I, C);
}
+
+/// Provide wrappers to std::binary_search which take ranges instead of having
+/// to pass begin/end explicitly.
+template <typename R, typename E>
+bool binary_search(R &&Range, const E &Element) {
+ return std::binary_search(adl_begin(Range), adl_end(Range), Element);
+}
+
+template <typename R, typename E, typename Compare>
+bool binary_search(R &&Range, const E &Element, Compare C) {
+ return std::binary_search(adl_begin(Range), adl_end(Range), Element, C);
+}
+
/// Wrapper function around std::equal to detect if all elements
/// in a container are same.
template <typename R>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58886.189087.patch
Type: text/x-patch
Size: 897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190303/ecae6bcb/attachment.bin>
More information about the llvm-commits
mailing list