On Monday, June 11, 2012 04:47:36 Mehrdad wrote: > On Monday, 11 June 2012 at 02:25:54 UTC, Jonathan M Davis wrote: > > Now, since in this particular case, what find returns won't > > ever include anything from any arguments other than the first, > > it'll be fine. > > Yes, that's precisely why your statement didn't make sense to me. > > :) > : > > But for any templated function which returns a portion of its > > argument, having it take a static array for that argument would > > be horribly broken. For instance, > > > > auto found = find([1, 2, 3, 4, 5], 3); > > > > _would_ definitely return a slice which referred to garbage > > were array literals > > static and find accepted them. > > > Ah, that's a different example. :) > > > Hm... could you automatically convert the static arrays to > dynamic if the argument isn't 'scope'?
That would be at odds with how passing static arrays to functions works normally. Normally, they get sliced. But I don't get why you're so hung up on making array literals static. Having them be dynamic works great in every single case except when you specifically want to be assigning them to a static array. In that case, you get an unnecessary array allocation, which we definitely don't want. However, all it takes is for the compiler to see that you're assigning an array literal to a static array and skip the allocation. That particular use case is then fixed, and all of the rest of them continue to work just fine. What are you trying to fix beyond assignments to static arrays with array literals? - Jonathan M Davis