Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-46026

needing QList|QVector constLast() or clast()

    XMLWordPrintable

Details

    • a5306c35d1cf1e471e2a073aa1ba279081ea47ee

    Description

      It's nice that last() has an overload returning a const item but that's not enough.

      Found hundreds of cases of detaching temporary containers in Qt and KDE.

      For example:
      if (foo.getList().first() == bar)

      first() is easy to replace with at(0).

      but last() is difficult to replace without:
      1) writing boiler-plate code / increasing verbosity

      2) loosing semantics/readability.

      3) Assigning the temporary into a const list first. Which I tried in https://codereview.qt-project.org/#/c/112029 but resulted in bug-prone code, due to the non-trivial nature of the existing code

      constFirst() would be welcome too, it has stronger semantics than at(0)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            iamsergio Sergio Martins
            iamsergio Sergio Martins
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes