From 11b604f45c3511571bc9190b67d1ef6d4aac0a17 Mon Sep 17 00:00:00 2001 From: MikeGitb Date: Tue, 6 Dec 2016 00:08:17 +0100 Subject: [PATCH] [algorithm] Add binary_search --- gsl/gsl_algorithm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gsl/gsl_algorithm b/gsl/gsl_algorithm index 3e6b353..c77e258 100644 --- a/gsl/gsl_algorithm +++ b/gsl/gsl_algorithm @@ -113,6 +113,19 @@ auto upper_bound(const span& rng, const T& value, Com return details_algo::toIt(rng, ptr); } +// binary_search +template +bool binary_search(span rng, const T& value) +{ + return std::binary_search(rng.data(), rng.data() + rng.size(), value); +} + +template +bool binary_search(span rng, const T& value, Compare comp) +{ + return std::binary_search(rng.data(), rng.data() + rng.size(), value, comp); +} + } // namespace gsl #ifdef _MSC_VER