Template argument deduction
Tom
tom at nospam.com
Wed Mar 2 12:45:17 PST 2011
El 01/03/2011 16:05, Ali Çehreli escribió:
> On 02/28/2011 07:39 PM, Tom wrote:
>
> > foo([[1,2],[3,4],[5,6]]); // ERROR [1]
> > bar([[1,2],[3,4],[5,6]]); // OK
> > foo!int([[1,2],[3,4],[5,6]]); // OK
>
> ...
>
> > void foo(T)(T[2][] t) {
> > writeln(typeid(t));
> > }
> >
> > void bar(T)(T[][] t) {
> > writeln(typeid(t));
> > }
>
> On 03/01/2011 04:30 AM, bearophile wrote:
>
> > Ali Çehreli:
> >
> >> That's because the type of literals like [1, 2] are slices (dynamic
> >> arrays), not fixed-sized arrays.
> >
> > Then why is this accepted?
> >
> > foo!int([[1,2],[3,4],[5,6]]); // OK
>
> If I have to guess, I think supplying T as int now becomes a problem of
> matching [1,2] with int[2] and it already works:
>
> int[2] a = [1, 2];
> int[2][] b = [ [1, 2] ];
>
> I don't know whether the compiler should go the extra mile and help Tom
> in the original case. :-/
>
> Ali
>
I should post on D newsgroup. Perhaps Walter or Andrei could enlight us
about this.
Thanks,
Tom;
More information about the Digitalmars-d-learn
mailing list