diff --git a/include/boost/container/experimental/segmented_is_partitioned.hpp b/include/boost/container/experimental/segmented_is_partitioned.hpp index fe92b12..4f15047 100644 --- a/include/boost/container/experimental/segmented_is_partitioned.hpp +++ b/include/boost/container/experimental/segmented_is_partitioned.hpp @@ -27,6 +27,9 @@ namespace boost { namespace container { +//! Note: This version is suboptimal only supports bidirectional iterators, +//! as it relies on stable_partition_shift. +//! //! Returns \c true if all elements satisfying \c pred appear before //! all elements that do not, i.e. the range [first, last) is //! partitioned with respect to \c pred. diff --git a/include/boost/container/experimental/segmented_partition_point.hpp b/include/boost/container/experimental/segmented_partition_point.hpp index 2362340..210ce09 100644 --- a/include/boost/container/experimental/segmented_partition_point.hpp +++ b/include/boost/container/experimental/segmented_partition_point.hpp @@ -34,30 +34,35 @@ template SegIter segmented_partition_point_dispatch (SegIter first, SegIter last, Predicate pred, segmented_iterator_tag) { - typedef segmented_iterator_traits traits; - typename traits::segment_iterator scur = traits::segment(first); - typename traits::segment_iterator slast = traits::segment(last); - typename traits::local_iterator lcur; + typedef segmented_iterator_traits traits; + typedef typename traits::local_iterator local_iterator; + typedef typename traits::segment_iterator segment_iterator; + + segment_iterator scur = traits::segment(first); + segment_iterator slast = traits::segment(last); if(scur == slast) { - lcur = boost::container::segmented_partition_point(traits::local(first), traits::local(last), pred); + local_iterator lcur = boost::container::segmented_partition_point(traits::local(first), traits::local(last), pred); if(lcur != traits::local(last)) return traits::compose(scur, lcur); } else { - lcur = boost::container::segmented_partition_point(traits::local(first), traits::end(scur), pred); - if(lcur != traits::end(scur)) - return traits::compose(scur, lcur); - - for(++scur; scur != slast; ++scur) { - lcur = boost::container::segmented_partition_point(traits::begin(scur), traits::end(scur), pred); - if(lcur != traits::end(scur)) + { + local_iterator lcur = boost::container::segmented_partition_point(traits::local(first), traits::end(scur), pred); + if (lcur != traits::end(scur)) return traits::compose(scur, lcur); } - lcur = boost::container::segmented_partition_point(traits::begin(scur), traits::local(last), pred); - if(lcur != traits::local(last)) - return traits::compose(scur, lcur); + for(++scur; scur != slast; ++scur) { + local_iterator lcur = boost::container::segmented_partition_point(traits::begin(scur), traits::end(scur), pred); + if(lcur != traits::end(scur)) + return traits::compose(scur, lcur); + } + { + local_iterator lcur = boost::container::segmented_partition_point(traits::begin(scur), traits::local(last), pred); + if (lcur != traits::local(last)) + return traits::compose(scur, lcur); + } } return last; } @@ -76,6 +81,9 @@ segmented_partition_point_dispatch } // namespace detail_algo +//! Note: This version is suboptimal only supports bidirectional iterators, +//! as it relies on stable_partition_shift. +//! //! Finds the partition point in [first, last): the first element //! for which \c pred returns false. The range must be partitioned //! with respect to \c pred. diff --git a/include/boost/container/experimental/segmented_stable_partition.hpp b/include/boost/container/experimental/segmented_stable_partition.hpp index 7ab3024..44b9181 100644 --- a/include/boost/container/experimental/segmented_stable_partition.hpp +++ b/include/boost/container/experimental/segmented_stable_partition.hpp @@ -89,13 +89,17 @@ template OuterIter stable_partition_scan(SegIt first, SegIt last, OuterIter result, Composer composer, Pred& pred, segmented_iterator_tag) { - typedef segmented_iterator_traits traits; - typedef typename traits::local_iterator local_iterator; + typedef segmented_iterator_traits traits; + typedef typename traits::local_iterator local_iterator; + typedef typename traits::segment_iterator segment_iterator; typedef typename segmented_iterator_traits::is_segmented_iterator is_local_seg_t; + typedef sp_chained_composer inner_composer_t; - typename traits::segment_iterator scur = traits::segment(first); - typename traits::segment_iterator slast = traits::segment(last); - local_iterator lcur = traits::local(first); + + segment_iterator scur = traits::segment(first); + segment_iterator slast = traits::segment(last); + local_iterator lcur = traits::local(first); + if(scur == slast) { inner_composer_t inner(composer, scur); result = stable_partition_scan(lcur, traits::local(last), result, inner, pred, is_local_seg_t()); @@ -133,6 +137,9 @@ BidirIt segmented_stable_partition_dispatch (BidirIt first, BidirIt last, Pred p } // namespace detail_algo +//! Note: This version is suboptimal only supports bidirectional iterators, +//! as it relies on stable_partition_shift. +//! //! Reorders elements in [first, last) so that elements satisfying //! \c pred come before those that do not, preserving relative order //! within each group. Returns an iterator to the partition point.