cpp[forge]landing
01 run
02 check copies
03 use ++it
04 submit
05 save progress
01problem
STL & Iterators · INTERMEDIATE

The postfix tax

Two loops. Same answer. One makes 1000 extra copies.

Keep the same output. Remove the extra iterator copies.

why it matters

it++ returns the old iterator — so it makes a copy first. Here the iterator is heavy.

checked

functional tests · copy counter · quality grade
02editorread-only demo
1// #207 — join every element into one string
2template <class It>
3std::string join(It it, It end) {
4 std::string s;
5 for (; it != end; it++) {
6 s += *it;
7 }
8 return s;
9}
03runneridle
$ run runs solution.cpp and counts iterator copies
// nothing has run yet. on $ run:
build & run your code ~400ms
check output against the reference
count iterator copies while it runs
grade the C++, not just the answer
press $ run or ⌘↵ to start
A normal checker sees the answer. CppForge sees the cost.
build output copies · guest mode: progress is not saved