www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24610] New: Basic range-based `toString` not recognized

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

          Issue ID: 24610
           Summary: Basic range-based `toString` not recognized
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

import std.array;
import std.format;

struct S
{
    void toString(Output)(ref Output output)
    {
        import std.range: put;
        output.put("S");
    }
}

void main()
{
    S s;
    auto output = appender!(char[]);
    s.toString(output);
    assert(output[] == "S"); // ok

    output.clear();
    formattedWrite!"%s"(output, s);

    import std.stdio;
    assert(output[] == "S"); // fail
}

The `toString` is implemented according to the spec
(https://dlang.org/phobos/std_format_write.html), and the formatter should use
it.

--
Jun 16