@@ -35,8 +35,9 @@ namespace detail_algo {
3535// ////////////////////////////////////////////////////////////////////////////
3636// Bounded destination helper: copies from source count elements into
3737// [dst_first, dst_last), stopping when count reaches zero or destination
38- // is full. Advances first_out and count (by reference) so the caller
39- // knows how far we got.
38+ // is full. Returns segduo<SrcIter, DstIter> with the final positions of
39+ // both iterators. count is advanced by reference so the caller knows
40+ // how many elements remain.
4041// Recursively walks destination segments when dst is segmented.
4142//
4243// When dst_last is unreachable_sentinel_t the destination-full check
@@ -46,12 +47,10 @@ namespace detail_algo {
4647#if defined(BOOST_CONTAINER_SEGMENTED_LOOP_UNROLLING)
4748
4849template <class RASrcIter , class Size , class DstIter , class DstSent >
49- DstIter segmented_copy_n_dst_bounded
50- (RASrcIter& first_out , Size& count, DstIter dst_first, DstSent dst_last,
50+ segduo<RASrcIter, DstIter> segmented_copy_n_dst_bounded
51+ (RASrcIter first , Size& count, DstIter dst_first, DstSent dst_last,
5152 const non_segmented_iterator_tag &, const std::random_access_iterator_tag &)
5253{
53- RASrcIter first = first_out;
54-
5554 while (count >= Size (4 )) {
5655 if (dst_first == dst_last) goto out_path; *dst_first = *first; ++first; ++dst_first; --count;
5756 if (dst_first == dst_last) goto out_path; *dst_first = *first; ++first; ++dst_first; --count;
@@ -73,33 +72,29 @@ DstIter segmented_copy_n_dst_bounded
7372 break ;
7473 }
7574 out_path:
76- first_out = first;
77- return dst_first;
75+ return segduo<RASrcIter, DstIter>(first, dst_first);
7876}
7977
8078#endif // BOOST_CONTAINER_SEGMENTED_LOOP_UNROLLING
8179
8280template <class SrcIter , class Size , class DstIter , class DstSent , class DstTag , class SrcCat >
83- typename algo_enable_if_c<!DstTag::value, DstIter>::type
81+ typename algo_enable_if_c<!DstTag::value, segduo<SrcIter, DstIter> >::type
8482segmented_copy_n_dst_bounded
85- (SrcIter& first_out , Size& count, DstIter dst_first, DstSent dst_last, DstTag, SrcCat)
83+ (SrcIter first , Size& count, DstIter dst_first, DstSent dst_last, DstTag, SrcCat)
8684{
87- SrcIter first = first_out;
88-
8985 for (; count > 0 ; ++first, --count) {
9086 if (dst_first == dst_last)
9187 goto out_path;
9288 *dst_first = *first;
9389 ++dst_first;
9490 }
9591 out_path:
96- first_out = first;
97- return dst_first;
92+ return segduo<SrcIter, DstIter>(first, dst_first);
9893}
9994
10095template <class SrcIter , class Size , class SegDstIter , class SrcCat >
101- SegDstIter segmented_copy_n_dst_bounded
102- (SrcIter& first, Size& count, SegDstIter dst_first, SegDstIter dst_last,
96+ segduo<SrcIter, SegDstIter> segmented_copy_n_dst_bounded
97+ (SrcIter first, Size& count, SegDstIter dst_first, SegDstIter dst_last,
10398 segmented_iterator_tag, SrcCat)
10499{
105100 typedef segmented_iterator_traits<SegDstIter> dst_traits;
@@ -111,26 +106,28 @@ SegDstIter segmented_copy_n_dst_bounded
111106 const dst_segment_iterator slast = dst_traits::segment (dst_last);
112107
113108 if (sfirst == slast) {
114- dst_local_iterator r = (segmented_copy_n_dst_bounded)
109+ segduo<SrcIter, dst_local_iterator> r = (segmented_copy_n_dst_bounded)
115110 (first, count, dst_traits::local (dst_first), dst_traits::local (dst_last), dst_is_local_seg_t (), SrcCat ());
116- return dst_traits::compose (sfirst, r);
111+ return segduo<SrcIter, SegDstIter>(r. first , dst_traits::compose (sfirst, r. second ) );
117112 }
118113 else {
119- dst_local_iterator dst_local = (segmented_copy_n_dst_bounded)
114+ segduo<SrcIter, dst_local_iterator> r = (segmented_copy_n_dst_bounded)
120115 (first, count, dst_traits::local (dst_first), dst_traits::end (sfirst), dst_is_local_seg_t (), SrcCat ());
116+ first = r.first ;
121117 if (count == 0 )
122- return dst_traits::compose (sfirst, dst_local );
118+ return segduo<SrcIter, SegDstIter>(first, dst_traits::compose (sfirst, r. second ) );
123119
124120 for (++sfirst; sfirst != slast; ++sfirst) {
125- dst_local = (segmented_copy_n_dst_bounded)
121+ r = (segmented_copy_n_dst_bounded)
126122 (first, count, dst_traits::begin (sfirst), dst_traits::end (sfirst), dst_is_local_seg_t (), SrcCat ());
123+ first = r.first ;
127124 if (count == 0 )
128- return dst_traits::compose (sfirst, dst_local );
125+ return segduo<SrcIter, SegDstIter>(first, dst_traits::compose (sfirst, r. second ) );
129126 }
130127
131- dst_local = (segmented_copy_n_dst_bounded)
128+ r = (segmented_copy_n_dst_bounded)
132129 (first, count, dst_traits::begin (slast), dst_traits::local (dst_last), dst_is_local_seg_t (), SrcCat ());
133- return dst_traits::compose (sfirst, dst_local );
130+ return segduo<SrcIter, SegDstIter>(r. first , dst_traits::compose (sfirst, r. second ) );
134131 }
135132}
136133
@@ -146,7 +143,7 @@ BOOST_CONTAINER_FORCEINLINE DstIter segmented_copy_n_dst_dispatch
146143 const non_segmented_iterator_tag &, Cat)
147144{
148145 return (segmented_copy_n_dst_bounded)
149- (first, count, result, unreachable_sentinel_t (), non_segmented_iterator_tag (), Cat ());
146+ (first, count, result, unreachable_sentinel_t (), non_segmented_iterator_tag (), Cat ()). second ;
150147}
151148
152149template <class SrcIter , class Size , class SegDstIter , class Cat >
@@ -166,13 +163,16 @@ SegDstIter segmented_copy_n_dst_dispatch
166163 dst_local_iterator dst_local = dst_traits::local (result);
167164
168165 while (count > 0 ) {
169- dst_local_iterator dst_end = dst_traits::end (dst_seg);
170- dst_local = (segmented_copy_n_dst_bounded)
166+ const dst_local_iterator dst_end = dst_traits::end (dst_seg);
167+ const segduo<SrcIter, dst_local_iterator> r = (segmented_copy_n_dst_bounded)
171168 (first, count, dst_local, dst_end, dst_is_local_seg_t (), Cat ());
169+ first = r.first ;
172170 if (count > 0 ) {
173171 ++dst_seg;
174172 dst_local = dst_traits::begin (dst_seg);
175173 }
174+ else
175+ dst_local = r.second ;
176176 }
177177 return dst_traits::compose (dst_seg, dst_local);
178178}
0 commit comments