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

View file

@ -19,7 +19,7 @@ namespace sprout {
std::size_t n 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) : sprout::detail::is_heap_until_impl(first, last, comp, n + 1)
; ;
} }

View file

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

View file

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

View file

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

View file

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