Hi everyone !

Let's say I have a struct :

struct Test
{
        immutable (ubyte)[] data;

        T get(T)()
        {
                return *(cast(T*)(&(data[0])));
        }
}

This code will work :

import std.stdio;

void main()
{
        Test t;
        t.data = [152, 32, 64, 28, 95];
        float b = t.get!float;
        writefln("%s", b);
}

This won't compile :

import std.stdio;

void main()
{
        Test t;
        t.data = [152, 32, 64, 28, 95];
        float b = t.get;
        writefln("%s", b);
}

This neither:

import std.stdio;

void main()
{
        Test t;
        t.data = [152, 32, 64, 28, 95];
        float b = t.get!(typeof(b));
        writefln("%s", b);
}

And this will work:

import std.stdio;

void main()
{
        Test t;
        t.data = [152, 32, 64, 28, 95];
        float b;
        b = t.get!(typeof(b));
        writefln("%s", b);
}

Why can't dmd infere the type 'float' ? In fact this would allow a nicer syntax for the Json struct in vibe.d for example.

Reply via email to