Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-03-30 10:32:36


On Fri, 30 Mar 2001, Serge Barral wrote:
sbarra> Concerning the discussion about overloaded operators, I find the idea of
sbarra> having only 3 (did I count well??) signatures for a binary operator quite
sbarra> seducing.
sbarra> I'm not sure, however, that I understand what you mean when you say that
sbarra> with other approaches, binary operators would have to be defined for all
sbarra> combinations of matrices and vectors. Do you mean that they need to be
sbarra> overloaded for
sbarra> ( matrix_type1, matrix_type1 )
sbarra> ( matrix_type2, matrix_type1 )
sbarra> ( matrix_type1, matrix_type2 )
sbarra> ( exp< T >, matrix_type1 )
sbarra> and so on?

Right, the above combinations is what you would get from PETE.

sbarra> If so, I think there are alternative approaches (I suspect Blitz uses one
sbarra> of these) which let you define at most n+2 overloaded operators (n is the
sbarra> number of supported basic types, excluding expressions). It can be achieved
sbarra> for example by deriving (with the B&N trick) from a common base class every
sbarra> supported type as well as the expression template type and by overloading:
sbarra> ( matrix_type1, T )
sbarra> ( matrix_type2, T )
sbarra> ( exp<T1>, T2)
sbarra> ( T1, base_class<T2> )

So the MTL prototype uses the B&N trick, but unlike what you've got above,
All the MTL matrix and vector types inherit from linalg_expr. All the expr
tree classes inherit from expr. The operators are then defined for
combinations of expr and linalg_expr.

Cheers,
Jeremy

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk