constancy and template parameters in D2.009+

Janice Caron caron800 at googlemail.com
Thu Dec 13 23:43:17 PST 2007


On 12/14/07, Christopher Wright <dhasenan at gmail.com> wrote:
> Well, in that case, you need some way of expressing const data but
> mutable reference (exists in 2.008, maybe a library solution in 2.009,

To be completely honest, the D2.008 solution doesn't work in all
cases. I don't know what the algorithm is, but I've made Walter aware
of some (fairly simple) source code which doesn't work, and he said
not to worry about it because it's all changing (presumably in D2.009)

So when, in D2.008, you do

    T!(Before)

to match

    template T(After)

I am not actually completely 100% certain of what the algorithm is
which transforms Before into After in D2.008. I only know that it
transforms const(int) into int. Beyond that, it's anybody's guess.

Maybe D2.007 got it right after all. Maybe multiple instantiations is
really not such a bad thing. Walter did suggest (in relation to a
different query) that the linker could be improved so that identical
functions are elided into a single function. If he could do that,
you'd get bigger .obj files, but the .exe would still be small.
Ultimately, that's probably the right way to go, so maybe we should
forget these intermediate kludges?

You're certainly right about the fact that RemoveHeadConst! would be a
furiously hard template to write though. (But Andrei could probably do
it!)



More information about the Digitalmars-d mailing list