Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Examples

Dimension Example
Unit Example
Quantity Example
Kitchen Sink Example using SI units
Conversion Example
User Defined Types
Complex Example
Performance Example
Radar Beam Height
Heterogeneous Unit Example
Absolute and Relative Temperature Example
Runtime Conversion Factor Example
Units with Non-base Dimensions
Output for Composite Units
Automatically Scaled Units
Conversion Factor
Runtime Units
Interoperability with Boost.Lambda

(dimension.cpp)

By using MPL metafunctions and the template specializations for operations on composite dimensions (defined in boost/units/dimension.hpp) it is possible to perform compile time arithmetic according to the dimensional analysis rules described above to produce new composite dimensions :

typedef mpl::times<length_dimension,mass_dimension>::type   LM_type;
typedef mpl::divides<length_dimension,time_dimension>::type L_T_type;
typedef static_root<
    mpl::divides<energy_dimension,mass_dimension>::type,
    static_rational<2>
>::type    V_type;

outputting (with symbol demangling, implemented in utility.hpp)

length_dimension  = list<dim<length_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
mass_dimension    = list<dim<mass_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
time_dimension    = list<dim<time_base_dimension, static_rational<1l, 1l> >, dimensionless_type>
energy_dimension  = list<dim<length_base_dimension, static_rational<2l, 1l> >, list<dim<mass_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-2l, 1l> >, dimensionless_type> > >
LM_type      = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<mass_base_dimension, static_rational<1l, 1l> >, dimensionless_type> >
L_T_type     = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-1l, 1l> >, dimensionless_type> >
V_type       = list<dim<length_base_dimension, static_rational<1l, 1l> >, list<dim<time_base_dimension, static_rational<-1l, 1l> >, dimensionless_type> >


PrevUpHomeNext