Another Transitive const solution
Craig Black
cblack at ara.com
Wed Apr 9 07:19:02 PDT 2008
> Goals of transitive const
> 1. To make the compiler able to perform optimisations based on const.
> 2. To make a documenting const system that is checked by the compiler and
> useful to the programmer.
>
> Goal 1 is not achievable as has been shown previously in this group :
Correct me if I'm wrong, but I read in an article that there are simple
optimizations that can be performed by C++ compilers using const. For
example this is preferred:
const int size = container.size();
for(int i = 0; i < size; i++) { ... }
rather than this:
int size = container.size();
for(int i = 0; i < size; i++) { ... }
Because it gives the compiler assurance to know that the size will not
change during the loop.
-Craig
More information about the Digitalmars-d
mailing list