digitalmars.D - Can const be inferred from invariant?
- David B. Held (20/20) Mar 24 2007 There was some discussion on whether const and invariant needed to be
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