www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Can const be inferred from invariant?

There was some discussion on whether const and invariant needed to be 
two separate keywords.  I believe that they do.  The reason is that they 
express different guarantees, and thus give the programmer the 
opportunity to demand the stronger or weaker guarantee. To wit:

void threadTask(const T* work)
{
    ...
}

void threadTask(invariant T* work)
{
    ...
}

In the first example, the thread doesn't need to lock access to work 
unless it needs a consistent read of different parts of work.  In the 
second example, access to work never needs to be locked.

If you took away one of the keywords and let the proper case be 
inferred, I would never be able to claim one of the guarantees and make 
the distinction between these two functions (which, for performance 
reasons, could be significant).

Dave
Mar 24 2007