Boost logo

Boost :

Subject: [boost] [qvm] scalar_cast
From: Nikolay Mladenov (nikolay.mladenov_at_[hidden])
Date: 2012-11-03 19:00:38

Hi Emil,

I am trying qvm in a small project that uses complex numbers and have
expressions of the kind :
  cv3 = c1*rv3_1 + c2*rv3_2
(the v3's are vectors, the c's are complex and the r's are real).

I wrote it as :

             = scalar_cast<complex>(rv3_1)*c1
             + scalar_cast<complex>(rv3_2)*c2;

but this seems to invoke 6 complex constructors (unnecessarily)
I have not tested to see if the constructors will be optimized away,
but it seems to me that if :
 v_traits<vector_scalar_cast_>::scalar_type == complex , bit
 v_traits<vector_scalar_cast_>::r/ir return real
the expression will compile and no complex constructors will be invoked.

It seems to me that there is a need for another kind of scalar_cast that
just adapts the v_traits<>:scalar_type but leaves the r() and ir() unchanged

Another question I have is if there is a reason why vector*scalar works but
scalar*vector does not?

Thanks in advance,


PS I can send patches if you'd like.

Boost list run by bdawes at, gregod at, cpdaniel at, john at