c++ - Clarification on postfix/prefix operators on iterators -


in accelerated c++ andrew koenig writes following code introduction templates , generic functions. code skip first element in container? or copy first iterator object before incrementing:

template<class in, class out> out copy(in begin, in end, out dest) { while (begin != end)     *dest++ = *begin++; return dest; } 

in other words, behave code?:

template<class in, class out> out copy(in begin, in end, out dest) { while (begin != end)     *dest = *begin;     dest++;  begin++; return dest; } 

post incrementing iterator (or else matter) may confusing doing pretty straight forward. makes copy of value, increments original , returns copy. location being referred "*dest++" same "*dest", difference after statement finishes dest refer next iteration in iteratable.

the problems arise when programmers use incremented variable repeatedly in same expression. (which used brain teaser , resulting effect varies language language)


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -