|
Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
|
optional, dependency-free interoperability between units and the Eigen linear-algebra library More...
#include <units/core.h>Go to the source code of this file.
optional, dependency-free interoperability between units and the Eigen linear-algebra library
Including this header after <Eigen/Core> teaches Eigen how to treat a units type as a matrix scalar, so a vector or matrix can hold dimensioned quantities (e.g. Eigen::Matrix<meters<double>, 3, 1>). It is inert when Eigen is not present: the whole body is guarded by __has_include(<Eigen/Core>), so units carries no dependency on Eigen and the header is a no-op if Eigen is unavailable.
The scalar-trait specializations unlock the same-dimension operations directly on Eigen expressions — construction, storage, addition/subtraction, scaling by a plain scalar, reductions such as sum(), block and Map views, and casting. The operations whose result changes dimension (a dot or cross product turns meters into square_meters, a norm takes a square root) cannot go through Eigen's built-ins, which assume scalar*scalar yields the same scalar; those are provided as free helper functions that compute the dimensionally-correct result type.