1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:FDL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Free Documentation License Usage
18** Alternatively, this file may be used under the terms of the GNU Free
19** Documentation License version 1.3 as published by the Free Software
20** Foundation and appearing in the file included in the packaging of
21** this file. Please review the following information to ensure
22** the GNU Free Documentation License version 1.3 requirements
23** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29    \headerfile <QtAlgorithms>
30    \title Generic Algorithms
31    \ingroup funclists
32    \keyword generic algorithms
33
34    \brief The <QtAlgorithms> header includes the generic, template-based algorithms.
35
36    Qt provides a number of global template functions in \c
37    <QtAlgorithms> that work on containers and perform small tasks to
38    make life easier, such as qDeleteAll(), which invokes \c{operator delete}
39    on all items in a given container or in a given range.
40    You can use these algorithms with any \l {container
41    class} that provides STL-style iterators, including Qt's QList,
42    QLinkedList, QVector, QMap, and QHash classes.
43
44    Most algorithms take \l {STL-style iterators} as parameters. The
45    algorithms are generic in the sense that they aren't bound to a
46    specific iterator class; you can use them with any iterators that
47    meet a certain set of requirements.
48
49    Different algorithms can have different requirements for the
50    iterators they accept. For example, qFill() accepts two
51    \l {forward iterators}. The iterator types required are specified
52    for each algorithm. If an iterator of the wrong type is passed (for
53    example, if QList::ConstIterator is passed as an
54    \l {Output Iterators}{output iterator}), you will always get a
55    compiler error, although not necessarily a very informative one.
56
57    Some algorithms have special requirements on the value type
58    stored in the containers. For example,
59    qDeleteAll() requires that the value type is a
60    non-const pointer type (for example, QWidget *). The value type
61    requirements are specified for each algorithm, and the compiler
62    will produce an error if a requirement isn't met.
63
64    The generic algorithms can be used on other container classes
65    than those provided by Qt and STL. The syntax of STL-style
66    iterators is modeled after C++ pointers, so it's possible to use
67    plain arrays as containers and plain pointers as iterators. A
68    common idiom is to use qBinaryFind() together with two static
69    arrays: one that contains a list of keys, and another that
70    contains a list of associated values. For example, the following
71    code will look up an HTML entity (e.g., \c &amp;) in the \c
72    name_table array and return the corresponding Unicode value from
73    the \c value_table if the entity is recognized:
74
75    \snippet code/doc_src_qalgorithms.cpp 2
76
77    This kind of code is for advanced users only; for most
78    applications, a QMap- or QHash-based approach would work just as
79    well:
80
81    \snippet code/doc_src_qalgorithms.cpp 3
82
83    \section1 Types of Iterators
84
85    The algorithms have certain requirements on the iterator types
86    they accept, and these are specified individually for each
87    function. The compiler will produce an error if a requirement
88    isn't met.
89
90    \section2 Input Iterators
91
92    An \e{input iterator} is an iterator that can be used for reading
93    data sequentially from a container. It must provide the following
94    operators: \c{==} and \c{!=} for comparing two iterators, unary
95    \c{*} for retrieving the value stored in the item, and prefix
96    \c{++} for advancing to the next item.
97
98    The Qt containers' iterator types (const and non-const) are all
99    input iterators.
100
101    \section2 Output Iterators
102
103    An output iterator is an iterator that can be used for
104    writing data sequentially to a container or to some output
105    stream. It must provide the following operators: unary \c{*} for
106    writing a value (i.e., \c{*it = val}) and prefix \c{++} for
107    advancing to the next item.
108
109    The Qt containers' non-const iterator types are all output
110    iterators.
111
112    \section2 Forward Iterators
113
114    A \e{forward iterator} is an iterator that meets the requirements
115    of both input iterators and output iterators.
116
117    The Qt containers' non-const iterator types are all forward
118    iterators.
119
120    \section2 Bidirectional Iterators
121
122    A \e{bidirectional iterator} is an iterator that meets the
123    requirements of forward iterators but that in addition supports
124    prefix \c{--} for iterating backward.
125
126    The Qt containers' non-const iterator types are all bidirectional
127    iterators.
128
129    \section2 Random Access Iterators
130
131    The last category, \e{random access iterators}, is the most
132    powerful type of iterator. It supports all the requirements of a
133    bidirectional iterator, and supports the following operations:
134
135    \table
136    \row \li \c{i += n} \li advances iterator \c i by \c n positions
137    \row \li \c{i -= n} \li moves iterator \c i back by \c n positions
138    \row \li \c{i + n} or \c{n + i} \li returns the iterator for the item \c
139       n positions ahead of iterator \c i
140    \row \li \c{i - n} \li returns the iterator for the item \c n positions behind of iterator \c i
141    \row \li \c{i - j} \li returns the number of items between iterators \c i and \c j
142    \row \li \c{i[n]} \li same as \c{*(i + n)}
143    \row \li \c{i < j} \li returns \c true if iterator \c j comes after iterator \c i
144    \endtable
145
146    QList and QVector's non-const iterator types are random access iterators.
147
148    \section1 Qt and the STL Algorithms
149
150    Historically, Qt used to provide functions which were direct equivalents of
151    many STL algorithmic functions. Starting with Qt 5.0, you are instead
152    encouraged to use directly the implementations available in the STL; most
153    of the Qt ones have been deprecated (although they are still available to
154    keep the old code compiling).
155
156    \section2 Porting guidelines
157
158    Most of the time, an application using the deprecated Qt algorithmic functions
159    can be easily ported to use the equivalent STL functions. You need to:
160
161    \list 1
162        \li add the \c{#include <algorithm>} preprocessor directive;
163        \li replace the Qt functions with the STL counterparts, according to the table below.
164    \endlist
165
166    \table
167    \header
168        \li Qt function
169        \li STL function
170    \row
171        \li qBinaryFind
172        \li \c std::binary_search or \c std::lower_bound
173    \row
174        \li qCopy
175        \li \c std::copy
176    \row
177        \li qCopyBackward
178        \li \c std::copy_backward
179    \row
180        \li qEqual
181        \li \c std::equal
182    \row
183        \li qFill
184        \li \c std::fill
185    \row
186        \li qFind
187        \li \c std::find
188    \row
189        \li qCount
190        \li \c std::count
191    \row
192        \li qSort
193        \li \c std::sort
194    \row
195        \li qStableSort
196        \li \c std::stable_sort
197    \row
198        \li qLowerBound
199        \li \c std::lower_bound
200    \row
201        \li qUpperBound
202        \li \c std::upper_bound
203    \row
204        \li qLess
205        \li \c std::less
206    \row
207        \li qGreater
208        \li \c std::greater
209
210    \endtable
211
212    The only cases in which the port may not be straightforward is if the old
213    code relied on template specializations of the qLess() and/or the qSwap()
214    functions, which were used internally by the implementations of the Qt
215    algorithmic functions, but are instead ignored by the STL ones.
216
217    In case the old code relied on the specialization of the qLess() functor,
218    then a workaround is explicitly passing an instance of the qLess() class
219    to the STL function, for instance like this:
220
221    \code
222        std::sort(container.begin(), container.end(), qLess<T>());
223    \endcode
224
225    Instead, since it's not possible to pass a custom swapper functor to STL
226    functions, the only workaround for a template specialization for qSwap() is
227    providing the same specialization for \c std::swap().
228
229    \sa {container classes}, <QtGlobal>
230*/
231
232/*! \fn template <typename InputIterator, typename OutputIterator> OutputIterator qCopy(InputIterator begin1, InputIterator end1, OutputIterator begin2)
233    \relates <QtAlgorithms>
234    \deprecated
235
236    Use \c std::copy instead.
237
238    Copies the items from range [\a begin1, \a end1) to range [\a
239    begin2, ...), in the order in which they appear.
240
241    The item at position \a begin1 is assigned to that at position \a
242    begin2; the item at position \a begin1 + 1 is assigned to that at
243    position \a begin2 + 1; and so on.
244
245    Example:
246    \snippet code/doc_src_qalgorithms.cpp 4
247
248    \sa qCopyBackward(), {input iterators}, {output iterators}
249*/
250
251/*! \fn template <typename BiIterator1, typename BiIterator2> BiIterator2 qCopyBackward(BiIterator1 begin1, BiIterator1 end1, BiIterator2 end2)
252    \relates <QtAlgorithms>
253    \deprecated
254
255    Use \c std::copy_backward instead.
256
257    Copies the items from range [\a begin1, \a end1) to range [...,
258    \a end2).
259
260    The item at position \a end1 - 1 is assigned to that at position
261    \a end2 - 1; the item at position \a end1 - 2 is assigned to that
262    at position \a end2 - 2; and so on.
263
264    Example:
265    \snippet code/doc_src_qalgorithms.cpp 5
266
267    \sa qCopy(), {bidirectional iterators}
268*/
269
270/*! \fn template <typename InputIterator1, typename InputIterator2> bool qEqual(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2)
271    \relates <QtAlgorithms>
272    \deprecated
273
274    Use \c std::equal instead.
275
276    Compares the items in the range [\a begin1, \a end1) with the
277    items in the range [\a begin2, ...). Returns \c true if all the
278    items compare equal; otherwise returns \c false.
279
280    Example:
281    \snippet code/doc_src_qalgorithms.cpp 6
282
283    This function requires the item type (in the example above,
284    QString) to implement \c operator==().
285
286    \sa {input iterators}
287*/
288
289/*! \fn template <typename ForwardIterator, typename T> void qFill(ForwardIterator begin, ForwardIterator end, const T &value)
290    \relates <QtAlgorithms>
291    \deprecated
292
293    Use \c std::fill instead.
294
295    Fills the range [\a begin, \a end) with \a value.
296
297    Example:
298    \snippet code/doc_src_qalgorithms.cpp 7
299
300    \sa qCopy(), {forward iterators}
301*/
302
303/*! \fn template <typename Container, typename T> void qFill(Container &container, const T &value)
304    \relates <QtAlgorithms>
305    \deprecated
306    \overload
307
308    Use \c std::fill instead.
309
310    This is the same as qFill(\a{container}.begin(), \a{container}.end(), \a value);
311*/
312
313/*! \fn template <typename InputIterator, typename T> InputIterator qFind(InputIterator begin, InputIterator end, const T &value)
314    \relates <QtAlgorithms>
315    \deprecated
316
317    Use \c std::find instead.
318
319    Returns an iterator to the first occurrence of \a value in a
320    container in the range [\a begin, \a end). Returns \a end if \a
321    value isn't found.
322
323    Example:
324    \snippet code/doc_src_qalgorithms.cpp 8
325
326    This function requires the item type (in the example above,
327    QString) to implement \c operator==().
328
329    If the items in the range are in ascending order, you can get
330    faster results by using qLowerBound() or qBinaryFind() instead of
331    qFind().
332
333    \sa qBinaryFind(), {input iterators}
334*/
335
336/*! \fn template <typename Container, typename T> void qFind(const Container &container, const T &value)
337    \relates <QtAlgorithms>
338    \deprecated
339    \overload
340
341    Use \c std::find instead.
342
343    This is the same as qFind(\a{container}.constBegin(), \a{container}.constEnd(), \a value);
344*/
345
346/*! \fn template <typename InputIterator, typename T, typename Size> void qCount(InputIterator begin, InputIterator end, const T &value, Size &n)
347    \relates <QtAlgorithms>
348    \deprecated
349
350    Use \c std::count instead.
351
352    Returns the number of occurrences of \a value in the range [\a begin, \a end),
353    which is returned in \a n. \a n is never initialized, the count is added to \a n.
354    It is the caller's responsibility to initialize \a n.
355
356    Example:
357
358    \snippet code/doc_src_qalgorithms.cpp 9
359
360    This function requires the item type (in the example above,
361    \c int) to implement \c operator==().
362
363    \sa {input iterators}
364*/
365
366/*! \fn template <typename Container, typename T, typename Size> void qCount(const Container &container, const T &value, Size &n)
367    \relates <QtAlgorithms>
368    \deprecated
369    \overload
370
371    Use \c std::count instead.
372
373    Instead of operating on iterators, as in the other overload, this function
374    operates on the specified \a container to obtain the number of instances
375    of \a value in the variable passed as a reference in argument \a n.
376*/
377
378/*! \fn template <typename T> void qSwap(T &var1, T &var2)
379    \relates <QtAlgorithms>
380    \deprecated
381
382    Use \c std::swap instead.
383
384    Exchanges the values of variables \a var1 and \a var2.
385
386    Example:
387    \snippet code/doc_src_qalgorithms.cpp 10
388*/
389
390/*! \fn template <typename RandomAccessIterator> void qSort(RandomAccessIterator begin, RandomAccessIterator end)
391    \relates <QtAlgorithms>
392    \deprecated
393
394    Use \c std::sort instead.
395
396    Sorts the items in range [\a begin, \a end) in ascending order
397    using the quicksort algorithm.
398
399    Example:
400    \snippet code/doc_src_qalgorithms.cpp 11
401
402    The sort algorithm is efficient on large data sets. It operates
403    in \l {linear-logarithmic time}, O(\e{n} log \e{n}).
404
405    This function requires the item type (in the example above,
406    \c{int}) to implement \c operator<().
407
408    If neither of the two items is "less than" the other, the items are
409    taken to be equal. It is then undefined which one of the two
410    items will appear before the other after the sort.
411
412    \sa qStableSort(), {random access iterators}
413*/
414
415/*! \fn template <typename RandomAccessIterator, typename LessThan> void qSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)
416    \relates <QtAlgorithms>
417    \deprecated
418    \overload
419
420    Use \c std::sort instead.
421
422    Uses the \a lessThan function instead of \c operator<() to
423    compare the items.
424
425    For example, here's how to sort the strings in a QStringList
426    in case-insensitive alphabetical order:
427
428    \snippet code/doc_src_qalgorithms.cpp 12
429
430    To sort values in reverse order, pass
431    \l{qGreater()}{qGreater<T>()} as the \a lessThan parameter. For
432    example:
433
434    \snippet code/doc_src_qalgorithms.cpp 13
435
436    If neither of the two items is "less than" the other, the items are
437    taken to be equal. It is then undefined which one of the two
438    items will appear before the other after the sort.
439
440    An alternative to using qSort() is to put the items to sort in a
441    QMap, using the sort key as the QMap key. This is often more
442    convenient than defining a \a lessThan function. For example, the
443    following code shows how to sort a list of strings case
444    insensitively using QMap:
445
446    \snippet code/doc_src_qalgorithms.cpp 14
447
448    \sa QMap
449*/
450
451/*! \fn template<typename Container> void qSort(Container &container)
452    \relates <QtAlgorithms>
453    \deprecated
454    \overload
455
456    Use \c std::sort instead.
457
458    This is the same as qSort(\a{container}.begin(), \a{container}.end());
459*/
460
461/*!
462    \fn template <typename RandomAccessIterator> void qStableSort(RandomAccessIterator begin, RandomAccessIterator end)
463    \relates <QtAlgorithms>
464    \deprecated
465
466    Use \c std::stable_sort instead.
467
468    Sorts the items in range [\a begin, \a end) in ascending order
469    using a stable sorting algorithm.
470
471    If neither of the two items is "less than" the other, the items are
472    taken to be equal. The item that appeared before the other in the
473    original container will still appear first after the sort. This
474    property is often useful when sorting user-visible data.
475
476    Example:
477    \snippet code/doc_src_qalgorithms.cpp 15
478
479    The sort algorithm is efficient on large data sets. It operates
480    in \l {linear-logarithmic time}, O(\e{n} log \e{n}).
481
482    This function requires the item type (in the example above,
483    \c{int}) to implement \c operator<().
484
485    \sa qSort(), {random access iterators}
486*/
487
488/*!
489    \fn template <typename RandomAccessIterator, typename LessThan> void qStableSort(RandomAccessIterator begin, RandomAccessIterator end, LessThan lessThan)
490    \relates <QtAlgorithms>
491    \deprecated
492    \overload
493
494    Use \c std::stable_sort instead.
495
496    Uses the \a lessThan function instead of \c operator<() to
497    compare the items.
498
499    For example, here's how to sort the strings in a QStringList
500    in case-insensitive alphabetical order:
501
502    \snippet code/doc_src_qalgorithms.cpp 16
503
504    Note that earlier versions of Qt allowed using a lessThan function that took its
505    arguments by non-const reference. From 4.3 and on this is no longer possible,
506    the arguments has to be passed by const reference or value.
507
508    To sort values in reverse order, pass
509    \l{qGreater()}{qGreater<T>()} as the \a lessThan parameter. For
510    example:
511
512    \snippet code/doc_src_qalgorithms.cpp 17
513
514    If neither of the two items is "less than" the other, the items are
515    taken to be equal. The item that appeared before the other in the
516    original container will still appear first after the sort. This
517    property is often useful when sorting user-visible data.
518*/
519
520/*!
521    \fn template <typename Container> void qStableSort(Container &container)
522    \relates <QtAlgorithms>
523    \deprecated
524    \overload
525
526    Use \c std::stable_sort instead.
527
528    This is the same as qStableSort(\a{container}.begin(), \a{container}.end());
529*/
530
531/*! \fn template <typename RandomAccessIterator, typename T> RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
532    \relates <QtAlgorithms>
533    \deprecated
534
535    Use \c std::lower_bound instead.
536
537    Performs a binary search of the range [\a begin, \a end) and
538    returns the position of the first occurrence of \a value. If no
539    such item is found, returns the position where it should be
540    inserted.
541
542    The items in the range [\a begin, \e end) must be sorted in
543    ascending order; see qSort().
544
545    Example:
546    \snippet code/doc_src_qalgorithms.cpp 18
547
548    This function requires the item type (in the example above,
549    \c{int}) to implement \c operator<().
550
551    qLowerBound() can be used in conjunction with qUpperBound() to
552    iterate over all occurrences of the same value:
553
554    \snippet code/doc_src_qalgorithms.cpp 19
555
556    \sa qUpperBound(), qBinaryFind()
557*/
558
559/*!
560    \fn template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
561    \relates <QtAlgorithms>
562    \deprecated
563    \overload
564
565    Use \c std::lower_bound instead.
566
567    Uses the \a lessThan function instead of \c operator<() to
568    compare the items.
569
570    Note that the items in the range must be sorted according to the order
571    specified by the \a lessThan object.
572*/
573
574/*!
575    \fn template <typename Container, typename T> void qLowerBound(const Container &container, const T &value)
576    \relates <QtAlgorithms>
577    \deprecated
578    \overload
579
580    Use \c std::lower_bound instead.
581
582    For read-only iteration over containers, this function is broadly equivalent to
583    qLowerBound(\a{container}.begin(), \a{container}.end(), value). However, since it
584    returns a const iterator, you cannot use it to modify the container; for example,
585    to insert items.
586*/
587
588/*! \fn template <typename RandomAccessIterator, typename T> RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
589    \relates <QtAlgorithms>
590    \deprecated
591
592    Use \c std::upper_bound instead.
593
594    Performs a binary search of the range [\a begin, \a end) and
595    returns the position of the one-past-the-last occurrence of \a
596    value. If no such item is found, returns the position where the
597    item should be inserted.
598
599    The items in the range [\a begin, \e end) must be sorted in
600    ascending order; see qSort().
601
602    Example:
603    \snippet code/doc_src_qalgorithms.cpp 20
604
605    This function requires the item type (in the example above,
606    \c{int}) to implement \c operator<().
607
608    qUpperBound() can be used in conjunction with qLowerBound() to
609    iterate over all occurrences of the same value:
610
611    \snippet code/doc_src_qalgorithms.cpp 21
612
613    \sa qLowerBound(), qBinaryFind()
614*/
615
616/*!
617    \fn template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qUpperBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
618    \relates <QtAlgorithms>
619    \deprecated
620    \overload
621
622    Use \c std::upper_bound instead.
623
624    Uses the \a lessThan function instead of \c operator<() to
625    compare the items.
626
627    Note that the items in the range must be sorted according to the order
628    specified by the \a lessThan object.
629*/
630
631/*!
632    \fn template <typename Container, typename T> void qUpperBound(const Container &container, const T &value)
633    \relates <QtAlgorithms>
634    \deprecated
635    \overload
636
637    Use \c std::upper_bound instead.
638
639    This is the same as qUpperBound(\a{container}.begin(), \a{container}.end(), \a value);
640*/
641
642
643/*! \fn template <typename RandomAccessIterator, typename T> RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
644    \relates <QtAlgorithms>
645    \deprecated
646
647    Use \c std::binary_search or \c std::lower_bound instead.
648
649    Performs a binary search of the range [\a begin, \a end) and
650    returns the position of an occurrence of \a value. If there are
651    no occurrences of \a value, returns \a end.
652
653    The items in the range [\a begin, \a end) must be sorted in
654    ascending order; see qSort().
655
656    If there are many occurrences of the same value, any one of them
657    could be returned. Use qLowerBound() or qUpperBound() if you need
658    finer control.
659
660    Example:
661    \snippet code/doc_src_qalgorithms.cpp 22
662
663    This function requires the item type (in the example above,
664    QString) to implement \c operator<().
665
666    \sa qLowerBound(), qUpperBound(), {random access iterators}
667*/
668
669/*! \fn template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value, LessThan lessThan)
670    \relates <QtAlgorithms>
671    \deprecated
672    \overload
673
674    Use \c std::binary_search or \c std::lower_bound instead.
675
676    Uses the \a lessThan function instead of \c operator<() to
677    compare the items.
678
679    Note that the items in the range must be sorted according to the order
680    specified by the \a lessThan object.
681*/
682
683/*!
684    \fn template <typename Container, typename T> void qBinaryFind(const Container &container, const T &value)
685    \relates <QtAlgorithms>
686    \deprecated
687    \overload
688
689    Use \c std::binary_search or \c std::lower_bound instead.
690
691    This is the same as qBinaryFind(\a{container}.begin(), \a{container}.end(), \a value);
692*/
693
694
695/*!
696    \fn template <typename ForwardIterator> void qDeleteAll(ForwardIterator begin, ForwardIterator end)
697    \relates <QtAlgorithms>
698
699    Deletes all the items in the range [\a begin, \a end) using the
700    C++ \c delete operator. The item type must be a pointer type (for
701    example, \c{QWidget *}).
702
703    Example:
704    \snippet code/doc_src_qalgorithms.cpp 23
705
706    Notice that qDeleteAll() doesn't remove the items from the
707    container; it merely calls \c delete on them. In the example
708    above, we call clear() on the container to remove the items.
709
710    This function can also be used to delete items stored in
711    associative containers, such as QMap and QHash. Only the objects
712    stored in each container will be deleted by this function; objects
713    used as keys will not be deleted.
714
715    \sa {forward iterators}
716*/
717
718/*!
719    \fn template <typename Container> void qDeleteAll(const Container &c)
720    \relates <QtAlgorithms>
721
722    \overload
723
724    This is the same as qDeleteAll(\a{c}.begin(), \a{c}.end()).
725*/
726
727/*! \fn template <typename LessThan> LessThan qLess()
728    \relates <QtAlgorithms>
729    \deprecated
730
731    Use \c std::less instead.
732
733    Returns a functional object, or functor, that can be passed to qSort()
734    or qStableSort().
735
736    Example:
737
738    \snippet code/doc_src_qalgorithms.cpp 24
739
740    \sa {qGreater()}{qGreater<T>()}
741*/
742
743/*! \fn template <typename LessThan> LessThan qGreater()
744    \relates <QtAlgorithms>
745    \deprecated
746
747    Use \c std::greater instead.
748
749    Returns a functional object, or functor, that can be passed to qSort()
750    or qStableSort().
751
752    Example:
753
754    \snippet code/doc_src_qalgorithms.cpp 25
755
756    \sa {qLess()}{qLess<T>()}
757*/
758
759
760/*!
761    \fn uint qPopulationCount(quint8 v)
762    \relates <QtAlgorithms>
763    \since 5.2
764
765    Returns the number of bits set in \a v. This number is also called
766    the Hamming Weight of \a v.
767 */
768
769/*!
770    \fn uint qPopulationCount(quint16 v)
771    \relates <QtAlgorithms>
772    \since 5.2
773    \overload
774 */
775
776/*!
777    \fn uint qPopulationCount(quint32 v)
778    \relates <QtAlgorithms>
779    \since 5.2
780    \overload
781 */
782
783/*!
784    \fn uint qPopulationCount(quint64 v)
785    \relates <QtAlgorithms>
786    \since 5.2
787    \overload
788 */
789
790/*!
791    \fn uint qCountTrailingZeroBits(quint8 v)
792    \relates <QtAlgorithms>
793    \since 5.6
794
795    Returns the number of consecutive zero bits in \a v, when searching from the LSB.
796    For example, qCountTrailingZeroBits(1) returns 0 and qCountTrailingZeroBits(8) returns 3.
797 */
798
799/*!
800    \fn uint qCountTrailingZeroBits(quint16 v)
801    \relates <QtAlgorithms>
802    \since 5.6
803    \overload
804 */
805
806/*!
807    \fn uint qCountTrailingZeroBits(quint32 v)
808    \relates <QtAlgorithms>
809    \since 5.6
810    \overload
811 */
812
813/*!
814    \fn uint qCountTrailingZeroBits(quint64 v)
815    \relates <QtAlgorithms>
816    \since 5.6
817    \overload
818 */
819
820/*!
821    \fn uint qCountLeadingZeroBits(quint8 v)
822    \relates <QtAlgorithms>
823    \since 5.6
824
825    Returns the number of consecutive zero bits in \a v, when searching from the MSB.
826    For example, qCountLeadingZeroBits(quint8(1)) returns 7 and
827    qCountLeadingZeroBits(quint8(8)) returns 4.
828 */
829
830/*!
831    \fn uint qCountLeadingZeroBits(quint16 v)
832    \relates <QtAlgorithms>
833    \since 5.6
834
835    Returns the number of consecutive zero bits in \a v, when searching from the MSB.
836    For example, qCountLeadingZeroBits(quint16(1)) returns 15 and
837    qCountLeadingZeroBits(quint16(8)) returns 12.
838 */
839
840/*!
841    \fn uint qCountLeadingZeroBits(quint32 v)
842    \relates <QtAlgorithms>
843    \since 5.6
844
845    Returns the number of consecutive zero bits in \a v, when searching from the MSB.
846    For example, qCountLeadingZeroBits(quint32(1)) returns 31 and
847    qCountLeadingZeroBits(quint32(8)) returns 28.
848 */
849
850/*!
851    \fn uint qCountLeadingZeroBits(quint64 v)
852    \relates <QtAlgorithms>
853    \since 5.6
854
855    Returns the number of consecutive zero bits in \a v, when searching from the MSB.
856    For example, qCountLeadingZeroBits(quint64(1)) returns 63 and
857    qCountLeadingZeroBits(quint64(8)) returns 60.
858 */
859