www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

D - Problem Porting C++ float4 operator code

I'm trying to port the
float1,float2,float3,float4,double1,double2,double3,double4 classes from
Brook for GPU's at
http://cvs.sourceforge.net/viewcvs.py/*checkout*/brook/brook/include/brtvector.hpp?rev=1.43

I've run into a problem with using templates for type promotion:

struct XVector(qfloat){
qfloat x;qfloat y;qfloat z;  
static XVector opCall (qfloat x, qfloat y, qfloat z) {
XVector ret;
ret.x=x;ret.y=y;ret.z=z;
return ret;
}

XVector opMul (XVector b) {
return  XVector(this.x*b.x,
this.y*b.y,
this.z*b.z);
}
}

I wish my b vector to be able to be cross-product'd on any template
instantiation of my template class.
in C++ I woudl write
template <class qfloat> class XVector {
template <class K> XVector<BetterType<K,qfloat>::type > operator %(XVector<K> b)
{
.. 
}
};
with
template <class A, class B> class BetterType{
typedef A type;
}
template <> class BetterType<float,double>{
typedef double type;
}


that way I could do the cross product between a XVector<float> and XVector<real>
like happens with float,double C++ types.

PS: I can't get opCall to work with templates 
XVector!(real)(1,2,3);
fails, but 
XVector!(real).opCall(1,2,3);
succeeds
Apr 28 2004