Perfect forwarding passes arguments through a wrapper while preserving their original value categories and cv-ref qualifiers. With vectors, it helps construct elements without copying temporary row data. section 2.2.3
The vector example distinguishes the relevant operations:
- push_back accepts a complete object; its const-reference overload copies the supplied row. section 2.2.3
- The rvalue-reference overload accepts a temporary and can move its elements instead of copying them. section 2.2.3
- emplace_back constructs the vector element in place from the temporary row. section 2.2.3
Generating a triangle without copying rows
generate_triangle initializes the first row, then calls get_next_row(triangle.back()) and passes the temporary directly to triangle.push_back. The alternative triangle.emplace_back(get_next_row(triangle.back())) constructs the row in place.
