On Thu, 02 Dec 2010 22:17:53 -0500, Andrei Alexandrescu <[email protected]> wrote:

On 12/2/10 6:54 PM, Simen kjaeraas wrote:
Michel Fortin <[email protected]> wrote:

I'm not sure I get the problem. Can you show me in code?

const a = map!"a+a"( [1,2,3] );

foreach ( e; a ) {
}

The foreach fails because popFront is not const. What is needed is for
typeof(a) to be Map!("a+a", const(int)[]). IOW,
is( const(Map!("a+a", int[])) == Map!("a+a", const(int)[]) ).

One possible way to do this is for all types T to have defined types
immutable_t and const_t, which by default alias to immutable(T) and
const(T), but can be defined to alias to other types. The compiler
would then automagically convert cast(const)T to cast(T.const_t)T.

Well the code asks for a constant object, and I don't see it as reasonable for the type system to automagically infer the intent. What should work is this:

const(int)[] data = [1,2,3];
auto a = map!"a+a"(data);
foreach (e;a) {
}

Now, change data to an SList range. This is what I'm talking about. Arrays already enjoy the benefits of tail-const, I want to extend that to all range types (and in fact all struct types).

-Steve

Reply via email to