www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Conversion and Assignment on EnumUnion and EnumChain

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
I've put up a module 
https://github.com/nordlow/justd/blob/master/enums.d

that provides two type constructors

- EnumChain
- EnumUnion

that can be used to combine names or names-and-values from one or 
more enums.

I would now like to define rules for assignments and implicit 
conversions with the following checks

- Assignment to EnumUnion, EnumChain from its parts is always 
nothrow.
- Assignment from EnumUnion, EnumChain to its parts may throw.

to emulate Ada's subtype.

Is it currently possible to implement any of these?

Also do you think the namings EnumChain and EnumUnion are correct?
May 03 2014
parent =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
 I would now like to define rules for assignments and implicit 
 conversions with the following checks
I believe I found a good solution through struct wrappers. See update at: https://github.com/nordlow/justd/blob/master/enums.d
May 04 2014