c++ - boost-units - using a dimensionless type of arbitrary system -


i trying make dimensioned vector class boost-units so,

//vector constructed vec<si::length> v(10, 1.0*si::metre); template<typename dimension> class vec {   public:   //constructor setting values q.   vec(const size_t, const boost::units::quantity<dimension> q)   //etc } 

it works fine except operator*= , operator/= element wise multiplication , division. since these not change dimension, make sense when multiplying/dividing dimensionless quantity: struggling find arbitrary dimensionless quantity not locked specific system (e.g. si or cgs units).

i want like,

  /** multiply dimensionless vector. */   vec<dimension>&    operator*=(const vec<boost::units::dimensionless_type>& b); 

or perhaps metaprogramming magic (i notice boost::units::is_dimensionless exists, have no idea how use not versed in general metaprogramming techniques)

  template<typename dimension>   template<typename a_dimensionless_type>   vec<dimension>&    vec<dimension>::operator*=(const vec<a_dimensionless_type>& b){     //some compile time check make sure a_dimensionless_type dimensionless?     //the rest of function   } 

i want following examples compile

  vec<si::dimensionless> d(10, 2.0);   vec<si::length>  l(10, 2.0*si::metre);   l*=d;    vec<cgs::dimensionless> d2(10, 2.0);   vec<cgs::length>  l2(10, 2.0*cgs::centimetre);   l2*=d2; 

okay, after examining library details (and learning boost_mpl_assert) turned out easy. compliments library designer.

template<typename a_dimensionless_type> vec<dimension>&  operator*=(const vec< a_dimensionless_type >& b) {     boost_mpl_assert(( boost::units::is_dimensionless<boost::units::quantity<a_dimensionless_type>  > ));      //the rest of function  }; 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -