refactor: QuantityValue concept renamed to Representation
This commit is contained in:
1 parent
67b2ad5d05
commit
88e642ec74
97 files changed
+197
-197
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
# Release notes
|
||||
|
||||
- **0.7.0 WIP**
|
||||
- (!) refactor: `ScalableNumber` renamed to `QuantityValue`
|
||||
- (!) refactor: `ScalableNumber` renamed to `Representation`
|
||||
- (!) refactor: output stream operators moved to the `units/quantity_io.h` header file
|
||||
- (!) refactor: Refactored the library file tree
|
||||
- (!) refactor: `quantity::count()` renamed to `quantity::number()`
|
||||
|
||||
@@ -11,7 +11,7 @@ Interface
|
||||
The difference is that it uses ``double`` as a default representation and has
|
||||
a few additional member types and functions::
|
||||
|
||||
template<Dimension D, UnitOf<D> U, QuantityValue Rep = double>
|
||||
template<Dimension D, UnitOf<D> U, Representation Rep = double>
|
||||
class quantity {
|
||||
public:
|
||||
using dimension = D;
|
||||
@@ -27,7 +27,7 @@ a few additional member types and functions::
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const quantity<D1, U1, Rep1>& lhs,
|
||||
const quantity<D2, U2, Rep2>& rhs);
|
||||
|
||||
template<QuantityValue Value, typename D, typename U, typename Rep>
|
||||
template<Representation Value, typename D, typename U, typename Rep>
|
||||
requires std::magma<std::ranges::divided_by, Value, Rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Value& v,
|
||||
const quantity<D, U, Rep>& q);
|
||||
|
||||
@@ -18,7 +18,7 @@ For example the speed of light constant in :term:`SI` is defined as::
|
||||
|
||||
namespace si::si2019 {
|
||||
|
||||
template<QuantityValue Rep = double>
|
||||
template<Representation Rep = double>
|
||||
inline constexpr auto speed_of_light = speed<metre_per_second, Rep>(299792458);
|
||||
|
||||
}
|
||||
@@ -27,7 +27,7 @@ The same constant defined for natural units may be provided as::
|
||||
|
||||
namespace natural {
|
||||
|
||||
template<QuantityValue Rep = double>
|
||||
template<Representation Rep = double>
|
||||
inline constexpr auto speed_of_light = speed<one, Rep>(1);
|
||||
|
||||
}
|
||||
@@ -79,8 +79,8 @@ you can use a quantity argument instead of a quantity kind.
|
||||
struct height_kind : kind<height_kind, dim_length> {};
|
||||
struct rate_of_climb_kind : derived_kind<rate_of_climb_kind, height_kind, dim_speed> {};
|
||||
|
||||
template <Unit U, QuantityValue Rep = double> using height = quantity_kind<height_kind, U, Rep>;
|
||||
template <Unit U, QuantityValue Rep = double> using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using height = quantity_kind<height_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using rate_of_climb = quantity_kind<rate_of_climb_kind, U, Rep>;
|
||||
|
||||
height h{100 * m};
|
||||
rate_of_climb rate = h / (25 * s);
|
||||
@@ -92,8 +92,8 @@ you can use a quantity argument instead of a quantity kind.
|
||||
struct width_kind : kind<width_kind, dim_length> {};
|
||||
struct horizontal_area_kind : derived_kind<horizontal_area_kind, width_kind, dim_area> {};
|
||||
|
||||
template <Unit U, QuantityValue Rep = double> using width = quantity_kind<width_kind, U, Rep>;
|
||||
template <Unit U, QuantityValue Rep = double> using horizontal_area = quantity_kind<horizontal_area_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using width = quantity_kind<width_kind, U, Rep>;
|
||||
template <Unit U, Representation Rep = double> using horizontal_area = quantity_kind<horizontal_area_kind, U, Rep>;
|
||||
|
||||
width w{5 * m};
|
||||
horizontal_area area1 = w * w;
|
||||
|
||||
@@ -37,10 +37,10 @@ type to ``double`` by default::
|
||||
|
||||
namespace si {
|
||||
|
||||
template<Unit U, QuantityValue Rep = double>
|
||||
template<Unit U, Representation Rep = double>
|
||||
using length = quantity<dim_length, U, Rep>;
|
||||
|
||||
template<Unit U, QuantityValue Rep = double>
|
||||
template<Unit U, Representation Rep = double>
|
||||
using speed = quantity<dim_speed, U, Rep>;
|
||||
|
||||
}
|
||||
@@ -208,7 +208,7 @@ be used::
|
||||
All instances of `quantity` class always match the `Quantity` concept.
|
||||
All other regular types that are not quantities are called
|
||||
:term:`scalable numbers <scalable number>` by the library and match the
|
||||
`QuantityValue` concept.
|
||||
`Representation` concept.
|
||||
|
||||
However, the above is not the most important usage of those concepts. Let's
|
||||
assume that the user wants to implement an ``avg_speed`` function that will
|
||||
@@ -318,7 +318,7 @@ are provided::
|
||||
template<typename T>
|
||||
concept Dimensionless = QuantityOf<T, dim_one>;
|
||||
|
||||
template<Unit U, QuantityValue Rep = double>
|
||||
template<Unit U, Representation Rep = double>
|
||||
using dimensionless = quantity<dim_one, U, Rep>;
|
||||
|
||||
There are two special units provided for usage with such a quantity:
|
||||
|
||||
@@ -68,7 +68,7 @@ Concepts
|
||||
satisfy :expr:`Quantity<typename T::value_type> || QuantityLike<typename T::value_type>` recursively
|
||||
(i.e. ``std::optional<si::length<si::metre>>``).
|
||||
|
||||
.. concept:: template<typename T> QuantityValue
|
||||
.. concept:: template<typename T> Representation
|
||||
|
||||
A concept matching types that can be used as a `Quantity` representation type. Satisfied
|
||||
by types that match ``(!Quantity<T>) && (!QuantityLike<T>) && (!WrappedQuantity<T>) && std::regular<T>``
|
||||
|
||||
@@ -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 `QuantityValue` concept
|
||||
A `Representation` concept
|
||||
--------------------------
|
||||
|
||||
To support a minimum set of `quantity` operations all custom representation types have to
|
||||
satisfy at least the `QuantityValue` concept. Which means that they:
|
||||
satisfy at least the `Representation` 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>>``),
|
||||
@@ -103,7 +103,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 `QuantityValue` concept guarantees us the possibility
|
||||
As noted in the previous chapter, the `Representation` 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.
|
||||
@@ -202,7 +202,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<QuantityValue Rep>
|
||||
template<Representation Rep>
|
||||
struct quantity_values {
|
||||
static constexpr Rep zero() noexcept { return Rep(0); }
|
||||
static constexpr Rep one() noexcept { return Rep(1); }
|
||||
@@ -223,7 +223,7 @@ types differently than the integral ones. This behavior can also be extended to
|
||||
representation types with `treat_as_floating_point` customization point which default
|
||||
definition is::
|
||||
|
||||
template<QuantityValue Rep>
|
||||
template<Representation 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
|
||||
|
||||
@@ -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<UnitOf<dim_desk_rate> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_desk_rate> U, Representation 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<UnitOf<dim_people> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_people> U, Representation 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<UnitOf<dim_occupancy_rate> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_occupancy_rate> U, Representation 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<UnitOf<dim_length> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_length> U, Representation 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<UnitOf<dim_length> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_length> U, Representation 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<UnitOf<dim_length> U, QuantityValue Rep = double>
|
||||
template<UnitOf<dim_length> U, Representation Rep = double>
|
||||
using length = quantity<dim_length, U, Rep>;
|
||||
|
||||
} // namespace fps
|
||||
|
||||
Reference in new issue
Block a user