www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Lossless Bidirectional Enum-Conversions Mixin

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
Have anybody come up with some mixin magic that given

     enum A { x,y,z }
     enum B { a,b,c }

and call to a mixin

BidirectionalEnums(
     "x", "a",
     "y", "b",
     "z", "c",
);

generates two to!Enum overloads that implement bidirectional 
(lossless) conversion rules between A and B?
Sep 07 2014
parent =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
On Sunday, 7 September 2014 at 17:22:38 UTC, Nordlöw wrote:
 BidirectionalEnums(
     "x", "a",
     "y", "b",
     "z", "c",
 );
The enumeration names must of course be given aswell: BidirectionalEnums2( "A", "B", "x", "a", ... ); and two specifies the number of enums involved. We could of course also use BidirectionalEnums( tuple("A", "B"), tuple("x", "a"), ... ); for more verbosity.
Sep 07 2014