static array literal syntax request: auto x=[1,2,3]S;

Artur Skawina art.08.09 at gmail.com
Mon Jun 11 03:39:04 PDT 2012


On 06/11/12 12:06, Christophe Travert wrote:
> Jonathan M Davis , dans le message (digitalmars.D:169705), a écrit :
>> auto found = find([1, 2, 3, 4, 5], 3);
> 
> No problem if the rule could be the following:
>  - array literals are static by default
>  - array literals are copied to the heap when assigned to a dynamic 
> array.
>  - the former rule applies even if the array literal is assigned to a 
> dynamic array via a function call, like it is the case in this example.
>  - if a function can take both static and dynamic array as parameter, 
> the static version takes precedence (it is always possible to call the 
> dynamic version via slicing, at your own risk since the array is no 
> longer valid at the end of the function call, or, much more wisely, by 
> explicitely using the .dup property).

T f(T)(T a) {}

artur


More information about the Digitalmars-d mailing list