On Tuesday, 29 May 2012 at 17:35:12 UTC, Michel Fortin wrote:
On 2012-05-29 15:09:00 +0000, Artur Skawina
<art.08...@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.
it would be elegant to reuse 'in', but is it too error-prone?
int[10] tmp;
int* ptr = &tmp[4];
if(ptr in tmp) // O(1), i.e. ok.
{
}