Request: a more logical static array behavior

Artur Skawina art.08.09 at gmail.com
Thu Aug 15 06:53:06 PDT 2013


On 08/15/13 14:44, Tommi wrote:
[...]
> No, I'm not asking A -> C, I'm just asking that int[3] convert to int[].

>From you earlier post:

  Ret bar(R)(R r) // [6]
  if (std.range.isInputRange!R)
  {
      return Ret.input_range;
  }

You'd like to be able to call 'bar' with a static array. Currently
you can't, because 'R' becomes a /static array/, hence not a input range.

Note that

  Ret baz(R)(R[] r) // [6]
  if (std.range.isInputRange!(R[]))
  {
      return Ret.input_range;
  }

/would/ work. This case works, because 'baz' expects a dynamic array
and static arrays implicitly convert to dynamic ones - so if there is
no better fitting overload then the static->dynamic conversion will be
done.

To make your case work, it would be necessary to first deduce R==int[3],
then try instantiating the template, and if this fails retry with whatever
int[3] implicitly converts to (int[] in this case).
The only alternative is making the static->dynamic array conversion
/mandatory/ when deducing types - which is not a good idea either.

The implicit int[3] -> int[] conversion should not exist.

artur


More information about the Digitalmars-d mailing list