physical units checked at compile time (yet lacking IFTI capabilities)

Norbert Nemec Norbert at Nemec-online.de
Sun Apr 23 14:06:50 PDT 2006


BCS wrote:
> I feel your pain. A few post back I include a link to a unit.d program that does
> just what you are trying to do, but a run time (with all of the costs :-p that
> entails, OTOH it lets you do units dynamically) I have bean waiting for better
> template support to do exactly the same project you are looking at. Until that
> happens I think we're sunk.
> 
> I was looking at something like this:
> 
> struct Unit(T, int L, int M, int T)
> {
> T val;
> 
> Unit(T, L, M, T) opAdd(Unit(T, L, M, T) op)
> {
> Unit(T, L, M, T) ret = { val : val+op.val };
> return ret;
> }
> 
> // this will need some improvements to templates
> Unit(T, L+opL, M+opM, T+opT) opMul(Unit(T,opL, opM, opT) op)
> {
> Unit(T, L+opL, M+opM, T+opT) ret = { val : val*op.val };
> return ret;
> }
> ..
> }

Pretty much the same thing.

> Lets hope walter makes some of these possible in the near future.

That's one of the main intentions of my detailed post. Walter clearly
stated that the current IFTI mechanism is rudimentary and that he
intends to improve it. Giving clear use cases may help in finding out
the details of what is really needed.

The difficulty is, that D templates are so fundamentally different from
C++ templates, that it really is hard to notice which features are
really missing in D and which things should simply be done in a
different way. Coming from C++, meta-programming in D asks for a
completely different way of thinking, yet it is important not to throw
overboard all the experience that was gained in C++.



More information about the Digitalmars-d mailing list