streaming redux

Steven Schveighoffer schveiguy at yahoo.com
Mon Jan 3 12:22:38 PST 2011


On Mon, 03 Jan 2011 15:15:27 -0500, so <so at so.do> wrote:

> On Mon, 03 Jan 2011 14:58:22 +0200, Steven Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>
>> On Sat, 01 Jan 2011 10:59:47 -0500, so <so at so.do> wrote:
>>
>>>> This can be significantly shortened:
>>>>
>>>> write((&i)[0..1]);
>>>
>>> Wow, i didn't know that!
>>> Could you point me to doc, please?
>>>
>>> Thanks.
>>
>> http://www.digitalmars.com/d/2.0/arrays.html#implicit-conversions
>>
>> -Steve
>
> Thanks.
> I know those 3, but they don't have much to do with your example, or  
> most likely i didn't get it...

type of (&i)[0..1] is int[].  int[] is implicitly convertable to void[]  
per those rules, so there is no need to cast.

The original post implying that void[] would make things more difficult  
stated that with write taking a (void[]) argument instead of (void *,  
size_t length) you would have to write put like this:


void put(int i) {
	void *tmp = cast(void*)(&i);
	void[] arr = tmp[0..int.sizeof];
	write(arr);
}

But you do not need to do this, all you need is what I wrote (which is  
actually simpler I think than the void*, size_t function).

That was my point.  If there is something else you are looking for, maybe  
you can ask a different question?

-Steve


More information about the Digitalmars-d mailing list