refactor: 💥 basic_concepts, quantity and quantity_cast refactored

BREAKING CHANGE:  ScalableNumber renamed to QuantityValue

Resolves #107
This commit is contained in:
Mateusz Pusz committed 2020-10-06 18:17:52 +02:00
1 parent 40f205b381
commit cfc90f4aac
96 files changed
+1620 -1017

No files matched your search

@@ -9,11 +9,11 @@ its own custom logic for it (i.e. use a complex number or a measurement class th
not only a value but also a measurement error).
A `ScalableNumber` concept
A `QuantityValue` concept
--------------------------
To support a minimum set of `quantity` operations all custom representation types have to
satisfy at least the `ScalableNumber` concept. Which means that they:
satisfy at least the `QuantityValue` concept. Which means that they:
- cannot be quantities by themselves,
- cannot be wrappers over the `quantity` type (i.e. ``std::optional<si::length<si::metre>>``),
@@ -101,7 +101,7 @@ The only difference here is that in this case we have to explicitly cast the `qu
Additional Requirements
-----------------------
As noted in the previous chapter, the `ScalableNumber` concept guarantees us the possibility
As noted in the previous chapter, the `QuantityValue` concept guarantees us the possibility
to construct quantities, convert between the units of the same dimension, and compare them
for equality. To provide additional `quantity` operations the custom representation type
have to satisfy more requirements.
@@ -200,7 +200,7 @@ The `quantity` class template has a few static member functions: `quantity::zero
representation type. The default implementation is provided through the `quantity_values` class
template::
template<ScalableNumber Rep>
template<QuantityValue Rep>
struct quantity_values {
static constexpr Rep zero() noexcept { return Rep(0); }
static constexpr Rep one() noexcept { return Rep(1); }
@@ -220,7 +220,7 @@ library's framework treat floating-point representation types differently than t
ones. This behavior can also be extended to the custom representation types with
`treat_as_floating_point` customization point which default definition is::
template<ScalableNumber Rep>
template<QuantityValue Rep>
inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
If our representation type should have a floating-point semantics or if it is a class
+6 -6
View File
@@ -121,7 +121,7 @@ coherent unit::
struct desk_per_hour : deduced_unit<desk_per_hour, dim_desk_rate, desk, si::hour> {};
// a quantity of our dimension
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_desk_rate> U, QuantityValue Rep = double>
using desk_rate = quantity<dim_desk_rate, U, Rep>;
// a concept matching the above quantity
@@ -150,7 +150,7 @@ define a new base dimension, its units, quantity helper, concept, and UDLs::
struct person : named_unit<person, "person", no_prefix> {};
struct dim_people : base_dimension<"people", person> {};
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_people> U, QuantityValue Rep = double>
using people = quantity<dim_people, U, Rep>;
template<typename T>
@@ -169,7 +169,7 @@ With the above we can now define a new derived dimension::
struct person_per_desk : deduced_unit<person_per_desk, dim_occupancy_rate, person, desk> {};
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_occupancy_rate> U, QuantityValue Rep = double>
using occupancy_rate = quantity<dim_occupancy_rate, U, Rep>;
template<typename T>
@@ -216,7 +216,7 @@ Such units do not share their references with base units of other systems:
struct dim_length : base_dimension<"L", foot> {};
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_length> U, QuantityValue Rep = double>
using length = quantity<dim_length, U, Rep>;
} // namespace fps
@@ -236,7 +236,7 @@ different systems:
struct dim_length : base_dimension<"L", metre> {};
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_length> U, QuantityValue Rep = double>
using length = quantity<dim_length, U, Rep>;
namespace fps {
@@ -246,7 +246,7 @@ different systems:
struct dim_length : base_dimension<"L", foot> {};
template<Unit U, ScalableNumber Rep = double>
template<UnitOf<dim_length> U, QuantityValue Rep = double>
using length = quantity<dim_length, U, Rep>;
} // namespace fps