Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.

Chapter 26. Boost.Units 1.1.0

Matthias C. Schabel

Steven Watanabe

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at

Table of Contents

Quick Start
Dimensional Analysis
Base Units
Scaled Base Units
Scaled Units
Heterogeneous Operators
Construction and Conversion of Quantities
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
Metaprogramming Classes
Metaprogramming Predicates
Units Reference
Dimensions Reference
SI System Reference
CGS System Reference
Trigonometry and Angle System Reference
Temperature System Reference
Abstract System Reference
Base Units by Category
Alphabetical Listing of Base Units
How does one distinguish between quantities that are physically different but have the same units (such as energy and torque)?
Angles are treated as units
Why are there homogeneous systems? Aren't heterogeneous systems sufficient?
Why can't I construct a quantity directly from the value type?
Why are conversions explicit by default?
Help Wanted
Version Info
Release Notes

The Boost.Units library is a C++ implementation of dimensional analysis in a general and extensible manner, treating it as a generic compile-time metaprogramming problem. With appropriate compiler optimization, no runtime execution cost is introduced, facilitating the use of this library to provide dimension checking in performance-critical code. Support for units and quantities (defined as a unit and associated value) for arbitrary unit system models and arbitrary value types is provided, as is a fine-grained general facility for unit conversions. Complete SI and CGS unit systems are provided, along with systems for angles measured in degrees, radians, gradians, and revolutions and systems for temperatures measured in Kelvin, degrees Celsius and degrees Fahrenheit. The library architecture has been designed with flexibility and extensibility in mind; demonstrations of the ease of adding new units and unit conversions are provided in the examples.

In order to enable complex compile-time dimensional analysis calculations with no runtime overhead, Boost.Units relies heavily on the Boost Metaprogramming Library (MPL) and on template metaprogramming techniques, and is, as a consequence, fairly demanding of compiler compliance to ISO standards. At present, it has been successfully compiled and tested on the following compilers/platforms :

  1. g++ 4.0.1 on Mac OSX 10.4
  2. Intel CC 9.1, 10.0, and 10.1 on Mac OSX 10.4
  3. g++ 3.4.4, 4.2.3, and 4.3.0 on Windows XP
  4. Microsoft Visual C++ 7.1, 8.0, and 9.0 on Windows XP
  5. Comeau beta2 on Windows XP
  6. Metrowerks CodeWarrior 9.2 on Windows XP.
  7. Sun CC 5.9 on Solaris and Linux

The following compilers/platforms are known not to work :

  1. g++ 3.3.x
  2. Microsoft Visual C++ 6.0 on Windows XP
  3. Microsoft Visual C++ 7.0 on Windows XP
  4. Metrowerks CodeWarrior 8.0 on Windows XP.
  5. All versions of Borland.

Last revised: November 10, 2010 at 00:45:35 GMT