www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Expression template in D struct

reply The Anh Tran <trtheanh gmail.com> writes:
Hi,

I'm converting my pet project from C++ to D. It is an aimbot game cheat.
One of my C++ struct is Vector3. It is a wrapper from D3DXVECTOR3.
I would like to use expression template to calculate where to point the 
gun. In C++, it is provided by boost::proto or boost::ublas.

My naive implementation (in fact, "copy&paste" from c++ book "thinking 
in c++") refused to compile.
I've searched dsource.org; the nearest match is Don's BLADE library.

Is there any tutorial, or simpler way to do expression in D; without 
building AST as in BLADE?

Thanks.
May 06 2009
parent reply Trass3r <mrmocool gmx.de> writes:
The Anh Tran schrieb:
 One of my C++ struct is Vector3. It is a wrapper from D3DXVECTOR3.
 I would like to use expression template to calculate where to point the 
 gun. In C++, it is provided by boost::proto or boost::ublas.
 
You calculate where to point the gun at compile-time?
May 06 2009
parent reply The Anh Tran <trtheanh gmail.com> writes:
Trass3r wrote:
 The Anh Tran schrieb:
 One of my C++ struct is Vector3. It is a wrapper from D3DXVECTOR3.
 I would like to use expression template to calculate where to point 
 the gun. In C++, it is provided by boost::proto or boost::ublas.
You calculate where to point the gun at compile-time?
No :) I would like to learn D template programming; all i need is just a compile-time expression. vPredicted = vEnd + (((ProjectileSpeed^2 * |vStart-vEnd|^2 - |(vStart-vEnd) X Velocity | ^2) ^ 0.5 + (vStart-vEnd) * vVelocity) / (ProjectileSpeed^2 - |vVelocity|^2)) * vVelocity vXYZ is a struct, re-present 3D coordinate / velocity vector.
May 06 2009
parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Thu, 07 May 2009 03:31:46 +0200, The Anh Tran <trtheanh gmail.com> wrote:

 Trass3r wrote:
 The Anh Tran schrieb:
 One of my C++ struct is Vector3. It is a wrapper from D3DXVECTOR3.
 I would like to use expression template to calculate where to point  
 the gun. In C++, it is provided by boost::proto or boost::ublas.
You calculate where to point the gun at compile-time?
No :) I would like to learn D template programming; all i need is just a compile-time expression. vPredicted = vEnd + (((ProjectileSpeed^2 * |vStart-vEnd|^2 - |(vStart-vEnd) X Velocity | ^2) ^ 0.5 + (vStart-vEnd) * vVelocity) / (ProjectileSpeed^2 - |vVelocity|^2)) * vVelocity vXYZ is a struct, re-present 3D coordinate / velocity vector.
If you want something capable of processing the above, it will probably have to work along the lines of BLADE: use a CTFE function to parse the string and turn it into whatever code you prefer it to be. I do not believe there is such a library in existence, though I may of course be wrong. As for which functions are CTFE-able: http://digitalmars.com/d/2.0/function.html#interpretation -- Simen
May 07 2009