A "general" tag

Aleksandar Ružičić" <aleksandar at ruzicic.info> Aleksandar Ružičić" <aleksandar at ruzicic.info>
Sat Apr 14 12:40:05 PDT 2012


On Saturday, 14 April 2012 at 19:17:52 UTC, Xan wrote:
> Hi,
>
> I try to translate a script I wrote in Fantom [www.fantom.org]. 
> In my script, I have a type "Tag" defined as a triple of:
> - String (the name of the tag),
> - Type (the type of the tag: could be Str, Date, Int, etc.)
> - Obj (the value of the tag; Fantom has Objects of Top-Class 
> hierachy).
>
> (normally the tag has Type = Obj.Type, but you can manually 
> set).
>
> For example,
> you could have:
> (name, Str#, "John")
>
> or
>
> (date, Date#, 2011-09-02)
>
>
> (# is the Fantom way for specifying type: Str# is the sys::Str 
> type)
>
>
> Is there any way for emulating this? My main trouble is how to 
> define Type and Object in D.
>
> Thanks in advance,
> Xan.
>
> PS: Please, be patient, I'm a newbee.


For "Type" look at enum (http://dlang.org/enum.html) and for 
"Object" look at std.variant 
(http://dlang.org/phobos/std_variant.html).

And since Variant can tell you what type it contains you might no 
longer need that "Type" parameter.


More information about the Digitalmars-d-learn mailing list