dmd 2.029 release

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 23 08:49:19 PDT 2009


On Thu, 23 Apr 2009 10:30:15 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Daniel Keep wrote:
>>  Andrei Alexandrescu wrote:
>>> Steven Schveighoffer wrote:
>>>> On Thu, 23 Apr 2009 09:24:59 -0400, Andrei Alexandrescu
>>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>>
>>>>> Steven Schveighoffer wrote:
>>>>>> This has to go into object.d and be part of the runtime, where
>>>>>> std.range doesn't exist.  There is nothing stopping you from  
>>>>>> calling:
>>>>>>  streamOut(&outputrange.put);
>>>>>>  So I'd rather have a sink function.
>>>>> It must be a sink _object_ so it can hold its own state. And it must
>>>>> support put() so it integrates with statically-bound output ranges.
>>>>>
>>>>> interface OutRange
>>>>> {
>>>>>      void put(... a number of overloads ...);
>>>>> }
>>>> I see now, yes I agree (I think that was don's original request
>>>> anyways).  That interface has to go in the runtime, though.
>>>>
>>>> We may not be able to do this using templates... it has to be a
>>>> virtual function in Object to be on-par with toString.  This means
>>>> struct interfaces are a requirement if you want to use ranges :(
>>> We're in good shape actually. OutRange as a dynamic interface and an
>>> implicit interface using .put against a struct will work just as well
>>> with templates. (The template doesn't care whether obj.put(x) is a
>>> virtual call or statically-bound call.)
>>>
>>> Andrei
>>  "We may not be able to do this using templates... it has to be a  
>> virtual
>> function in Object to be on-par with toString."
>>  Note that toString is a virtual method.  You are proposing replacing
>> toString with a template.  You cannot have virtual template methods.
>> Ergo, "new toString" would be inaccessible without the actual type, and
>> certainly not at runtime.
>
> The toStream that I have in mind is virtual and takes an interface of  
> type OutRange as outlined above.

OK, that's fine, I was working off your original proposal:

void streamOut(R)(R range)
{
      foreach(x; a) range.put(x);
      range.put(b);
      range.put(c);
}

Of course, this then eliminates structs from being OutRange's without  
having struct interfaces.  As most ranges are structs (and rightfully so,  
who wants to call 3 virtual functions every loop!), they would have to be  
wrapped under the current compiler. Or am I missing something else?

-Steve


More information about the Digitalmars-d-announce mailing list