TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  CFL#021Checked automatically with code checker

This rule is Obsolete
Synopsis:Use prefix instead of postfix versions of ++ and -- operators for non-simple types
Severity Level:8
Category:Control Flow


Especially in non trivial iterator types, the prefix versions of the ++ and -- operators are more efficient than the postfix versions. Only use the postfix version when you actually need to use the previous value.

        set<CClass1> set1;
        set<CClass1>::iterator theEnd = set1.end();

        // use ++i, not i++
        for (set<CClass1>::iterator i = set1.begin(); i != theEnd; ++i)
            // Do something with *i

Note that a pointer is indeed a simple kind of iterator where usually no significant performance difference will exist between the prefix and postfix versions.

Other simple types are the built-in character types, integer types, floating point types and enumerations.