Skip to content

Conversation

@GermanAizek
Copy link
Contributor

@GermanAizek GermanAizek commented Dec 1, 2025

For custom iterator types, such as those often found in standard library containers or custom data structures, prefix increment (++it) is generally more efficient than postfix increment (it++). The postfix version typically requires creating a temporary copy of the iterator's original state before performing the increment and returning the copy. In contrast, the prefix version increments the iterator directly and returns a reference to the modified iterator, avoiding the overhead of a temporary object.

References:

Co-Authored-By: Gemini 2.5 Pro (References and desc commit changes)

For custom iterator types, such as those often found in standard library containers or custom data structures, prefix increment (`++it`) is generally more efficient than postfix increment (`it++`). The postfix version typically requires creating a temporary copy of the iterator's original state before performing the increment and returning the copy. In contrast, the prefix version increments the iterator directly and returns a reference to the modified iterator, avoiding the overhead of a temporary object.

References:
*   **Stack Overflow:** Is there a performance difference between ++i and i++ in C++?
    [https://stackoverflow.com/questions/248549/is-there-a-performance-difference-between-i-and-i-in-c](https://stackoverflow.com/questions/248549/is-there-a-performance-difference-between-i-and-i-in-c)
*   **GeeksforGeeks:** Prefix vs Postfix Increment/Decrement Operators in C++
    [https://www.geeksforgeeks.org/prefix-vs-postfix-increment-decrement-operators-in-cpp/](https://www.geeksforgeeks.org/prefix-vs-postfix-increment-decrement-operators-in-cpp/)
*   **Fluent C++:** The Performance of Prefix vs Postfix Increment Operator
    [https://www.fluentcpp.com/2019/02/15/the-performance-of-prefix-vs-postfix-increment-operator/](https://www.fluentcpp.com/2019/02/15/the-performance-of-prefix-vs-postfix-increment-operator/)
*   **Bjarne Stroustrup's FAQ:** Why should I prefer prefix to postfix increment?
    [https://www.stroustrup.com/bs_faq2.html#iterators](https://www.stroustrup.com/bs_faq2.html#iterators)
*   **Modern C++ Best Practices:** Prefer prefix increment/decrement
    [https://www.modernescpp.com/index.php/prefer-prefix-increment-decrement](https://www.modernescpp.com/index.php/prefer-prefix-increment-decrement)
@GermanAizek GermanAizek requested a review from CISC as a code owner December 1, 2025 10:56
@am17an
Copy link
Collaborator

am17an commented Dec 1, 2025

Have you looked at the #17625?

@GermanAizek
Copy link
Contributor Author

Have you looked at the #17625?

Oh no, my sorry. Wait, I'll fix it now.

@GermanAizek
Copy link
Contributor Author

GermanAizek commented Dec 1, 2025

Co-Authored-By: Gemini 2.5 Pro (References and desc commit changes)

@am17an fix it

@CISC
Copy link
Collaborator

CISC commented Dec 1, 2025

Cool, all links are dead. :)

Besides I don't believe for a second that there is an actual difference when you compile with optimization.

@GermanAizek
Copy link
Contributor Author

GermanAizek commented Dec 1, 2025

Cool, all links are dead. :)

I think it's because of the old 2.5 model, although maybe the model was actually trained on links that are no longer relevant.

I thought that at least she would make links and description changes without problems.

@pwilkin
Copy link
Collaborator

pwilkin commented Dec 1, 2025

@CISC I think it's time to unravel the shiny new label.

@pwilkin pwilkin added the vibe-coded Created with heavy use of LLM assistants, requires human verification label Dec 1, 2025
@am17an
Copy link
Collaborator

am17an commented Dec 1, 2025

Let it be known that I had nothing to do with this when the robots come for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vibe-coded Created with heavy use of LLM assistants, requires human verification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants