www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8851] New: std.string.join should allow 'char' as joiner

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

           Summary: std.string.join should allow 'char' as joiner
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-10-18
15:26:25 PDT ---
import std.string;

void main()
{
    char sep = '|';
    string z = ["foo", "bar"].join(sep);
}

test.d(7): Error: template std.array.join does not match any function template
declaration
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\array.d(1273): Error: template
std.array.join cannot deduce template function from argument types
!()(string[],char)

Well apparently it's std.array.join, but nevertheless it should work.

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


Jonathan M Davis <jmdavisProg gmx.com> changed:

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


--- Comment #1 from Jonathan M Davis <jmdavisProg gmx.com> 2012-10-18 16:17:08
PDT ---
I expect that this stems from the stupidity of character literals defaulting to
char rather than dchar, and when you couple that with the fact that templates
always use the _exact_ type of what you give them, it's going to try and
instantiate join with a separator of char, which doesn't work with ranges of
dchar. I'm not sure how you'd go about fixing that.

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


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #2 from monarchdodra gmail.com 2012-10-19 02:36:28 PDT ---
(In reply to comment #1)
 I expect that this stems from the stupidity of character literals defaulting to
 char rather than dchar, and when you couple that with the fact that templates
 always use the _exact_ type of what you give them, it's going to try and
 instantiate join with a separator of char, which doesn't work with ranges of
 dchar. I'm not sure how you'd go about fixing that.

I investigated, and that's not it. It's *just* that std.array.join, like std.algorithm.joiner, expects the separator to be a range. The enhancement request here would be for both "std.array.join" std.algorithm.joiner" to accept a single element as a separator. In the meantime, of course, a simple workaround is to just "join([sep])". I think this needlessly allocates a 1 element array though, no? -------- On a side note, the current restrictions in join are overly restrictive, requiring an exact match, making this illegal: int[] sep = [1]; double[] z = [[0.1], [0.2]].join(sep); When it is perfectly supported: joiner supports it. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8851



--- Comment #3 from monarchdodra gmail.com 2012-10-19 02:39:28 PDT ---
(In reply to comment #1)
 I expect that this stems from the stupidity of character literals defaulting to
 char rather than dchar, and when you couple that with the fact that templates
 always use the _exact_ type of what you give them, it's going to try and
 instantiate join with a separator of char, which doesn't work with ranges of
 dchar. I'm not sure how you'd go about fixing that.

I investigated, and that's not it. It's *just* that std.array.join, like std.algorithm.joiner, expects the separator to be a range. The enhancement request here would be for both "std.array.join" std.algorithm.joiner" to accept a single element as a separator. In the meantime, of course, a simple workaround is to just "join([sep])". I think this needlessly allocates a 1 element array though, no? -------- On a side note, the current restrictions in join are overly restrictive, requiring an *exact* ElementType match, making this illegal: int[] sep = [1]; double[] z = [[0.1], [0.2]].join(sep); The implementation actually perfectly supports it. As a matter of fact, joiner supports it. I'll see into relaxing the restraints for now, and taking the opportunity to investigate using an element as a separator. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 19 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8851


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody puremagic.com        |monarchdodra gmail.com


--- Comment #4 from monarchdodra gmail.com 2012-10-19 02:45:07 PDT ---
(In reply to comment #3)
 (In reply to comment #1)
 I expect that this stems from the stupidity of character literals defaulting to
 char rather than dchar, and when you couple that with the fact that templates
 always use the _exact_ type of what you give them, it's going to try and
 instantiate join with a separator of char, which doesn't work with ranges of
 dchar. I'm not sure how you'd go about fixing that.

I investigated, and that's not it. It's *just* that std.array.join, like std.algorithm.joiner, expects the separator to be a range. The enhancement request here would be for both "std.array.join" std.algorithm.joiner" to accept a single element as a separator. In the meantime, of course, a simple workaround is to just "join([sep])". I think this needlessly allocates a 1 element array though, no? -------- On a side note, the current restrictions in join are overly restrictive, requiring an *exact* ElementType match, making this illegal: int[] sep = [1]; double[] z = [[0.1], [0.2]].join(sep); The implementation actually perfectly supports it. As a matter of fact, joiner supports it. I'll see into relaxing the restraints for now, and taking the opportunity to investigate using an element as a separator.

That was fast actually. Both the fix and the enhancement are trivially trivial. I believe in the change, so I'm assigning to self. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 19 2012