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)