...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(const std::vector<int> &Cc) {
std::for_each(Cc.end(), Cc.begin(), [](int Ii) { std::cout << Ii; });
} |
Invalid iterator ranges can also result from comparison functions that return true for equal values. See CTR57-CPP. Provide a valid ordering predicate for more information about comparators.
...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(const std::vector<int> &Cc) {
std::for_each(Cc.begin(), Cc.end(), [](int Ii) { std::cout << Ii; });
} |
Noncompliant Code Example
...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(const std::vector<int> &Cc) {
std::vector<int>::const_iterator Ee;
std::for_each(Cc.begin(), Ee, [](int Ii) { std::cout << Ii; });
} |
Compliant Solution
...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(const std::vector<int> &Cc) {
std::for_each(Cc.begin(), Cc.end(), [](int Ii) { std::cout << Ii; });
}
|
Noncompliant Code Example
...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(std::vector<int> &Cc) {
std::remove(Cc.begin(), Cc.end(), 42);
for (auto Vv : Cc) {
std::cout << "Container element: " << Vv << std::endl;
}
} |
Compliant Solution
...
Code Block |
---|
|
#include <algorithm>
#include <iostream>
#include <vector>
void f(std::vector<int> &Cc) {
Cc.erase(std::remove(Cc.begin(), Cc.end(), 42), Cc.end());
for (auto Vv : Cc) {
std::cout << "Container element: " << Vv << std::endl;
}
} |
Risk Assessment
...