D - Problem Porting C++ float4 operator code
- hellcatv hotmail.com (41/41) Apr 28 2004 I'm trying to port the
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