rspec/rules/S5294/rule.adoc

23 lines
678 B
Plaintext

Container member functions that modify the containers often take an iterator as input to specify a precise location work on. If this iterator comes from a different container than the one calling the function, the result will be undefined.
== Noncompliant Code Example
----
void test(std::vector &v1, std::vector &v2) {
v1.insert(v2.begin(), v2.begin(), v2.end()); // Noncompliant, the first argument is the insertion location and must be in v1
v1.erase(v2.begin()); // Noncompliant
}
----
== Compliant Solution
----
void test(std::vector &v1, std::vector &v2) {
v1.insert(v1.begin(), v2.begin(), v2.end()); // Compliant
v1.erase(v1.begin()); // Compliant
}
----