[Interest] qsort() Obsolete?

Berkay Elbir berkayelbir at gmail.com
Fri Apr 17 13:01:11 CEST 2015


Thanks. I used std::sort that is most reliable way.

Berkay

On Fri, Apr 17, 2015 at 1:22 PM, André Somers <andre at familiesomers.nl>
wrote:

>  Berkay Elbir schreef op 17-4-2015 om 12:12:
>
> Hello All,
>
>  I want to ask a question to you to be certain. Is void qsort() function
> obsolete? Should we use std::sort instead of this function? Because I have
> a priority list and need to sort it.
>
>  Yes, in general the things you can find in <QtAlgorithms> should be
> replaced with their stl (or other) counterparts. If you are just like I am
> and do not like the verbose syntax of specifying two iterators instead of
> just the whole container, you can use a small macro (or specify your own
> overloads for all algorithms of course). I use:
>
> /**
>
>   * shorthand to writing a range with a c.constBegin and c
>  .constE
> nd. Instead, you
>
>   * can pass in constAll(c)
>
>   */
>
> #define constAll(c) c.constBegin(), c.constEnd()
>
>  /**
>
>   * shorthand to writing a range with a c.cBegin and c.cEn
>  d. Instead, you
>
>   * can pass in ccAll(c)
>
>   */
>
> #define cAll(c) c.cBegin(), c.cEnd()
>
>  /**
>
>   * shorthand to writing a range with a c.begin and c.end.
>   Instead, you
>
>   * can pass in all(c)
>
>   */
>
> #define all(c) c.begin(), c.end()
>
> Of course, if you use C++/11, you should probably be using begin(c) and end(c) instead of c.begin() and c.end()
>
> You can then write:
> std::sort(all(myList));
>
> instead of:
> std::sort(begin(myList), end(myList));
> or
> std::sort(myList.begin(), myList.end());
>
> Of course, if you actually need to operate on part of a container, you can still use the iterators directly.
>
> André
>
>
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150417/0a52824a/attachment.html>


More information about the Interest mailing list