Creating new types from tuples.

Evan Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 6 16:44:03 PDT 2014


Hello,

I'm looking to use the Tuple type as a way of generating types to 
represent data in a send recieve connection pair. I created a 
template to try this:


template s_to_c(UDP packetType) {
          static if (packetType == UDP.ping) {
     alias Tuple!() s_to_c;
   } else static if (packetType == UDP.connect) {
     alias Tuple!(byte) s_to_c;
   } else static if (packetType == UDP.keep_alive) {
     alias Tuple!() s_to_c;
   }
}

(UDP is a enum with packet types.)

This works, but it also means that s_to_c(UDP.ping) is the same 
type as s_to_c(UDP.keep_alive). I want to be forced to 
distinguish between types, even if they contain the same fields, 
so that

recieve(
   (s_to_c!(UDP.ping) value) { },
   (s_to_c!(UDP.keep_alive) value) { }
)

isn't an error.

Any suggestions are welcome, and thanks for any help,

-Evan Davis


More information about the Digitalmars-d-learn mailing list