opDispatch, duck typing, and error messages
spir
denis.spir at gmail.com
Fri Apr 22 02:29:44 PDT 2011
On 04/22/2011 03:53 AM, Robert Jacques wrote:
> On Thu, 21 Apr 2011 18:24:55 -0400, Adam D. Ruppe <destructionator at gmail.com>
> wrote:
> [snip]
>> Or, there's a whole new approach:
>>
>> e) Duck typing for ranges in to!() might be a bad idea. Again, remember,
>> a class might legitimately offer a range interface, so it would
>> trigger this message without opDispatch.
>>
>> If ranges are meant to be structs, maybe isInputRange should check
>> is(T == struct)? This doesn't sit right with me though. The real
>> problem is to!() - other range functions probably don't overload
>> on classes separately than ranges, so it won't matter there.
>>
>>
>> I think the best thing to do is simply to prefer Object over range.
>>
>> toImpl(T) if (isInputRange!(T) && (!is(T : Object)))
>>
>> Or something along those lines. Why? If the object has it's own
>> toString/writeTo methods, it seems fairly obvious to me anyway that
>> to!string ought to simply call them, regardless or what else there is.
>
> There's actually a bug report regarding the toString vs range semantics issue,
> it's issue 5354 ( http://d.puremagic.com/issues/show_bug.cgi?id=5354 ). Also
> note that classes (but not structs as of yet, see bug 5719) can provide their
> own to!T conversions.
>
> However, what you ran into deserves a new bug report, since to!string should
> always be able to fall back to toString and it didn't.
>
Agreed. A programmer who defines toString *means* it to be used for conversion
to string (esp. for write* funcs). Please support and vote for this bug ;-)
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list