diff --git a/docs/_static/img/units.svg b/docs/_static/img/units.svg index 59002174..21a7388d 100644 --- a/docs/_static/img/units.svg +++ b/docs/_static/img/units.svg @@ -1,122 +1,157 @@ -Unitprefix_familyno_prefixprefixPrefixFamily, Symbol, Ratioscaled_unitUnitRatio, Unitprefixed_alias_unitUnit, Prefix, AliasUnitalias_unitUnit, Symbol, PrefixFamilynamed_derived_unitDimension, Symbol, PrefixFamily, Unit, Unit...derived_unitDimension, Unit, Unit...prefixed_unitPrefix, Unitnamed_scaled_unitSymbol, PrefixFamily, Ratio, Unitnamed_unitSymbol, PrefixFamilyunit + + + + + Unit + + + + + scaled_unit + + UnitRatio, Unit + + + + + prefixed_alias_unit + + Unit, Prefix, AliasUnit + + + + + + alias_unit + + Unit, Symbol + + + + + + derived_scaled_unit + + Dimension, Unit, Unit... + + + + + + derived_unit + + + + + + prefixed_unit + + Prefix, Unit + + + + + + named_scaled_unit + + Symbol, Ratio, Unit + + + + + + named_unit + + Symbol + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +--> + + \ No newline at end of file diff --git a/docs/framework/units.rst b/docs/framework/units.rst index 9e00b7ee..8e37e3e2 100644 --- a/docs/framework/units.rst +++ b/docs/framework/units.rst @@ -40,38 +40,22 @@ of a `scaled_unit` class template: left to right direction package Unit <> [[../../framework/units.html]] { - abstract prefix_family [[../../framework/units.html#prefixed-unit]] - abstract no_prefix [[../../framework/units.html#named-scaled-units]] - abstract prefix [[../../framework/units.html#prefixed-unit]] - - prefix_family <|-- no_prefix - prefix_family <.. prefix - - ' prefix_family <.. named_unit - ' prefix_family <.. named_scaled_unit - ' prefix_family <.. named_derived_unit - ' prefix_family <.. alias_unit - - ' prefix <.. prefixed_unit - ' prefix <.. prefixed_alias_unit abstract scaled_unit abstract prefixed_alias_unit [[../../framework/units.html#aliased-units]] - abstract alias_unit [[../../framework/units.html#aliased-units]] - abstract named_derived_unit [[../../framework/units.html#derived-scaled-units]] - abstract derived_unit [[../../framework/units.html#derived-scaled-units]] + abstract alias_unit [[../../framework/units.html#aliased-units]] + abstract derived_scaled_unit [[../../framework/units.html#derived-scaled-units]] + abstract derived_unit [[../../framework/units.html#derived-unnamed-units]] abstract prefixed_unit [[../../framework/units.html#prefixed-unit]] - abstract named_scaled_unit [[../../framework/units.html#named-scaled-units]] - abstract named_unit [[../../framework/units.html#base-units]] - abstract unit [[../../framework/units.html#derived-unnamed-units]] + abstract named_scaled_unit [[../../framework/units.html#named-scaled-units]] + abstract named_unit [[../../framework/units.html#base-units]] - scaled_unit <|-- unit scaled_unit <|-- named_unit scaled_unit <|-- named_scaled_unit scaled_unit <|-- prefixed_unit scaled_unit <|-- derived_unit - scaled_unit <|-- named_derived_unit + scaled_unit <|-- derived_scaled_unit scaled_unit <|-- alias_unit scaled_unit <|-- prefixed_alias_unit } @@ -191,14 +175,11 @@ Those units are the scaled versions of a time dimension's base unit, namely second. Those can be defined easily in the library using `named_scaled_unit` class template:: - struct minute : named_scaled_unit {}; - struct hour : named_scaled_unit {}; - struct day : named_scaled_unit {}; + struct minute : named_scaled_unit {}; + struct hour : named_scaled_unit {}; + struct day : named_scaled_unit {}; -where `no_prefix` is a special tag type describing that the library should -not allow to define a new prefixed unit that would use this unit as a -reference ("kilohours" does not have much sense, right?). The `ratio` type -used in the definition is really similar to ``std::ratio`` but it takes +The `ratio` type used in the definition is really similar to ``std::ratio`` but it takes an additional ``Exponent`` template parameter that defines the exponent of the ratio. Another important difference is the fact that the objects of that class are used as class NTTPs rather then a type template parameter kind. @@ -227,28 +208,26 @@ complete list of all the :term:`SI` prefixes supported by the library:: namespace si { - struct prefix : prefix_family {}; - - struct yocto : units::prefix {}; - struct zepto : units::prefix {}; - struct atto : units::prefix {}; - struct femto : units::prefix {}; - struct pico : units::prefix {}; - struct nano : units::prefix {}; - struct micro : units::prefix {}; - struct milli : units::prefix {}; - struct centi : units::prefix {}; - struct deci : units::prefix {}; - struct deca : units::prefix {}; - struct hecto : units::prefix {}; - struct kilo : units::prefix {}; - struct mega : units::prefix {}; - struct giga : units::prefix {}; - struct tera : units::prefix {}; - struct peta : units::prefix {}; - struct exa : units::prefix {}; - struct zetta : units::prefix {}; - struct yotta : units::prefix {}; + struct yocto : units::prefix {}; + struct zepto : units::prefix {}; + struct atto : units::prefix {}; + struct femto : units::prefix {}; + struct pico : units::prefix {}; + struct nano : units::prefix {}; + struct micro : units::prefix {}; + struct milli : units::prefix {}; + struct centi : units::prefix {}; + struct deci : units::prefix {}; + struct deca : units::prefix {}; + struct hecto : units::prefix {}; + struct kilo : units::prefix {}; + struct mega : units::prefix {}; + struct giga : units::prefix {}; + struct tera : units::prefix {}; + struct peta : units::prefix {}; + struct exa : units::prefix {}; + struct zetta : units::prefix {}; + struct yotta : units::prefix {}; } @@ -257,14 +236,12 @@ domain:: namespace iec80000 { - struct binary_prefix : prefix_family {}; - - struct kibi : units::prefix {}; - struct mebi : units::prefix {}; - struct gibi : units::prefix {}; - struct tebi : units::prefix {}; - struct pebi : units::prefix {}; - struct exbi : units::prefix {}; + struct kibi : units::prefix {}; + struct mebi : units::prefix {}; + struct gibi : units::prefix {}; + struct tebi : units::prefix {}; + struct pebi : units::prefix {}; + struct exbi : units::prefix {}; } @@ -338,7 +315,7 @@ will result in a different unnamed unit symbol: where ``kilogram_metre_per_second`` is defined as:: - struct kilogram_metre_per_second : unit {}; + struct kilogram_metre_per_second : derived_unit {}; However, the easiest way to define momentum is just to use the ``si::dim_speed`` derived dimension in the recipe: @@ -385,12 +362,12 @@ ratio in reference to the "metre per second": Whichever, we choose there will always be someone not happy with our choice. -Thanks to a `derived_unit` class template provided by the library this problem +Thanks to a `derived_scaled_unit` class template provided by the library this problem does not exist at all. With it ``si::kilometre_per_hour`` can be defined as:: namespace si { - struct kilometre_per_hour : derived_unit {}; + struct kilometre_per_hour : derived_scaled_unit {}; } @@ -400,7 +377,7 @@ by him/her-self:: namespace si::fps { - struct knot : named_derived_unit {}; + struct knot : named_derived_unit {}; } diff --git a/docs/reference/core/concepts.rst b/docs/reference/core/concepts.rst index ecc79b8a..99f38ce9 100644 --- a/docs/reference/core/concepts.rst +++ b/docs/reference/core/concepts.rst @@ -8,10 +8,6 @@ Concepts All names defined in this chapter reside in the :any:`units` namespace unless specified otherwise. -.. concept:: template PrefixFamily - - A concept matching a prefix family. Satisfied by all types derived from :class:`prefix_family`. - .. concept:: template Prefix A concept matching a symbol prefix. Satisfied by all instantiations of :struct:`prefix`. @@ -44,6 +40,11 @@ Concepts A concept matching all unit types in the library. Satisfied by all unit types derived from the instantiation of :class:`scaled_unit`. +.. concept:: template NamedUnit + + A concept matching all unit types that have an atomic text symbol that can be used to aggregate it with + other named units to form a final symbol of a derived unit. + .. concept:: template UnitOf A concept matching only units of a specified dimension. Satisfied by all unit types that diff --git a/docs/reference/core/types/prefixes.rst b/docs/reference/core/types/prefixes.rst index 414eda66..7f160aef 100644 --- a/docs/reference/core/types/prefixes.rst +++ b/docs/reference/core/types/prefixes.rst @@ -1,11 +1,5 @@ Prefixes ======== -.. doxygenstruct:: units::prefix_family - :members: - -.. doxygenstruct:: units::no_prefix - :members: - .. doxygenstruct:: units::prefix :members: diff --git a/docs/reference/core/types/units.rst b/docs/reference/core/types/units.rst index 897fcc85..ce21fc68 100644 --- a/docs/reference/core/types/units.rst +++ b/docs/reference/core/types/units.rst @@ -4,9 +4,6 @@ Units .. doxygenstruct:: units::scaled_unit :members: -.. doxygenstruct:: units::unit - :members: - .. doxygenstruct:: units::named_unit :members: @@ -19,7 +16,7 @@ Units .. doxygenstruct:: units::derived_unit :members: -.. doxygenstruct:: units::named_derived_unit +.. doxygenstruct:: units::derived_scaled_unit :members: .. doxygenstruct:: units::alias_unit diff --git a/docs/use_cases/extensions.rst b/docs/use_cases/extensions.rst index 9e07a92a..fd9db565 100644 --- a/docs/use_cases/extensions.rst +++ b/docs/use_cases/extensions.rst @@ -22,7 +22,7 @@ Defining a New Unit My working desk is of ``180 cm x 60 cm`` which gives an area of ``0.3 m²``. I would like to make it a unit of area for my project:: - struct desk : named_scaled_unit {}; + struct desk : named_scaled_unit {}; With the above I can define a quantity with the area of ``2 desks``:: @@ -56,28 +56,22 @@ In case I would like to check how much area ``6 desks`` take in SI units:: Enabling a Unit for Prefixing ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -In case I decide it is reasonable to express my desks with SI prefixes the only thing I have -to change in the above code is to replace `no_prefix` with `isq::si::prefix`:: - - struct desk : named_scaled_unit {}; - -Now I can define a new unit named ``kilodesk``:: +In case I decide it is reasonable to express my desks with SI prefixes, I can define +a new unit named ``kilodesk``:: struct kilodesk : prefixed_unit {}; static_assert(3_d * 1000 == si::area(3)); But maybe SI prefixes are not good for me. Maybe I always pack ``6`` desks into one package -for shipment and ``40`` such packages fit into my lorry. To express this with prefixes a new -prefix family and prefixes are needed:: +for shipment and ``40`` such packages fit into my lorry. To express this new prefix definitions +are needed:: - struct shipping_prefix : prefix_family {}; - - struct package : prefix {}; - struct lorry : prefix {}; + struct package : prefix {}; + struct lorry : prefix {}; Now we can use it for our unit:: - struct desk : named_scaled_unit {}; + struct desk : named_scaled_unit {}; struct packagedesk : prefixed_unit {}; struct lorrydesk : prefixed_unit {}; @@ -111,14 +105,14 @@ rate of wood during production I need to define a new derived dimension together coherent unit:: // coherent unit must apply to the system rules (in this case SI) - struct square_metre_per_second : unit {}; + struct square_metre_per_second : derived_unit {}; // new derived dimensions struct dim_desk_rate : derived_dimension, exponent> {}; // our unit of interest for a new derived dimension - struct desk_per_hour : derived_unit {}; + struct desk_per_hour : derived_scaled_unit {}; // a quantity of our dimension template U, Representation Rep = double> @@ -147,7 +141,7 @@ a customer's office I would need a unit called ``person_per_desk`` of a new deri dimension. However, our library does not know what a ``person`` is. For this I need to define a new base dimension, its units, quantity helper, concept, and UDLs:: - struct person : named_unit {}; + struct person : named_unit {}; struct dim_people : base_dimension<"people", person> {}; template U, Representation Rep = double> @@ -162,12 +156,12 @@ define a new base dimension, its units, quantity helper, concept, and UDLs:: With the above we can now define a new derived dimension:: - struct person_per_square_metre : unit {}; + struct person_per_square_metre : derived_unit {}; struct dim_occupancy_rate : derived_dimension, exponent> {}; - struct person_per_desk : derived_unit {}; + struct person_per_desk : derived_scaled_unit {}; template U, Representation Rep = double> using occupancy_rate = quantity; @@ -211,8 +205,8 @@ Such units do not share their references with base units of other systems: namespace fps { - struct foot : named_unit {}; - struct yard : named_scaled_unit {}; + struct foot : named_unit {}; + struct yard : named_scaled_unit {}; struct dim_length : base_dimension<"L", foot> {}; @@ -231,7 +225,7 @@ different systems: namespace si { - struct metre : named_unit {}; + struct metre : named_unit {}; struct kilometre : prefixed_unit {}; struct dim_length : base_dimension<"L", metre> {}; @@ -241,8 +235,8 @@ different systems: namespace fps { - struct foot : named_scaled_unit {}; - struct yard : named_scaled_unit {}; + struct foot : named_scaled_unit {}; + struct yard : named_scaled_unit {}; struct dim_length : base_dimension<"L", foot> {}; @@ -300,7 +294,7 @@ the library always keeps the ratio relative to the primary reference unit which in this case is ``si::metre``. This results in much bigger ratios and in case of some units may result with a problem of limited resolution of ``std::int64_t`` used to store numerator, denominator, and exponent -values of ratio. For example the ``si::fps::qubic_foot`` already has the +values of ratio. For example the ``si::fps::cubic_foot`` already has the ratio of ``ratio{55306341, 1953125, -3}``. In case of more complicated conversion ratio we can overflow `ratio` and get a compile-time error. In such a situation the standalone system may be a better choice here.