Tuples and compile-time assigned properties

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Sep 19 07:40:45 PDT 2013


Hello all,

This is a query that relates to my Dgraph library:
https://github.com/WebDrake/Dgraph

When simulating graphs/networks, very often you want the vertices or edges to 
have certain properties.  For example, the edges may have weights, or the 
vertices may be coloured.

The current implementation doesn't allow for this, and I'm trying to find an 
appropriate solution to allow at compile time to specify the various properties.

The thought that's currently running through my head is to do this with Tuples 
where the variable names are all specified, e.g.

     alias EdgeProperties = Tuple!(double, "weight");

     alias VertexProperties = Tuple!(size_t, "colour", string, "name");

So then, you'd be able to extract the list of variable names and types at 
compile time and use them to create the underlying data structures required; and 
similarly you'd be able to create a set of public interfaces that gives you 
access to those members.

With that in mind, there are a number of potential issues that arise:

    (i) is there a compile-time constraint via which I can insist that every
        member of the tuple must be named?

   (ii) is there an easy way to extract all the names of tuple members as an
        array of strings?

Can anyone advise?

Thanks & best wishes,

     -- Joe


More information about the Digitalmars-d-learn mailing list