[Issue 8851] std.string.join should allow 'char' as joiner

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Sep 12 04:09:47 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=8851

--- Comment #15 from monarchdodra at gmail.com ---
(In reply to Andrej Mitrovic from comment #14)
> import std.string;
> 
> void main()
> {
>     char sep = '|';
>     string z = ["foo", "bar"].join(sep.only);
> }

I'll assume you also imported std.range, and got this error?
Error: template std.array.join cannot deduce function from argument types ...

It seems the issue here is that the template restrictions are overzealous in
that it checks for exact element type matching, rather than checking if they
have a common type (Or at the very least, if ElementType!Sep is implicitly
convertible to ElementType!(ElementType!RoR)).

As a workaround, using an (explicit) dchar only works.

//----
import std.range;
import std.stdio;

void main()
{
    ["foo", "bar"].join(dchar('|').only).writeln();
}
//----

So Jonathan's original
assesment(https://issues.dlang.org/show_bug.cgi?id=8851#c1) was also correct
(it's a dual issue I guess)

--


More information about the Digitalmars-d-bugs mailing list