www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10006] New: Implicit conversion in initializers doesn't work for subtypes

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10006

           Summary: Implicit conversion in initializers doesn't work for
                    subtypes
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



03:30:47 PDT ---
-----
struct S
{
    float value = 0.0;
    alias value this;
}

float f = 250.0;  // ok
S s = 250.0;  // ng

void main() { }
-----

Error: cannot implicitly convert expression (250.000) of type double to S

I think the above should work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10006




03:32:28 PDT ---
This does give me an idea for a DIP:

struct S
{
    float value = 0.0;
    alias value this;

    // called only when a *literal* is provided
    this(enum double val) { }
}

This would enable creating custom implicit conversions when initializing a
struct with a literal of some sort.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 29 2013