const debacle

Neil Vice psgdg at swiftdsl.com.au
Mon Mar 24 06:17:53 PDT 2008


> "Janice Caron" <caron800 at googlemail.com> wrote:
> Broken, as you say, but *it's still not what's being asked for*.
> What's being asked for is
>
>    K(T)[] f(T)(const(T)[] a) { return cast(K(T)[]) a[X..Y]; }
>
> where K is the constancy of a at the caller site. I claim that I can
> prove that this is not fundamentally broken, and specifically that it
> does not violate const correctness.

Apologies... apparently Ctrl-Enter sends in my client O_o

My apologies if I misunderstand as I have not been following the discussion
at large but could you not implemented the desired template method using two
overloaded templates, differing only by the constness of the parameter and
return type?

i.e.

const(T)[] f(const(T)[] t) { ... }
T[] f(T[] t) { ... }

where you could share implementation if desired using something like:

T[] f(T[] t)
{
    return cast(T[]) f(const(T) t);
}

I should probably have attempted this before posting but it's late and after 
my previous half-post I want to get this out there =)





More information about the Digitalmars-d mailing list