diff --git a/gsl/gsl_algorithm b/gsl/gsl_algorithm index 91271ce..3e6b353 100644 --- a/gsl/gsl_algorithm +++ b/gsl/gsl_algorithm @@ -83,7 +83,35 @@ auto find_if_not(const span& rng, UnaryPredicate p) - return details_algo::toIt(rng, ptr); } +// lower_bound +template +auto lower_bound(const span& rng, const T& value) -> decltype(rng.begin()) +{ + auto* ptr = std::lower_bound(rng.data(), rng.data() + rng.size(), value); + return details_algo::toIt(rng, ptr); +} +template +auto lower_bound(const span& rng, const T& value, Compare comp) -> decltype(rng.begin()) +{ + auto* ptr = std::lower_bound(rng.data(), rng.data() + rng.size(), value, comp); + return details_algo::toIt(rng, ptr); +} + +// upper_bound +template +auto upper_bound(const span& rng, const T& value) -> decltype(rng.begin()) +{ + auto* ptr = std::upper_bound(rng.data(), rng.data() + rng.size(), value); + return details_algo::toIt(rng, ptr); +} + +template +auto upper_bound(const span& rng, const T& value, Compare comp) -> decltype(rng.begin()) +{ + auto* ptr = std::upper_bound(rng.data(), rng.data() + rng.size(), value, comp); + return details_algo::toIt(rng, ptr); +} } // namespace gsl