Fully dynamic d by opDotExp overloading
bearophile
bearophileHUGS at lycos.com
Sat Apr 18 07:28:39 PDT 2009
SandeepK:
> I too am having difficulty in understanding the benefit of this particular proposal.
Read the thread, some of the answers give several use cases.
>If I understand it right, the string essentially is still static and hence known at compile time?<
It can be unknown at compile-time.
> Anyways, I have wanted similar functionality for a different purpose. In graphics is common to do swizzle on vector. A float4 vector has xyzw components and some specialized languages like shaders allow you to do shuffle and replicate the components.
> float4 vec = float4(1.0f,2.0f,3.0f,4.0f);
> vec = vec.wzyx;
Note that using dynamic access may be a bit slow for that.
On the other hand you can do that in D1 creating a small compile-time function that computes the cartesian product to create the strings of the names of those function methods (to be used as attributes), that you can add with a mixin (and a static foreach, if necessary).
I have shown such code here time ago, don't ask me to write it again :-) This is a starting point:
const string chars = "xyzw";
foreach (x; Range!(4))
foreach (y; Range!(4))
foreach (y; Range!(4))
foreach (w; Range!(4))
chars[x] ~ chars[y] ~ chars[w] ~ chars[w];
Bye,
bearophile
More information about the Digitalmars-d
mailing list