1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

sprout/algorithm/bogo_sort.hpp 追加

sprout/algorithm/bogo_sort_result.hpp 追加
sprout/algorithm/shuffle_result.hpp 追加
This commit is contained in:
bolero-MURAKAMI 2011-12-22 21:52:59 +09:00
parent e660c7261f
commit 01e458886a
14 changed files with 706 additions and 3 deletions

View file

@ -141,6 +141,36 @@ namespace sprout {
: sprout::detail::find(sprout::next(first), last, value)
;
}
//
// is_sorted_until
//
template<typename InputIterator>
SPROUT_CONSTEXPR InputIterator is_sorted_until(InputIterator first, InputIterator last) {
return first == last || sprout::next(first) == last ? last
: *sprout::next(first) < *first ? sprout::next(first)
: sprout::detail::is_sorted_until(sprout::next(first), last)
;
}
template<typename InputIterator, typename Compare>
SPROUT_CONSTEXPR InputIterator is_sorted_until(InputIterator first, InputIterator last, Compare comp) {
return first == last || sprout::next(first) == last ? last
: comp(*sprout::next(first), *first) != false ? sprout::next(first)
: sprout::detail::is_sorted_until(sprout::next(first), last)
;
}
//
// is_sorted
//
template<typename InputIterator>
SPROUT_CONSTEXPR bool is_sorted(InputIterator first, InputIterator last) {
return sprout::detail::is_sorted_until(first, last) == last;
}
template<typename InputIterator, typename Compare>
SPROUT_CONSTEXPR bool is_sorted(InputIterator first, InputIterator last, Compare comp) {
return sprout::detail::is_sorted_until(first, last, comp) == last;
}
} // namespace detail
} // namespace sprout