dmd 2.029 release

Simen Kjaeraas simen.kjaras at gmail.com
Fri Apr 24 06:27:41 PDT 2009


grauzone wrote:

>>>>>> void streamOut(T, R)(T object, R range)
>>>>>> {
>>>>>>     foreach(x; a) range.put(x);
>>>>>>     range.put(b);
>>>>>>     range.put(c);
>>>>>> }
>
> So, um... what is a b c and T object?

In my opinion, this is a confusing example. I believe it was meant to be:

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

So, streamOut is a free function, which it normally would not be. Now, consider this:

struct foo {
  int[] a;
  bool b;
  char c;

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

I believe this is what you'd normally do.

Do note that I might have misinterpreted it all, as Andrei's code would not do what I have outlined above, I only feel it makes the most sense.

--
  Simen


More information about the Digitalmars-d-announce mailing list