March 19, 2014
On Wednesday, 19 March 2014 at 04:10:21 UTC, Meta wrote:
> On Wednesday, 19 March 2014 at 01:56:35 UTC, Rikki Cattermole wrote:
>> Is an enum not appropriate? Because it can be used to push constants and available at ctfe.
>>
>> enum int[int] aa = [1: 2, 3: 4];
>> pragma(msg, aa);
>
> This will create a new associative array at runtime wherever aa is used, rather than creating only one instance at compile time and referring to it wherever aa is used. This is also the case with normal arrays, and possibly objects... I can't remember.

Okay, well I learnt something.
March 19, 2014
On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote:
> Rikki Cattermole:
>
>> Is an enum not appropriate? Because it can be used to push constants and available at ctfe.
>>
>> enum int[int] aa = [1: 2, 3: 4];
>> pragma(msg, aa);
>
> This is bad from an efficiency point of view. I think Don even suggested to disallow it.
>
> Bye,
> bearophile

It still only existing way to define compile-time usable AA value, disallowing it without fixing alternatives is not an option.
March 19, 2014
On Wednesday, 19 March 2014 at 09:12:53 UTC, Dicebot wrote:
> On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote:
>> Rikki Cattermole:
>>
>>> Is an enum not appropriate? Because it can be used to push constants and available at ctfe.
>>>
>>> enum int[int] aa = [1: 2, 3: 4];
>>> pragma(msg, aa);
>>
>> This is bad from an efficiency point of view. I think Don even suggested to disallow it.
>>
>> Bye,
>> bearophile
>
> It still only existing way to define compile-time usable AA value, disallowing it without fixing alternatives is not an option.

There might be another way depending on how good the compiler is at optimizing out pure functions.
Because in theory it'll only call it once (did test in this context). But I don't know how it handles it within memory.

@property pure int[int] test() {
	pragma(msg, "hit");
	return [1 : 2, 3 : 4];
}

pragma(msg, test);
pragma(msg, test);

hit
[1:2, 3:4]
[1:2, 3:4]
March 19, 2014
On Wednesday, 19 March 2014 at 09:12:53 UTC, Dicebot wrote:
> On Wednesday, 19 March 2014 at 02:52:23 UTC, bearophile wrote:
>> Rikki Cattermole:
>>
>>> Is an enum not appropriate? Because it can be used to push constants and available at ctfe.
>>>
>>> enum int[int] aa = [1: 2, 3: 4];
>>> pragma(msg, aa);
>>
>> This is bad from an efficiency point of view. I think Don even suggested to disallow it.
>>
>> Bye,
>> bearophile
>
> It still only existing way to define compile-time usable AA value, disallowing it without fixing alternatives is not an option.

The only thing I've said we should disallow, is creating a runtime reference to a value which only exists at compile-time. I think it is logically nonsensical.

I don't see any problem at all with creating a compile-time AA, and then looking up an index in it at compile time.

1 2
Next ›   Last »