diff --git a/gsl/gsl_algorithm b/gsl/gsl_algorithm index 34c6c34..91271ce 100644 --- a/gsl/gsl_algorithm +++ b/gsl/gsl_algorithm @@ -52,6 +52,39 @@ void copy(span src, span std::copy_n(src.data(), src.size(), dest.data()); } +namespace details_algo +{ + template + auto toIt(const span& rng, const ElementType* ptr) -> decltype(rng.begin()) + { + return rng.begin() + (ptr - rng.data()); + } +} + +// find +template +auto find(const span& rng, const T& value) -> decltype(rng.begin()) +{ + auto* ptr = std::find(rng.data(), rng.data() + rng.size(), value); + return details_algo::toIt(rng, ptr); +} + +template +auto find_if(const span& rng, UnaryPredicate p) -> decltype(rng.begin()) +{ + auto* ptr = std::find_if(rng.data(), rng.data() + rng.size(), p); + return details_algo::toIt(rng, ptr); +} + +template +auto find_if_not(const span& rng, UnaryPredicate p) -> decltype(rng.begin()) +{ + auto* ptr = std::find_if_not(rng.data(), rng.data() + rng.size(), p); + return details_algo::toIt(rng, ptr); +} + + + } // namespace gsl #ifdef _MSC_VER