Boost logo

Ublas :

From: Dima Sorkin (dsorkin_at_[hidden])
Date: 2005-07-06 03:41:21

 I have 2 questions about the general concept of
expression templates (ET),rather than about ublas
itself. Since ublas is (or was) built around the
ET concept (ublas is a good example), I decided to
ask them here (I will spread them in 2 separate
messages, this one is the first)

1) Encapsulation of classes that use ETs :
   What is the right way ?

     Suppose the folowing example:

      class A {
        typedef some_ublas_matrix_type matr_type;
        matr_type M1,M2;
        A(const matr_type &M1in,const matr_type &M2in)
          :M1(M1in),M2(M2in) {}
        A const operator+(A const &a) const {
          return A(M1+a.M1,M2+a.M2);

   Then,if I have 4 objects x1,x2,x3,x4 of class A, writing
     x4 = x1+x2+x3;
   "forces" a temporary (I understand (following the whole
    discussion about aliasing) that temporary is created
    anyway, but see my question as a concept question).
    What should "operator+" return, in order to make the
    ETs work ? If it returns some encapsulation of ublas ET,
    then I need also write an "operator+" that accepts such
    encapsulation.The things start becoming compicated,if
    I implement all arith. operators.
    Is there some simple way (pattern of design) ?

Thank you.