2
* Copyright 2008-2011 NVIDIA Corporation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
19
* \brief Defines the interface to various
25
#include <thrust/detail/config.h>
31
/*! \addtogroup sorting
36
/*! \p sort sorts the elements in <tt>[first, last)</tt> into
37
* ascending order, meaning that if \c i and \c j are any two valid
38
* iterators in <tt>[first, last)</tt> such that \c i precedes \c j,
39
* then \c *j is not less than \c *i. Note: \c sort is not guaranteed
40
* to be stable. That is, suppose that \c *i and \c *j are equivalent:
41
* neither one is less than the other. It is not guaranteed that the
42
* relative order of these two elements will be preserved by \p sort.
44
* This version of \p sort compares objects using \c operator<.
46
* \param first The beginning of the sequence.
47
* \param last The end of the sequence.
49
* \tparam RandomAccessIterator is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
50
* \p RandomAccessIterator is mutable,
51
* and \p RandomAccessIterator's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>,
52
* and the ordering relation on \p RandomAccessIterator's \c value_type is a <em>strict weak ordering</em>, as defined in the
53
* <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a> requirements.
55
* The following code snippet demonstrates how to use \p sort to sort
56
* a sequence of integers.
59
* #include <thrust/sort.h>
62
* int A[N] = {1, 4, 2, 8, 5, 7};
63
* thrust::sort(A, A + N);
64
* // A is now {1, 2, 4, 5, 7, 8}
67
* \see http://www.sgi.com/tech/stl/sort.html
71
template<typename RandomAccessIterator>
72
void sort(RandomAccessIterator first,
73
RandomAccessIterator last);
75
/*! \p sort sorts the elements in <tt>[first, last)</tt> into
76
* ascending order, meaning that if \c i and \c j are any two valid
77
* iterators in <tt>[first, last)</tt> such that \c i precedes \c j,
78
* then \c *j is not less than \c *i. Note: \c sort is not guaranteed
79
* to be stable. That is, suppose that \c *i and \c *j are equivalent:
80
* neither one is less than the other. It is not guaranteed that the
81
* relative order of these two elements will be preserved by \p sort.
83
* This version of \p sort compares objects using a function object
86
* \param first The beginning of the sequence.
87
* \param last The end of the sequence.
88
* \param comp Comparison operator.
90
* \tparam RandomAccessIterator is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
91
* \p RandomAccessIterator is mutable,
92
* and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's
93
* \c first_argument_type and \c second_argument_type.
94
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
96
* The following code demonstrates how to sort integers in descending order
97
* using the greater<int> comparison operator.
100
* #include <thrust/sort.h>
101
* #include <thrust/functional.h>
104
* int A[N] = {1, 4, 2, 8, 5, 7};
105
* thrust::sort(A, A + N, thrust::greater<int>());
106
* // A is now {8, 7, 5, 4, 2, 1};
109
* \see http://www.sgi.com/tech/stl/sort.html
110
* \see \p stable_sort
111
* \see \p sort_by_key
113
template<typename RandomAccessIterator,
114
typename StrictWeakOrdering>
115
void sort(RandomAccessIterator first,
116
RandomAccessIterator last,
117
StrictWeakOrdering comp);
119
/*! \p stable_sort is much like \c sort: it sorts the elements in
120
* <tt>[first, last)</tt> into ascending order, meaning that if \c i
121
* and \c j are any two valid iterators in <tt>[first, last)</tt> such
122
* that \c i precedes \c j, then \c *j is not less than \c *i.
124
* As the name suggests, \p stable_sort is stable: it preserves the
125
* relative ordering of equivalent elements. That is, if \c x and \c y
126
* are elements in <tt>[first, last)</tt> such that \c x precedes \c y,
127
* and if the two elements are equivalent (neither <tt>x < y</tt> nor
128
* <tt>y < x</tt>) then a postcondition of \p stable_sort is that \c x
129
* still precedes \c y.
131
* This version of \p stable_sort compares objects using \c operator<.
133
* \param first The beginning of the sequence.
134
* \param last The end of the sequence.
136
* \tparam RandomAccessIterator is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
137
* \p RandomAccessIterator is mutable,
138
* and \p RandomAccessIterator's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>,
139
* and the ordering relation on \p RandomAccessIterator's \c value_type is a <em>strict weak ordering</em>, as defined in the
140
* <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a> requirements.
142
* The following code snippet demonstrates how to use \p sort to sort
143
* a sequence of integers.
146
* #include <thrust/sort.h>
149
* int A[N] = {1, 4, 2, 8, 5, 7};
150
* thrust::stable_sort(A, A + N);
151
* // A is now {1, 2, 4, 5, 7, 8}
154
* \see http://www.sgi.com/tech/stl/stable_sort.html
156
* \see \p stable_sort_by_key
158
template<typename RandomAccessIterator>
159
void stable_sort(RandomAccessIterator first,
160
RandomAccessIterator last);
162
/*! \p stable_sort is much like \c sort: it sorts the elements in
163
* <tt>[first, last)</tt> into ascending order, meaning that if \c i
164
* and \c j are any two valid iterators in <tt>[first, last)</tt> such
165
* that \c i precedes \c j, then \c *j is not less than \c *i.
167
* As the name suggests, \p stable_sort is stable: it preserves the
168
* relative ordering of equivalent elements. That is, if \c x and \c y
169
* are elements in <tt>[first, last)</tt> such that \c x precedes \c y,
170
* and if the two elements are equivalent (neither <tt>x < y</tt> nor
171
* <tt>y < x</tt>) then a postcondition of \p stable_sort is that \c x
172
* still precedes \c y.
174
* This version of \p stable_sort compares objects using a function object
177
* \param first The beginning of the sequence.
178
* \param last The end of the sequence.
179
* \param comp Comparison operator.
181
* \tparam RandomAccessIterator is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
182
* \p RandomAccessIterator is mutable,
183
* and \p RandomAccessIterator's \c value_type is convertible to \p StrictWeakOrdering's
184
* \c first_argument_type and \c second_argument_type.
185
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
187
* The following code demonstrates how to sort integers in descending order
188
* using the greater<int> comparison operator.
191
* #include <thrust/sort.h>
192
* #include <thrust/functional.h>
195
* int A[N] = {1, 4, 2, 8, 5, 7};
196
* thrust::sort(A, A + N, thrust::greater<int>());
197
* // A is now {8, 7, 5, 4, 2, 1};
200
* \see http://www.sgi.com/tech/stl/stable_sort.html
202
* \see \p stable_sort_by_key
204
template<typename RandomAccessIterator,
205
typename StrictWeakOrdering>
206
void stable_sort(RandomAccessIterator first,
207
RandomAccessIterator last,
208
StrictWeakOrdering comp);
214
/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the
215
* elements in <tt>[keys_first, keys_last)</tt> and <tt>[values_first,
216
* values_first + (keys_last - keys_first))</tt> into ascending key order,
217
* meaning that if \c i and \c j are any two valid iterators in <tt>[keys_first,
218
* keys_last)</tt> such that \c i precedes \c j, and \c p and \c q are iterators
219
* in <tt>[values_first, values_first + (keys_last - keys_first))</tt>
220
* corresponding to \c i and \c j respectively, then \c *j is not less than
223
* Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that
224
* \c *i and \c *j are equivalent: neither one is less than the other. It is not
225
* guaranteed that the relative order of these two keys or the relative
226
* order of their corresponding values will be preserved by \p sort_by_key.
228
* This version of \p sort_by_key compares key objects using \c operator<.
230
* \param keys_first The beginning of the key sequence.
231
* \param keys_last The end of the key sequence.
232
* \param values_first The beginning of the value sequence.
234
* \tparam RandomAccessIterator1 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
235
* \p RandomAccessIterator1 is mutable,
236
* and \p RandomAccessIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>,
237
* and the ordering relation on \p RandomAccessIterator1's \c value_type is a <em>strict weak ordering</em>, as defined in the
238
* <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a> requirements.
239
* \tparam RandomAccessIterator2 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.hml">Random Access Iterator</a>,
240
* and \p RandomAccessIterator2 is mutable.
242
* The following code snippet demonstrates how to use \p sort_by_key to sort
243
* an array of character values using integers as sorting keys.
246
* #include <thrust/sort.h>
249
* int keys[N] = { 1, 4, 2, 8, 5, 7};
250
* char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'};
251
* thrust::sort_by_key(keys, keys + N, values);
252
* // keys is now { 1, 2, 4, 5, 7, 8}
253
* // values is now {'a', 'c', 'b', 'e', 'f', 'd'}
256
* \see http://www.sgi.com/tech/stl/sort.html
257
* \see \p stable_sort_by_key
260
template<typename RandomAccessIterator1,
261
typename RandomAccessIterator2>
262
void sort_by_key(RandomAccessIterator1 keys_first,
263
RandomAccessIterator1 keys_last,
264
RandomAccessIterator2 values_first);
266
/*! \p sort_by_key performs a key-value sort. That is, \p sort_by_key sorts the
267
* elements in <tt>[keys_first, keys_last)</tt> and <tt>[values_first,
268
* values_first + (keys_last - keys_first))</tt> into ascending key order,
269
* meaning that if \c i and \c j are any two valid iterators in <tt>[keys_first,
270
* keys_last)</tt> such that \c i precedes \c j, and \c p and \c q are iterators
271
* in <tt>[values_first, values_first + (keys_last - keys_first))</tt>
272
* corresponding to \c i and \c j respectively, then \c *j is not less than
275
* Note: \c sort_by_key is not guaranteed to be stable. That is, suppose that
276
* \c *i and \c *j are equivalent: neither one is less than the other. It is not
277
* guaranteed that the relative order of these two keys or the relative
278
* order of their corresponding values will be preserved by \p sort_by_key.
280
* This version of \p sort_by_key compares key objects using a function object
283
* \param keys_first The beginning of the key sequence.
284
* \param keys_last The end of the key sequence.
285
* \param values_first The beginning of the value sequence.
286
* \param comp Comparison operator.
288
* \tparam RandomAccessIterator1 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
289
* \p RandomAccessIterator1 is mutable,
290
* and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's
291
* \c first_argument_type and \c second_argument_type.
292
* \tparam RandomAccessIterator2 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.hml">Random Access Iterator</a>,
293
* and \p RandomAccessIterator2 is mutable.
294
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
296
* The following code snippet demonstrates how to use \p sort_by_key to sort
297
* an array of character values using integers as sorting keys. The keys
298
* are sorted in descending order using the greater<int> comparison operator.
301
* #include <thrust/sort.h>
304
* int keys[N] = { 1, 4, 2, 8, 5, 7};
305
* char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'};
306
* thrust::sort_by_key(keys, keys + N, values, thrust::greater<int>());
307
* // keys is now { 8, 7, 5, 4, 2, 1}
308
* // values is now {'d', 'f', 'e', 'b', 'c', 'a'}
311
* \see http://www.sgi.com/tech/stl/sort.html
312
* \see \p stable_sort_by_key
315
template<typename RandomAccessIterator1,
316
typename RandomAccessIterator2,
317
typename StrictWeakOrdering>
318
void sort_by_key(RandomAccessIterator1 keys_first,
319
RandomAccessIterator1 keys_last,
320
RandomAccessIterator2 values_first,
321
StrictWeakOrdering comp);
323
/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key
324
* sorts the elements in <tt>[keys_first, keys_last)</tt> and <tt>[values_first,
325
* values_first + (keys_last - keys_first))</tt> into ascending key order,
326
* meaning that if \c i and \c j are any two valid iterators in <tt>[keys_first,
327
* keys_last)</tt> such that \c i precedes \c j, and \c p and \c q are iterators
328
* in <tt>[values_first, values_first + (keys_last - keys_first))</tt>
329
* corresponding to \c i and \c j respectively, then \c *j is not less than
332
* As the name suggests, \p stable_sort_by_key is stable: it preserves the
333
* relative ordering of equivalent elements. That is, if \c x and \c y
334
* are elements in <tt>[keys_first, keys_last)</tt> such that \c x precedes \c y,
335
* and if the two elements are equivalent (neither <tt>x < y</tt> nor
336
* <tt>y < x</tt>) then a postcondition of \p stable_sort_by_key is that \c x
337
* still precedes \c y.
339
* This version of \p stable_sort_by_key compares key objects using \c operator<.
341
* \param keys_first The beginning of the key sequence.
342
* \param keys_last The end of the key sequence.
343
* \param values_first The beginning of the value sequence.
345
* \tparam RandomAccessIterator1 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
346
* \p RandomAccessIterator1 is mutable,
347
* and \p RandomAccessIterator1's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>,
348
* and the ordering relation on \p RandomAccessIterator1's \c value_type is a <em>strict weak ordering</em>, as defined in the
349
* <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a> requirements.
350
* \tparam RandomAccessIterator2 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.hml">Random Access Iterator</a>,
351
* and \p RandomAccessIterator2 is mutable.
353
* The following code snippet demonstrates how to use \p stable_sort_by_key to sort
354
* an array of characters using integers as sorting keys.
357
* #include <thrust/sort.h>
360
* int keys[N] = { 1, 4, 2, 8, 5, 7};
361
* char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'};
362
* thrust::stable_sort_by_key(keys, keys + N, values);
363
* // keys is now { 1, 2, 4, 5, 7, 8}
364
* // values is now {'a', 'c', 'b', 'e', 'f', 'd'}
367
* \see http://www.sgi.com/tech/stl/sort.html
368
* \see \p sort_by_key
369
* \see \p stable_sort
371
template<typename RandomAccessIterator1,
372
typename RandomAccessIterator2>
373
void stable_sort_by_key(RandomAccessIterator1 keys_first,
374
RandomAccessIterator1 keys_last,
375
RandomAccessIterator2 values_first);
377
/*! \p stable_sort_by_key performs a key-value sort. That is, \p stable_sort_by_key
378
* sorts the elements in <tt>[keys_first, keys_last)</tt> and <tt>[values_first,
379
* values_first + (keys_last - keys_first))</tt> into ascending key order,
380
* meaning that if \c i and \c j are any two valid iterators in <tt>[keys_first,
381
* keys_last)</tt> such that \c i precedes \c j, and \c p and \c q are iterators
382
* in <tt>[values_first, values_first + (keys_last - keys_first))</tt>
383
* corresponding to \c i and \c j respectively, then \c *j is not less than
386
* As the name suggests, \p stable_sort_by_key is stable: it preserves the
387
* relative ordering of equivalent elements. That is, if \c x and \c y
388
* are elements in <tt>[keys_first, keys_last)</tt> such that \c x precedes \c y,
389
* and if the two elements are equivalent (neither <tt>x < y</tt> nor
390
* <tt>y < x</tt>) then a postcondition of \p stable_sort_by_key is that \c x
391
* still precedes \c y.
393
* This version of \p stable_sort_by_key compares key objects using the function
396
* \param keys_first The beginning of the key sequence.
397
* \param keys_last The end of the key sequence.
398
* \param values_first The beginning of the value sequence.
399
* \param comp Comparison operator.
401
* \tparam RandomAccessIterator1 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>,
402
* \p RandomAccessIterator1 is mutable,
403
* and \p RandomAccessIterator1's \c value_type is convertible to \p StrictWeakOrdering's
404
* \c first_argument_type and \c second_argument_type.
405
* \tparam RandomAccessIterator2 is a model of <a href="http://www.sgi.com/tech/stl/RandomAccessIterator.hml">Random Access Iterator</a>,
406
* and \p RandomAccessIterator2 is mutable.
407
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
409
* The following code snippet demonstrates how to use \p sort_by_key to sort
410
* an array of character values using integers as sorting keys. The keys
411
* are sorted in descending order using the greater<int> comparison operator.
414
* #include <thrust/sort.h>
417
* int keys[N] = { 1, 4, 2, 8, 5, 7};
418
* char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'};
419
* thrust::stable_sort_by_key(keys, keys + N, values, thrust::greater<int>());
420
* // keys is now { 8, 7, 5, 4, 2, 1}
421
* // values is now {'d', 'f', 'e', 'b', 'c', 'a'}
425
* \see http://www.sgi.com/tech/stl/sort.html
426
* \see \p sort_by_key
427
* \see \p stable_sort
429
template<typename RandomAccessIterator1,
430
typename RandomAccessIterator2,
431
typename StrictWeakOrdering>
432
void stable_sort_by_key(RandomAccessIterator1 keys_first,
433
RandomAccessIterator1 keys_last,
434
RandomAccessIterator2 values_first,
435
StrictWeakOrdering comp);
437
/*! \} // end sorting
440
/*! \addtogroup reductions
442
* \addtogroup predicates
446
/*! \p is_sorted returns \c true if the range <tt>[first, last)</tt> is
447
* sorted in ascending order, and \c false otherwise.
449
* Specifically, this version of \p is_sorted returns \c false if for
450
* some iterator \c i in the range <tt>[first, last - 1)</tt> the
451
* expression <tt>*(i + 1) < *i</tt> is \c true.
453
* \param first The beginning of the sequence.
454
* \param last The end of the sequence.
455
* \return \c true, if the sequence is sorted; \c false, otherwise.
457
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
458
* \p ForwardIterator's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>,
459
* and the ordering on objects of \p ForwardIterator's \c value_type is a <em>strict weak ordering</em>, as defined
460
* in the <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a> requirements.
463
* The following code demonstrates how to use \p is_sorted to test whether the
464
* contents of a \c device_vector are stored in ascending order.
467
* #include <thrust/sort.h>
468
* #include <thrust/device_vector.h>
469
* #include <thrust/sort.h>
471
* thrust::device_vector<int> v(6);
479
* bool result = thrust::is_sorted(v.begin(), v.end());
483
* thrust::sort(v.begin(), v.end());
484
* result = thrust::is_sorted(v.begin(), v.end());
489
* \see http://www.sgi.com/tech/stl/is_sorted.html
490
* \see is_sorted_until
492
* \see \c stable_sort
495
template<typename ForwardIterator>
496
bool is_sorted(ForwardIterator first,
497
ForwardIterator last);
499
/*! \p is_sorted returns \c true if the range <tt>[first, last)</tt> is sorted in ascending
500
* order accoring to a user-defined comparison operation, and \c false otherwise.
502
* Specifically, this version of \p is_sorted returns \c false if for some iterator \c i in
503
* the range <tt>[first, last - 1)</tt> the expression <tt>comp(*(i + 1), *i)</tt> is \c true.
505
* \param first The beginning of the sequence.
506
* \param last The end of the sequence.
507
* \param comp Comparison operator.
508
* \return \c true, if the sequence is sorted according to comp; \c false, otherwise.
510
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a>,
511
* and \p ForwardIterator's \c value_type is convertible to both \c StrictWeakOrdering's \c first_argument_type
512
* and \c second_argument_type.
513
* \tparam Compare is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
515
* The following code snippet demonstrates how to use \p is_sorted to test whether the
516
* contents of a \c device_vector are stored in descending order.
519
* #include <thrust/sort.h>
520
* #include <thrust/functional.h>
521
* #include <thrust/device_vector.h>
523
* thrust::device_vector<int> v(6);
531
* thrust::greater<int> comp;
532
* bool result = thrust::is_sorted(v.begin(), v.end(), comp);
536
* thrust::sort(v.begin(), v.end(), comp);
537
* result = thrust::is_sorted(v.begin(), v.end(), comp);
542
* \see http://www.sgi.com/tech/stl/is_sorted.html
544
* \see \c stable_sort
547
template<typename ForwardIterator, typename Compare>
548
bool is_sorted(ForwardIterator first,
549
ForwardIterator last,
552
/*! This version of \p is_sorted_until returns the last iterator \c i in <tt>[first,last]</tt> for
553
* which the range <tt>[first,last)</tt> is sorted using \c operator<. If <tt>distance(first,last) < 2</tt>,
554
* \p is_sorted_until simply returns \p last.
556
* \param first The beginning of the range of interest.
557
* \param last The end of the range of interest.
558
* \return The last iterator in the input range for which it is sorted.
560
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a> and
561
* \p ForwardIterator's \c value_type is a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan Comparable</a>.
564
* #include <thrust/sort.h>
568
* int A[8] = {0, 1, 2, 3, 0, 1, 2, 3};
570
* int * B = thrust::is_sorted_until(A, A + 8);
573
* // [A, B) is sorted
578
* \see \p sort_by_key
579
* \see \p stable_sort
580
* \see \p stable_sort_by_key
582
template<typename ForwardIterator>
583
ForwardIterator is_sorted_until(ForwardIterator first,
584
ForwardIterator last);
586
/*! This version of \p is_sorted_until returns the last iterator \c i in <tt>[first,last]</tt> for
587
* which the range <tt>[first,last)</tt> is sorted using the function object \c comp. If <tt>distance(first,last) < 2</tt>,
588
* \p is_sorted_until simply returns \p last.
590
* \param first The beginning of the range of interest.
591
* \param last The end of the range of interest.
592
* \param comp The function object to use for comparison.
593
* \return The last iterator in the input range for which it is sorted.
595
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward Iterator</a> and
596
* \p ForwardIterator's \c value_type is convertible to \p Compare's \c argument_type.
597
* \tparam Compare is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
600
* #include <thrust/sort.h>
601
* #include <thrust/functional.h>
605
* int A[8] = {3, 2, 1, 0, 3, 2, 1, 0};
607
* thrust::greater<int> comp;
608
* int * B = thrust::is_sorted_until(A, A + 8, comp);
611
* // [A, B) is sorted in descending order
616
* \see \p sort_by_key
617
* \see \p stable_sort
618
* \see \p stable_sort_by_key
620
template<typename ForwardIterator, typename Compare>
621
ForwardIterator is_sorted_until(ForwardIterator first,
622
ForwardIterator last,
625
/*! \} // end predicates
626
* \} // end reductions
629
} // end namespace thrust
631
#include <thrust/detail/sort.inl>