Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot (jp)

...

Code Block
bgColor#FFcccc
double data[5] = { 2.3, 3.7, 1.4, 0.8, 9.6 };

deque<double>deque&lt;double&gt; d;
deque<double>deque&lt;double&gt;::iterator pos = d.begin();

for (size_t i = 0; i <&lt; 5; ++i) {
  d.insert(pos++, data[i] + 41);
}

...

Code Block
bgColor#ccccff
double data[5] = { 2.3, 3.7, 1.4, 0.8, 9.6 };

deque<double>deque&lt;double&gt; d;
deque<double>deque&lt;double&gt;::iterator pos = d.begin();

for (size_t i = 0; i <&lt; 5; ++i) {
  pos = d.insert(pos, data[i] + 41);
  ++pos;
}

...

Code Block
bgColor#ccccff
double data[5] = { 2.3, 3.7, 1.4, 0.8, 9.6 };
deque<double>deque&lt;double&gt; d;

transform(data, data+5,
    inserter(d, d.begin()),
    bind2nd(plus<int>plus&lt;int&gt;(), 41));

Risk Assessment

Using invalid iterators yields undefined results.

...

Wiki Markup
\[[ISO/IEC 14882-2003|AA. C++ References#ISO/IEC 14882-2003]\] Section 24: Iterators Library.

...

12. Vectors (VEC)      14. Templates and the STL (TPL)      STL31-C. Use Valid Iterator Ranges