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) {
}

Andrei

Reply via email to