Use template functions within mixin

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 6 11:08:52 PDT 2017


Just import modules at local scopes. Here is something that works:

void displayinfo(T)(T v) {
     import std.stdio : writefln;
     writefln("%08x", v);
}

void foo() {
     import std.meta : AliasSeq;

     enum value = cast(ubyte[])x"33 3a 3f d4";
     foreach (type; AliasSeq!(int, uint, byte)) {
         static if (value.length == type.sizeof) {
             import std.bitmanip : littleEndianToNative;

             pragma(msg, "working with " ~ type.stringof);

             ubyte[type.sizeof] raw = value;
             auto fValue = raw.littleEndianToNative!type;
             displayinfo(fValue);
             break;
         }
     }
}

void main() {
     foo();
}

Ali



More information about the Digitalmars-d-learn mailing list