thrust::stable_sort_by_key
Defined in thrust/sort.h
- 
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename StrictWeakOrdering>
 void thrust::stable_sort_by_key(RandomAccessIterator1 keys_first, RandomAccessIterator1 keys_last, RandomAccessIterator2 values_first, StrictWeakOrdering comp)
- stable_sort_by_keyperforms a key-value sort. That is,- stable_sort_by_keysorts the elements in- [keys_first, keys_last)and- [values_first, values_first + (keys_last - keys_first))into ascending key order, meaning that if- iand- jare any two valid iterators in- [keys_first, keys_last)such that- iprecedes- j, and- pand- qare iterators in- [values_first, values_first + (keys_last - keys_first))corresponding to- iand- jrespectively, then- *jis not less than- *i.- As the name suggests, - stable_sort_by_keyis stable: it preserves the relative ordering of equivalent elements. That is, if- xand- yare elements in- [keys_first, keys_last)such that- xprecedes- y, and if the two elements are equivalent (neither- x < ynor- y < x) then a postcondition of- stable_sort_by_keyis that- xstill precedes- y.- This version of - stable_sort_by_keycompares key objects using the function object- comp.- The following code snippet demonstrates how to use - sort_by_keyto sort an array of character values using integers as sorting keys. The keys are sorted in descending order using the greater<int> comparison operator.- #include <thrust/sort.h> ... const int N = 6; int keys[N] = { 1, 4, 2, 8, 5, 7}; char values[N] = {'a', 'b', 'c', 'd', 'e', 'f'}; thrust::stable_sort_by_key(keys, keys + N, values, thrust::greater<int>()); // keys is now { 8, 7, 5, 4, 2, 1} // values is now {'d', 'f', 'e', 'b', 'c', 'a'} - See also - sort_by_key- See also - stable_sort- Parameters
- keys_first – The beginning of the key sequence. 
- keys_last – The end of the key sequence. 
- values_first – The beginning of the value sequence. 
- comp – Comparison operator. 
 
- Template Parameters
- RandomAccessIterator1 – is a model of Random Access Iterator, - RandomAccessIterator1is mutable, and- RandomAccessIterator1's- value_typeis convertible to- StrictWeakOrdering'sfirst argument type and second argument type.
- RandomAccessIterator2 – is a model of Random Access Iterator, and - RandomAccessIterator2is mutable.
- StrictWeakOrdering – is a model of Strict Weak Ordering. 
 
- Pre
- The range - [keys_first, keys_last))shall not overlap the range- [values_first, values_first + (keys_last - keys_first)).