any news on const/invariant?

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 29 12:38:55 PST 2007


"Walter Bright" wrote
> Invariant member functions: you argued these are unnecessary. I believe 
> they are, for exactly the same reason as any other invariant references 
> passed as parameters. Invariant is needed to support functional 
> programming, better code optimization, and more reliable multithreaded 
> code.

I believe pure functions are required to support functional programming and 
more reliable multithreaded code.  Given that an invariant function is 
allowed to change global state, it cannot be assumed that it is safe to 
reorder invariant function calls, cache results, or call multiple invariant 
functions without synchronization on multiple threads.  invariant as a 
*storage* attribute is required for pure functions and reliable 
multithreaded calls.

However, I think invariant functions would be good for optimization, as you 
can keep member data in registers between calls, etc.

-Steve 





More information about the Digitalmars-d mailing list