mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
[algorithm] Add lower/upper bound
This commit is contained in:
parent
8d7a49cfea
commit
b3a21d1173
@ -83,7 +83,35 @@ auto find_if_not(const span<SrcElementType, SrcExtent>& rng, UnaryPredicate p) -
|
||||
return details_algo::toIt(rng, ptr);
|
||||
}
|
||||
|
||||
// lower_bound
|
||||
template <class SrcElementType, std::ptrdiff_t SrcExtent, class T>
|
||||
auto lower_bound(const span<SrcElementType, SrcExtent>& 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 <class SrcElementType, std::ptrdiff_t SrcExtent, class T, class Compare>
|
||||
auto lower_bound(const span<SrcElementType, SrcExtent>& 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 <class SrcElementType, std::ptrdiff_t SrcExtent, class T>
|
||||
auto upper_bound(const span<SrcElementType, SrcExtent>& 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 <class SrcElementType, std::ptrdiff_t SrcExtent, class T, class Compare>
|
||||
auto upper_bound(const span<SrcElementType, SrcExtent>& 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user