Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Coding style conformance

...

Code Block
bgColor#FFcccc
langcpp
#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
bgColor#ccccff
langcpp
#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
bgColor#FFcccc
langcpp
#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
bgColor#ccccff
langcpp
#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
bgColor#ffcccc
langcpp
#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
bgColor#ccccff
langcpp
#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

...