One case of array assignments
monarch_dodra
monarchdodra at gmail.com
Tue Mar 19 00:18:26 PDT 2013
On Monday, 18 March 2013 at 22:59:58 UTC, Timon Gehr wrote:
> On 03/18/2013 11:52 PM, monarch_dodra wrote:
>> On Monday, 18 March 2013 at 22:33:17 UTC, Timon Gehr wrote:
>>> On 03/18/2013 10:45 PM, monarch_dodra wrote:
>>>> ...
>>>>
>>>> ubyte[4096] x = repeat( cast(ubyte)0 )[ 0 .. 4096 ].array();
>>>>
>>>> This can be used as-is inside normal code. Hwoever, array is
>>>> not
>>>> CTFE-able, so it can't work to define a struct T.init value.
>>>
>>> Which is annoying and should be fixed.
>>
>> Making array work with CTFE is a no-go, as array's job is to
>> run-time
>> allocate a new array.
>>
>
> Uh. Its job is to collect a range into an array. Implementation
> details are irrelevant.
Yes, you are right. For a few seconds I though that all
allocations were banned in CTFE, but it's actually hand made
allocation that don't work.
>> Now, if we had "staticArray(R, Sizes)(R)" transforms a range
>> into an
>> array whose size is know at compile time, then that's another
>> story.
>> It'd be more efficient at run-time, and CTFE-able
>>
>
> Sizes should go first.
Hum, I had meant: "staticArray(R, Sizes...)(R)" in case you
wanted a multidim array.
I'm not 100% sure if putting Sizes... before R mixes well.
>> 1) Do we want such a weird and specific function? Or is that
>> just
>> premature optimization? I mean, is there a real need?
>
> Use 'copy'.
Yes, but unfortunately, using 'copy' entails first declaring the
variable, then copying to it, which defeats what we're trying to
achieve.
That said, I investigated array, and just got it to work :) And
it was trivial, so I'll push it.
More information about the Digitalmars-d
mailing list