fix non-modidying operation algorithm iteration

This commit is contained in:
bolero-MURAKAMI 2012-04-03 21:58:23 +09:00
parent db20f64991
commit cf593ffeff
7 changed files with 37 additions and 27 deletions

View file

@ -44,7 +44,7 @@ namespace sprout {
//
template<typename T, std::size_t N>
SPROUT_CONSTEXPR typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator cbegin(sscrisk::cel::array<T, N> const& cont) {
return sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator(cont, 0);
return typename sprout::container_traits<sscrisk::cel::array<T, N> >::const_iterator(cont, 0);
}
//

View file

@ -13,10 +13,10 @@ namespace sprout {
SPROUT_CONSTEXPR bool binary_search(ForwardIterator first, ForwardIterator last, T const& value) {
return first == last ? false
: sprout::next(first) == last ? !(*first < value) && !(value < *first) ? true : false
: *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2) < value
? sprout::binary_search(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value)
: value < *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last)) / 2
? sprout::binary_search(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value)
: *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2) < value
? sprout::binary_search(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value)
: value < *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last)) / 2
? sprout::binary_search(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
: true
;
}
@ -25,10 +25,10 @@ namespace sprout {
SPROUT_CONSTEXPR bool binary_search(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) {
return first == last ? false
: sprout::next(first) == last ? !comp(*first, value) && !comp(value, *first) ? true : false
: comp(*(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
? sprout::binary_search(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value)
: comp(value, *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last)) / 2)
? sprout::binary_search(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value)
: comp(*sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
? sprout::binary_search(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value)
: comp(value, *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last)) / 2)
? sprout::binary_search(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
: true
;
}

View file

@ -19,7 +19,7 @@ namespace sprout {
std::size_t n
)
{
return first + n == last || !comp(first[n], first[(n - 1) / 2]) ? first + n
return sprout::next(first, n) == last || !comp(first[n], first[(n - 1) / 2]) ? sprout::next(first, n)
: sprout::detail::is_heap_until_impl(first, last, comp, n + 1)
;
}

View file

@ -22,7 +22,7 @@ namespace sprout {
{
return first1_ == last1 ? true
: sprout::count(first1, last1, *first1_)
== sprout::count(first2, first2 + NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1), *first1_)
== sprout::count(first2, sprout::next(first2, NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1)), *first1_)
&& sprout::detail::is_permutation_impl(first1, last1, first2, sprout::next(first1_))
? true
: false
@ -40,7 +40,7 @@ namespace sprout {
{
return first1_ == last1 ? true
: sprout::count_if(first1, last1, NS_SSCRISK_CEL_OR_SPROUT::bind2nd(pred, *first1_))
== sprout::count_if(first2, first2 + NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1), NS_SSCRISK_CEL_OR_SPROUT::bind2nd(pred, *first1_))
== sprout::count_if(first2, sprout::next(first2, NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1)), NS_SSCRISK_CEL_OR_SPROUT::bind2nd(pred, *first1_))
&& sprout::detail::is_permutation_impl(first1, last1, first2, sprout::next(first1_), pred)
? true
: false

View file

@ -13,9 +13,9 @@ namespace sprout {
SPROUT_CONSTEXPR ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, T const& value) {
return first == last ? last
: sprout::next(first) == last ? *first < value ? last : first
: *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2) < value
? sprout::lower_bound(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value)
: sprout::lower_bound(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value)
: *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2) < value
? sprout::lower_bound(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value)
: sprout::lower_bound(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
;
}
@ -23,9 +23,9 @@ namespace sprout {
SPROUT_CONSTEXPR ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) {
return first == last ? last
: sprout::next(first) == last ? comp(*first, value) ? last : first
: comp(*(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
? sprout::lower_bound(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value, comp)
: sprout::lower_bound(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value, comp)
: comp(*sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
? sprout::lower_bound(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value, comp)
: sprout::lower_bound(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value, comp)
;
}
} // namespace sprout

View file

@ -12,8 +12,18 @@ namespace sprout {
template<typename ForwardIterator, typename Predicate>
SPROUT_CONSTEXPR ForwardIterator partition_point_impl(ForwardIterator first, ForwardIterator last, Predicate pred, ForwardIterator mid) {
return mid == last ? mid
: pred(*mid) ? sprout::detail::partition_point_impl(mid + 1, last, pred, mid + 1 + NS_SSCRISK_CEL_OR_SPROUT::distance(mid + 1, last) / 2)
: sprout::detail::partition_point_impl(first, mid, pred, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, mid) / 2)
: pred(*mid) ? sprout::detail::partition_point_impl(
sprout::next(mid),
last,
pred,
sprout::next(mid, 1 + NS_SSCRISK_CEL_OR_SPROUT::distance(sprout::next(mid), last) / 2)
)
: sprout::detail::partition_point_impl(
first,
mid,
pred,
sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, mid) / 2)
)
;
}
} // namespace detail
@ -21,7 +31,7 @@ namespace sprout {
// 25.3.13 Partitions
template<typename ForwardIterator, typename Predicate>
SPROUT_CONSTEXPR ForwardIterator partition_point(ForwardIterator first, ForwardIterator last, Predicate pred) {
return sprout::detail::partition_point_impl(first, last, pred, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2);
return sprout::detail::partition_point_impl(first, last, pred, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2));
}
} // namespace sprout

View file

@ -13,9 +13,9 @@ namespace sprout {
SPROUT_CONSTEXPR ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, T const& value) {
return first == last ? last
: sprout::next(first) == last ? !(value < *first) ? last : first
: !(value < *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2))
? upper_bound(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value)
: sprout::upper_bound(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value)
: !(value < *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2))
? upper_bound(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value)
: sprout::upper_bound(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value)
;
}
@ -23,9 +23,9 @@ namespace sprout {
SPROUT_CONSTEXPR ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, T const& value, Compare comp) {
return first == last ? last
: sprout::next(first) == last ? !comp(value, *first) ? last : first
: !comp(value, *(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2))
? sprout::upper_bound(first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, last, value, comp)
: sprout::upper_bound(first, first + NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2, value, comp)
: !comp(value, *sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2))
? sprout::upper_bound(sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), last, value, comp)
: sprout::upper_bound(first, sprout::next(first, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2), value, comp)
;
}
} // namespace sprout