[algorithm] Add sort

This commit is contained in:
MikeGitb 2016-12-06 00:09:19 +01:00
parent 11b604f45c
commit 2221c56fc5

View File

@ -126,6 +126,32 @@ bool binary_search(span<SrcElementType, SrcExtent> rng, const T& value, Compare
return std::binary_search(rng.data(), rng.data() + rng.size(), value, comp); return std::binary_search(rng.data(), rng.data() + rng.size(), value, comp);
} }
// sort
template <class SrcElementType, std::ptrdiff_t SrcExtent>
void sort(span<SrcElementType, SrcExtent> rng)
{
std::sort(rng.data(), rng.data() + rng.size());
}
template <class SrcElementType, std::ptrdiff_t SrcExtent, class Compare>
void sort(span<SrcElementType, SrcExtent> rng, Compare comp)
{
std::sort(rng.data(), rng.data() + rng.size(), comp);
}
// stable sort
template <class SrcElementType, std::ptrdiff_t SrcExtent>
void stable_sort(span<SrcElementType, SrcExtent> rng)
{
std::stable_sort(rng.data(), rng.data() + rng.size());
}
template <class SrcElementType, std::ptrdiff_t SrcExtent, class Compare>
void stable_sort(span<SrcElementType, SrcExtent> rng, Compare comp)
{
std::stable_sort(rng.data(), rng.data() + rng.size(), comp);
}
} // namespace gsl } // namespace gsl
#ifdef _MSC_VER #ifdef _MSC_VER