diff --git a/docs/_static/img/units.png b/docs/_static/img/units.png index be543e5f..7fd36576 100644 Binary files a/docs/_static/img/units.png and b/docs/_static/img/units.png differ diff --git a/docs/framework/units.rst b/docs/framework/units.rst index ee42aa64..225facd5 100644 --- a/docs/framework/units.rst +++ b/docs/framework/units.rst @@ -308,6 +308,32 @@ provided in the template parameter list after the derived dimension parameter, the library calculates the final ratio for this unit. +Aliased Units +------------- + +In order to make our life easier people tend to assign alternative/aliased names +to some popular units. As an example we often use "tonne" instead of "megagram", +"litre" instead of "cubic decimetre", or "hectare" instead of "square hectometre". + +This library provides facilities to define aliased names to already defined units +with `alias_unit` class template:: + + namespace si { + + struct litre : alias_unit {}; + + } + +Also, it is possible to add prefixes to such aliased units with `prefixed_alias_unit` +class template:: + + namespace si { + + struct millilitre : prefixed_alias_unit {}; + + } + + Class Hierarchy --------------- @@ -327,6 +353,8 @@ of a `scaled_unit` class template: [scaled_unit]<:-[named_scaled_unit] [scaled_unit]<:-[prefixed_unit] [scaled_unit]<:-[deduced_unit] + [scaled_unit]<:-[alias_unit] + [scaled_unit]<:-[prefixed_alias_unit] `scaled_unit` is a class template used exclusively by the library's framework and user should not instantiate it by him/her-self. However the user can sometimes diff --git a/src/include/units/unit.h b/src/include/units/unit.h index 6bf3db22..02930483 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -172,6 +172,19 @@ struct deduced_unit : downcast_child struct alias_unit : U { static constexpr bool is_named = true; @@ -179,6 +192,17 @@ struct alias_unit : U { using prefix_family = PT; }; +/** + * @brief A prefixed alias unit + * + * Defines a new unit that is an alias for a scaled version of another unit by the provided + * prefix. It is only possible to create such a unit if the given prefix type matches the one + * defined in a reference unit. + * + * @tparam U Unit for which an alias is defined + * @tparam P prefix to be appied to the reference unit + * @tparam AU reference alias unit + */ // TODO gcc bug: 95015 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95015 // template