Disallow implicit "conversion" from alias-types

Vladimirs Nordholm v at vladde.net
Tue Nov 10 11:38:30 UTC 2020


Hello.

I am unsure if I am going about this the right way, and if my 
question even makes sense.

In essence what I want is to have two "types" represented by a 
size_t. Here is an example of what I want think I want (but might 
be completely off)

     alias Foo = size_t;
     alias Bar = size_t;

     Foo foo = 4;
     Bar bar = foo; // i want some error like
                    // "cannot implicitly convert from type Foo to 
Bar"

My best solution is to have the types as classes to force type 
checking.

Is there a better way to do what I want here?


More information about the Digitalmars-d-learn mailing list