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

Christophe Travert travert at phare.normalesup.org
Thu Jun 14 03:20:39 PDT 2012


Artur Skawina , dans le message (digitalmars.D:169717), a écrit :
> 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

I don't see the problem. If T compiles with a static array, it returns a 
static array, there is no invalid pointer issue, since the returned 
value is not a slice, but a static array.

-- 
Christophe



More information about the Digitalmars-d mailing list