Fully transitive const is not necessary

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Wed Apr 2 11:52:45 PDT 2008


Janice Caron wrote:
> (1) const does not guarantee thread safety
> (2) thread safety requires const guarantees

Steven is arguing that thread safety does not require transitive const
guarantees. 
It was already established that pure functions will not have access to
global variables. If you add the rule that pure functions cannot access the
mutable part of a const object, const and pure work together to provide
thread safety just as well as with fully transitive const.

That's where the examples comparing transitive const with global variables
to logical const with mutable members originated:

int x;
class C
{
  void foo() const { x++; } // const but can't be pure
  void bar() pure { /* automatically safe */ } 
}

versus

class C
{
  mutable int x;
  void foo() const { x++; } // const but can't be pure
  void bar() pure 
  { /* can't do anything in here you couldn't have done above */ }
}




More information about the Digitalmars-d mailing list