Overhauling the notion of output range

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jul 13 08:05:59 PDT 2010


On 07/13/2010 06:15 AM, Steven Schveighoffer wrote:
> On Mon, 12 Jul 2010 22:58:07 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> Actually a char[] is not a valid output range. Overwriting
>> variable-length codes with other variable-length codes might mess up
>> the string.
>
> Hm... I think it should be, and here is why. Imagine this situation:
>
> char[1024] buffer = void; // allocate some blank space on the stack
> put(buffer, someInputRange);
>
> But the above won't compile anyways, because a ref char[1024] isn't a
> range, and even if it was, it would be left in a state where it pointed
> to the uninitialized data. What we need is a helper struct, and then we
> are covered.
>
> char[1024] buffer = void;
> CharBuilder builder(buffer[]); // defines put
> put(builder, someInputRange);
>
> So I think we are good. Does Appender work here?

Appender doesn't currently work with fixed-size buffers, but it could 
and should be made to work. It's a good idea.

Andrei


More information about the Digitalmars-d mailing list