toString refactor in druntime
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Sat Nov 8 07:12:43 PST 2014
On 11/8/14 5:25 AM, John Colvin wrote:
> On Monday, 3 November 2014 at 16:02:23 UTC, Steven Schveighoffer wrote:
>> On 10/31/14 3:07 PM, H. S. Teoh via Digitalmars-d wrote:
>>> x.toString((const(char)[] data) { outputRange.put(data); });
>>
>> No, please don't do that. It's put(outputRange, data);
>>
>
> Why?
import std.range;
struct ORange
{
void put(char) {}
}
static assert(isOutputRange!(ORange, char));
void main()
{
char[] buf = "hello".dup;
ORange r;
//r.put(buf); // fails
put(r, buf); // works
}
I have said before, making the UFCS function the same name as the member
hook it uses was a bad anti-pattern. Now, you must always use the
non-UFCS version of put, which sucks.
-Steve
More information about the Digitalmars-d
mailing list