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