Implementing typestate

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 16 08:57:12 PDT 2015


On Wednesday, 16 September 2015 at 15:34:40 UTC, Idan Arye wrote:
> Move semantics should be enough. We can declare the destructor 
> private, and then any code outside the module that implicitly 
> calls the d'tor when the variable goes out of scope will raise 
> a compilation error. In order to "get rid" of the variable, 
> you'll have to pass ownership to the `close` function, so your 
> code won't try to implicitly call the d'tor.

Sounds plausible, but does this work in C++ and D? I assume you 
mean that you "reinterpret_cast" to a different type in the 
close() function, which is cheating, but ok :).



More information about the Digitalmars-d mailing list