constancy and template parameters in D2.009+

Janice Caron caron800 at googlemail.com
Thu Dec 13 02:52:10 PST 2007


That said, it occurs to me that (U, T=const(U)) is itself not the best
syntax, because it suggests that T is a constant version of U, which
is not the intent. So maybe this is isn't the right syntax after all.

The problem is simply stated. We need (1) some notation which means
"with constancy preserved", and (2) some notation which means "with
head constancy removed"

I argue that (T:T) is not the most obvious way to state (1), and that
typeof(T) is not the most obvious way to state (2).

At the risk of overusing keywords, maybe we could reinterpret init? As in:

    class A(init T)
    {

to mean T preserves the complete original type of the callee
parameter. And you could use a template for the second situation:

        alias RemoveHeadConst!(T) U;

to mean U is T with head constancy removed (that is, const(int)
becomes just int).

I don't know if that's any better or not? Somehow (init T) seems a
little more suggestive than (T:T) (and also more expressive, because
you can distinguish between (T:T[]) and (init T:T[]); and also,
RemoveHeadConst!(T) seems a little more suggestive than typeof(T).

I think it's better than the idea in my previous post, anyway.



More information about the Digitalmars-d mailing list