Supertypes, subtypes, and more

Tofu Ninja via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 25 14:44:48 PDT 2014


On Wednesday, 25 June 2014 at 20:59:00 UTC, Justin Whear wrote:
> On Wed, 25 Jun 2014 15:33:14 +0000, bearophile wrote:
> 
>> I think where you expect a String you can send a 
>> Social_Security_Number,
>> but where it expects a Social_Security_Number it doesn't 
>> accept a
>> String. (The Dynamic_Predicate and Static_Predicate of modern 
>> Ada allow
>> to perform such restrictions.) So I think there are some 
>> analogies with
>> OOP.
>> 
>> I'd like to do something like this in D, with structs/values.
>> 
>> Bye,
>> bearophile
>
> Does this do everything you're looking for?
> http://dpaste.dzfl.pl/50531f5b1356
>
> The only potential problem I see is that the invariant 
> presumably won't
> be compiled in when in release mode.

Now if only we could get that to work with more than one type, 
such that we could have subtype implicitly convertible to more 
than one type.


More information about the Digitalmars-d mailing list