Hi,
 
Using units and ublas for new code is great, but how about using both in legacy code? I’ve got some legacy numerical code using primitive types, i plan to use units for some reasons, i.e. to check performance using both primitive types and boost::units types, and to check my code at compile time which is its whole purpose after all. I spent a day and my code it’s already broken, specially because of the initializations and ublas, some self-explanatory code follows:
 
 
----- calculations.hpp -----------
//typedefs to get library-free code
 
#include <complex>
#include <iostream>
 
#if USING_BOOST_UNITS
 
 
#include <boost/typeof/std/complex.hpp>
#include <boost/units/systems/si/power.hpp>
//...
using namespace boost::units;
using namespace boost::units::si;
using namespace std;
 
typedef std::complex<double> complex_type;
 
typedef quantity<electric_potential,complex_type> tPotencial;
typedef quantity<current,complex_type> tIntensidad;
typedef quantity<resistance,complex_type> tResistancia;
 
//...
#elif
 
typedef double tPotencial;
typedef double tIntensidad;
typedef double tResistancia;
 
//...
#endif
------------------------------------------
 
-----  some_legacy_calculations.cpp ------
 
#define USING_BOOST_UNITS
tPotencial tension = complex_type(12.5,0.0)*volts; //ok
tPotencial tension2 = complex_type(12.5,0.0); //auch!
 
some_file << tesion + tension2 << std::endl;
some_file.close();
 
//get Real part from 'tension' and pretend it's a current
quantity<current, double> phony_tension = tension.value().real * amperes;//compiler doesn't complain, but how do I prevent this to compile?
 
#undef USING_BOOST_UNITS
tPotencial tension = complex_type(12.5,0.0)*volts; //auch!
tPotencial tension2 = complex_type(12.5,0.0); //ok
 
some_file.open("/*some_file*/");
some_file >> tesion + tension2 >> std::endl; //auch!
 
 
#define USING_BOOST_UNITS
//use ublas
ublas::matrix<tAdmitancia, ublas::column_major> admi(2, 2);     
ublas::matrix<tPotencia, ublas::column_major> ind(2, 1);  
 
ind(0, 0) = complex_type (1, 0)*volts;
ind(1, 0) = complex_type (-1, 0)*volts;
 
admi(0, 0) = complex_type (0, -2)*siemens;
admi(0, 1) = complex_type (0, 2)*siemens;
admi(1, 0) = complex_type (0, 2)*siemens;
admi(1, 1) = complex_type (0, -2)*siemens;
 
 
int er = lapack::gesv(admi, ind);//auch!
 
------------------------------------------
 
For each of those problems i found some workaround but I'd like to discuss whether it's ok or not.
Thanks for  your time.