Fully dynamic d by opDotExp overloading

SandeepK sandeep.iitkgpNOSPAM at gmail.com
Sat Apr 18 07:18:54 PDT 2009


Leandro Lucarella Wrote:

> > So now, let's try this again:
> > What is this usefulness you speak of that traditional dynamic methods and/or 
> > opDotSrc dynamic methods have that is more useful than a dispatch method? 
> 
> Uniform (and better) syntax. It's just about that.

I too am having difficulty in understanding the benefit of this particular proposal. If I understand it right, the string essentially is still static and hence known at compile time? In which case I fail to see the advantage of using this opDotSrc method instead of defining a function. 

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; 
//vec is now (4.0f, 3.0f, 2.0f, 1.0f);
vec = vec.xxyy; 
//vec is now (4.0f, 4.0f, 3.0f, 3.0f);

There is no good syntax to implement the swizzles in C++. You can make all of them member functions but the number of possibilities is so huge that is ridiculous to do it by hand. 

With something like this proposal, it should be easy to implement. 

Also, *if* there was a default opDotExp dispatcher (which automatically dispatches to the regular member functions) wouldn't it be easier to build interceptor classes? Or to implement class specific tracing? All calls to an object go through an interceptor object which can print debug trace information for example. For the default generated opDotExp the compiler can still do static type checking since it knows opDotExp will forward calls to the defined memeber functions. 



More information about the Digitalmars-d mailing list