Use template functions within mixin

Timoses via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 6 08:00:50 PDT 2017


Hey there,

I'm wondering how I can use a template function within my mixin:

```
                 ubyte[] value = x[33, 3a,3f, d4];
                 foreach (type; TypeTuple!("int", "unsigned int", 
"byte"))
                 {
                     mixin(`if (value.length == type.sizeof)
                             {
                                 ubyte[type.sizeof] raw = 
value[0..$];
                                 auto fValue = 
raw.littleEndianToNative!(type);
                                 displayinfo(fValue);
                             }
                             break;
                         `);
                 }
```


Error: template std.bitmanip.littleEndianToNative cannot deduce 
function from argument types !("int")(ubyte[8]), candidates are:
[..]\src\phobos\std\bitmanip.d(2560,3):        
std.bitmanip.littleEndianToNative(T, uint n)(ubyte[n] val) if 
(canSwapEndianness!T && n == T.sizeof)

```
`raw.littleEndianToNative!` ~ type ~ `;`
```

neither works..

Any way to accomplish this?


More information about the Digitalmars-d-learn mailing list