[proto] applying proto to real problems

I haven't used proto before and as I read the documentation everything makes sense but I can't figure out how to apply the information there to solve my problems. I think if I can figure out how to solve a simplified example from my actual problem I can figure out the rest. // typical 3d vector template< typename T > struct vec3 { T x,y,z; }; // typical 3d dot product template< typename T > T dot_product( const vec3<T>& a, const vec3<T>& b ) { return a.x*b.x + a.y*b.y + a.z*b.z; } // typical 16.16 fixed point number struct fixed { boost::int32_t data; }; // typical multiplication for this fixed point number fixed operator*( fixed lhs, fixed rhs ) { fixed result = { static_castboost::int32_t ( ( boost::int64_t(lhs.data)*rhs.data ) >> 16 ) }; return result; } // however using the typical dot product with // fixed numbers is too lossy and inefficient // so we have to specialize dot_product for // these fixed point numbers to do this template<> fixed dot_product( const vec3<fixed>& a, const vec3<fixed>& b ) { fixed result = { static_castboost::int32_t ( ( boost::int64_t(a.x.data) * b.x.data + boost::int64_t(a.y.data) * b.y.data + boost::int64_t(a.z.data) * b.z.data ) >> 16 ) }; return result; } What I want to be able to do is to make the typical dot product generate code that is equivalent to the specialized dot product when instantiated with T = fixed. This seems like something proto should handle easily from the description of the library but I just don't get proto yet. Thanks, -- Michael Marcin

Michael Marcin a écrit :
template<> fixed dot_product( const vec3<fixed>& a, const vec3<fixed>& b ) { fixed result = { static_castboost::int32_t ( ( boost::int64_t(a.x.data) * b.x.data + boost::int64_t(a.y.data) * b.y.data + boost::int64_t(a.z.data) * b.z.data ) >> 16 ) }; return result; }
Well, SFNIAE and template overlaod should be enough Try remove this template<> from the fixed overload. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Michael Marcin wrote:
I haven't used proto before and as I read the documentation everything makes sense but I can't figure out how to apply the information there to solve my problems.
I think if I can figure out how to solve a simplified example from my actual problem I can figure out the rest.
<snip>
What I want to be able to do is to make the typical dot product generate code that is equivalent to the specialized dot product when instantiated with T = fixed. This seems like something proto should handle easily from the description of the library but I just don't get proto yet.
So far, nothing you've shown has demonstrated a need for expression templates or a DSEL. You don't appear to need Proto. An overloaded dot_product() function that handles vec3<fixed> as you have it is sufficient. Am I missing something? -- Eric Niebler BoostPro Computing www.boostpro.com
participants (3)
-
Eric Niebler
-
Joel Falcou
-
Michael Marcin