www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8264] New: [std.conv.to] constructing conversion doesn't work with alias this

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

           Summary: [std.conv.to] constructing conversion doesn't work
                    with alias this
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com



from
http://forum.dlang.org/thread/mailman.1606.1340038410.24740.digitalmars-d-learn puremagic.com#post-cetlbrtfhbtunchppikq:40forum.dlang.org

----
This kind conversions should be possible with std.conv.to.

import std.conv;
struct Wrap
{
    string wrap;
    alias wrap this;
}
void main()
{
    Wrap[] y = to!(Wrap[])(["foo", "bar"]);  // shold work
}

If you can construct Wrap object with the syntax Wrap("foo"), 
std.conv.to runs 'conversion by construction'.
And if S is convertible to T, std.conv.to!(T[])(S[] source) runs 
'element-wise array conversion'.
As a result, string[] to Wrap[] will be converted.

...but, this does not work in 2.060head, it is a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PDT ---
Is it really bug? What if you have

struct Wrap
{
    string wrap;
    int i;
    double d;
    string s;

    alias wrap this;
}

Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init,
string.init)? Or should it not work? Maybe it should work, but it seems a bit
funny to me to create a Wrap from just a string considering that the alias
doesn't define how to initialize the rest of the object.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264





 Is it really bug?
Yes. The problem is that declaring alias this is incorrectly matches more than two templates. If you remove 'alias wrap this' from Wrap type, the conversion will succeed.
 What if you have
 
 struct Wrap
 {
     string wrap;
     int i;
     double d;
     string s;
 
     alias wrap this;
 }
 
 Should Wrap("foo") create the same thing as Wrap("foo", int.init, double.init,
 string.init)? Or should it not work? Maybe it should work, but it seems a bit
 funny to me to create a Wrap from just a string considering that the alias
 doesn't define how to initialize the rest of the object.
I also it seems a bit funny, but it should work. std.conv.to supports constructing conversion based on _syntactic possibilities_ - like range interface: r.empty, r.front, and r.popFront(). I think such limitation provides no benefit. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



https://github.com/D-Programming-Language/phobos/pull/640

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/18564f4fa20bd7d3c66e0d37494d4305edb048fd
fix Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias
this

https://github.com/D-Programming-Language/phobos/commit/32d9b329057a01b5775c4cfdebc869f86ca0c691


Issue 8264 - [std.conv.to] constructing conversion doesn't work with alias this

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264




Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/2a3b0b0ffe12a25e5f0a1e9e5b6535a0a531cb33


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8264


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 20 2012