Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this noncompliant code example, iterators from different containers are passed for the same iterator range. Although many STL implementations will compile this code and exhibit reasonable behaviorthe program may behave as the developer expects, there is no requirement that an STL implementation treat a default-initialized iterator as a synonym for for the iterator returned by end().

Code Block
bgColor#FFcccc
langcpp
#include <algorithm>
#include <iostream>
#include <vector>
 
void f(const std::vector<int> &c) {
  std::vector<int>::const_iterator e;
  std::for_each(c.begin(), e, [](int i) { std::cout << i; });
}

...