Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Unit Example

(unit.cpp)

This example demonstrates the use of the simple but functional unit system implemented in test_system.hpp

const length                    L;
const mass                      M;
// needs to be namespace-qualified because of global time definition
const boost::units::test::time  T;
const energy                    E;

We can perform various algebraic operations on these units, resulting in the following output:

L             = m
L+L           = m
L-L           = m
L/L           = dimensionless
meter*meter   = m^2
M*(L/T)*(L/T) = m^2 kg s^-2
M*(L/T)^2     = m^2 kg s^-2
L^3           = m^3
L^(3/2)       = m^(3/2)
2vM           = kg^(1/2)
(3/2)vM       = kg^(2/3)


PrevUpHomeNext