toString refactor in druntime

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 3 17:47:47 PST 2014


On 11/3/14 8:16 PM, Walter Bright wrote:
> On 11/3/2014 2:33 PM, Steven Schveighoffer wrote:
>> On 11/3/14 4:40 PM, Walter Bright wrote:
>>> On 11/3/2014 8:09 AM, Steven Schveighoffer wrote:
>>>> It is a huge difference to say EVERYONE who implements toString will
>>>> take any
>>>> templated type that purports to be an output range, vs giving one case
>>>> to handle.
>>>
>>> All an output range is is a type with a 'put' method. That's it. You're
>>> making it out to be far more complex than it is.
>>>
>>
>> Directly from the docs:
>> (http://dlang.org/phobos/std_range.html#isOutputRange)
>>
>> void myprint(in char[] s) { }
>> static assert(isOutputRange!(typeof(&myprint), char));
>>
>> No 'put' in sight, except as a substring of isOutputRange.
>>
>> I don't think you realize what a beast supporting all output ranges
>> is, or using
>> them (hint: calling r.put for a generic output range is an ERROR).
>
> The documentation says, more specifically, that the requirement is that
> it support put(r,e). The array operands are output ranges NOT because
> the output ranges need to know about arrays, but because arrays
> themselves have a put() operation (as defined in std.array).

You can't import std.array from druntime.

>
> All the algorithm (such as a toString()) needs to do is call put(r,e).
> It doesn't need to do anything else. It isn't any more complicated than
> the sink interface.

Again, std.range.put isn't defined in druntime.

And neither is isOutputRange. Are you planning on moving these things to 
druntime?

-Steve


More information about the Digitalmars-d mailing list