Library Typedefs are fundamentally broken

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 23 11:15:55 PDT 2014


On Tue, 23 Sep 2014 18:02:56 +0000
Meta via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

>      //Allowed?
>      money o = m * n;
>      assert(o == 20.0);
yes.

>      //Allowed?
>      money p = m * 2.0;
>      assert(p == 8.0);
no.

>      //Passes or fails?
>      assert(!isNaN(p.init));
passes, as it's 'dobule' descendant.

>      //Do typedef'd types inherit the properties
>      //of their base classes?
>      assert(p.min_normal == double.min_normal);
yes.

>      typedef float dollars = 0.0f;
>      typedef float cents = 0.0f;
> 
>      dollars d = 1.0f;
>      //Allowed?
>      cents c = d;
no.

>      cents c = cast(cents)d;
yes.

>      cents c = cast(float)d;
no.

>      //Allowed?
>      float f = d
>      float f = d - c;
>      float f = d - 1.0f;
no.

>      //Are these allowed? If so, what
>      //are the resultant types?
>      auto g = c * d;
>      auto h = d * 1.0f;
no.

>      typedef int index;
> 
>      int[] arr = [0, 1, 2];
>      index a = 1;
>      //Allowed?
>      assert(arr[a] == 1);
no.

>      index b = 4;
>      arr ~= b;
no.

my 0.05 dollars.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140923/5182ea02/attachment.sig>


More information about the Digitalmars-d mailing list