Why function template 'among' is of complexity O(1) and not O(n)?
anonymous at example.com
Fri Feb 21 06:36:13 PST 2014
On Thursday, 20 February 2014 at 13:40:38 UTC, anonymous wrote:
> When a
> value is needed at compile time (e.g. initializer for a static
> variable, length of a static array), then CTFE is forced. When
> the value is not needed at compile time, the optimizer may go
> it, but that's not guaranteed.
On Thursday, 20 February 2014 at 21:23:08 UTC, anonymous wrote:
> On Thursday, 20 February 2014 at 17:08:11 UTC, Jakob Ovrum
>> On Thursday, 20 February 2014 at 13:40:38 UTC, anonymous wrote:
>>> When the value is not needed at compile time, the optimizer
>>> may go for it, but that's not guaranteed.
>> That's not really true. The optimizer will never try CTFE
>> because of the halting problem. Runtime is runtime,
>> compile-time is compile-time - they are clearly separated by
>> the context of the expression alone.
> LDC does it. The halting problem just dictates that it can't be
> done in all cases.
While it's evaluation at compile time, that optimization should
not be called "CTFE". The way I had worded it, it sounded like
__ctfe may or may not be true, depending on the optimizer's mood.
That's not so, of course.
More information about the Digitalmars-d-learn