Boost C++ Libraries Home Libraries People FAQ More


Chapter 23. Boost.Units 1.0.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
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
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
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.
Boost.Units庫是將問題當作一個泛型元編程問題而實現的一個通用可擴展的庫。通過合適 的編譯優化,沒有運行時開銷會被引入,這使其很適合應用在性能敏感的代碼中實現量綱檢查。 單位和數量(定義為一個單位和相應的數字)可以應用於任意的單位系統,一個合適粒度的單位 轉換工具。提供了完整的SI和CGS單位系統,以(degrees)角度、(radians)弧度、gradians、 revolutions度量的角度系統和以Kelvin(開)、攝氏度、華氏度為單位的溫度系統。系統結構被設計 得有很強的適應性 和擴展性;例子中提供的添加新的單位和單位轉換就可以說明這一點。

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 :
為了實現這個複雜的、運行時零開銷、編譯時量綱分析,Boost.Units非常依賴於 Boost Metaprogramming Library (MPL) 和模板元編程技術。其結果就是,只有符合ISO標準的編譯器才可以使用。 下面是一些測試成功通過的編譯器和平台:

  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. Metrowerks CodeWarrior 9.2 on Windows XP.

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.

Last revised: November 02, 2008 at 13:07:13 GMT