Pointer semantics in CTFE
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 30 07:44:37 PDT 2012
On Tue, 29 May 2012 13:35:12 -0400, Michel Fortin
<michel.fortin at michelf.com> wrote:
> On 2012-05-29 15:09:00 +0000, Artur Skawina <art.08.09 at gmail.com> said:
>
>> int a[1024];
>> int[] da = a[0..1024];
>> if (whatever)
>> da = da[3..14];
>> if (something_else)
>> da = [42] ~ da;
>> // etc
>> if (da_is_a_slice_of_a())
>> still_inside_a();
>> How do you implement da_is_a_slice_of_a()?
>
> Indeed, for that to work you'd still need to handle this case specially.
> My bad for not catching that.
>
> Personally, I think it'd be much cleaner to go with some kind of magic
> function than trying to match the condition against a predefined
> pattern. Something like da.isSliceOf(a), which could do the usual
> pointer thing at runtime and call some sort of CTFE intrinsic at
> compile-time.
That doesn't help when most code does not use this today. I.e. one of the
main benefits of ctfe is that you don't *have* to write special code.
-Steve
More information about the Digitalmars-d
mailing list