Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
5.6.0 Alpha
-
None
-
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
For Gerrit Dashboard: QTBUG-46026 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
112343,3 | WIP: QVector: add rvalue overloads and const versions for accessors | dev | qt/qtbase | Status: ABANDONED | -2 | 0 |
112439,4 | QVector: add const first/last getters | dev | qt/qtbase | Status: MERGED | +2 | 0 |
115184,3 | QList: Introduce constFirst() and constEnd() | dev | qt/qtbase | Status: MERGED | +2 | 0 |