Physical units put in the physical namespace (I am sorry)
This commit is contained in:
1 parent
771a9a1551
commit
7e935a4108
117 files changed
+352
-349
No files matched your search
+12
-12
@@ -148,7 +148,7 @@ in the design documentation.
|
||||
Coming back to units, here are a few examples of unit definitions:
|
||||
|
||||
```cpp
|
||||
namespace units::si {
|
||||
namespace units::physical::si {
|
||||
|
||||
// prefixes
|
||||
struct prefix : prefix_family {};
|
||||
@@ -170,7 +170,7 @@ struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilom
|
||||
|
||||
}
|
||||
|
||||
namespace units::us {
|
||||
namespace units::physical::us {
|
||||
|
||||
// length
|
||||
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio<9'144, 10'000>, si::metre> {};
|
||||
@@ -224,7 +224,7 @@ These identifiers provide total ordering of exponents of base dimensions in a de
|
||||
The SI physical units system defines 7 base dimensions:
|
||||
|
||||
```cpp
|
||||
namespace units::si {
|
||||
namespace units::physical::si {
|
||||
|
||||
struct dim_length : base_dimension<"L", metre> {};
|
||||
struct dim_mass : base_dimension<"M", kilogram> {};
|
||||
@@ -244,7 +244,7 @@ base unit is needed for the text output of unnamed derived units. Second, there
|
||||
one system of physical units. For example CGS definitions look as follows:
|
||||
|
||||
```cpp
|
||||
namespace units::cgs {
|
||||
namespace units::physical::cgs {
|
||||
|
||||
using si::centimetre;
|
||||
using si::gram;
|
||||
@@ -354,7 +354,7 @@ directly define a barye in terms of pascal or vice versa.
|
||||
Below are a few examples of derived dimension definitions:
|
||||
|
||||
```cpp
|
||||
namespace units::si {
|
||||
namespace units::physical::si {
|
||||
|
||||
struct dim_velocity : derived_dimension<dim_velocity, metre_per_second,
|
||||
exp<dim_length, 1>, exp<dim_time, -1>> {};
|
||||
@@ -448,8 +448,8 @@ Beside adding new elements a few other changes where applied compared to the `st
|
||||
|
||||
To simplify writing efficient generic code quantities of each dimension have associated:
|
||||
1. Concept (i.e. `units::Length`) that matches a length dimension of any physical systems.
|
||||
2. Per-system quantity alias (i.e. `units::si::length<Unit, Rep>` for
|
||||
`units::quantity<units::si::dim_length, Unit, Rep>`).
|
||||
2. Per-system quantity alias (i.e. `units::physical::si::length<Unit, Rep>` for
|
||||
`units::quantity<units::physical::si::dim_length, Unit, Rep>`).
|
||||
|
||||
Also, to help instantiate quantities with compile-time known values every unit in the library
|
||||
has an associated UDL. For example:
|
||||
@@ -603,9 +603,9 @@ user. If we will get a compilation error message containing `dim_capacitance` in
|
||||
the compiler will print the following type instead of the alias:
|
||||
|
||||
```text
|
||||
units::detail::derived_dimension_base<units::exp<units::si::dim_electric_current, 2, 1>,
|
||||
units::exp<units::si::dim_length, -2, 1>, units::exp<units::si::dim_mass, -1, 1>,
|
||||
units::exp<units::si::dim_time, 4, 1> >
|
||||
units::detail::derived_dimension_base<units::exp<units::physical::si::dim_electric_current, 2, 1>,
|
||||
units::exp<units::physical::si::dim_length, -2, 1>, units::exp<units::physical::si::dim_mass, -1, 1>,
|
||||
units::exp<units::physical::si::dim_time, 4, 1> >
|
||||
```
|
||||
|
||||
You can notice that even this long syntax was carefully selected to provide quite good user
|
||||
@@ -760,8 +760,8 @@ struct unknown_dimension : derived_dimension<unknown_dimension<E, ERest...>,
|
||||
with this the error log or a debugger breakpoint involving a `temp1` type will include:
|
||||
|
||||
```text
|
||||
units::quantity<units::unknown_dimension<units::exp<units::si::dim_length, 2, 1>,
|
||||
units::exp<units::si::dim_time, -1, 1> >, units::unknown_coherent_unit, long int>
|
||||
units::quantity<units::unknown_dimension<units::exp<units::physical::si::dim_length, 2, 1>,
|
||||
units::exp<units::physical::si::dim_time, -1, 1> >, units::unknown_coherent_unit, long int>
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ Design Deep Dive
|
||||
For brevity all the code examples in this chapter assume::
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -6,6 +6,7 @@ Framework Basics
|
||||
For brevity all the code examples in this chapter assume::
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -47,7 +47,7 @@ values the library provides :abbr:`UDL (User Defined Literal)` s for each
|
||||
:term:`unit` of every :term:`dimension`. Thanks to them the same code can
|
||||
be as simple as::
|
||||
|
||||
using namespace si::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
constexpr auto d1 = 123q_km; // si::length<si::kilometre, std::int64_t>
|
||||
constexpr auto d2 = 123.q_km; // si::length<si::kilometre, long double>
|
||||
|
||||
@@ -66,7 +66,7 @@ In case the user does not care about the specific unit and representation but
|
||||
requires quantity of a concrete dimension than dimension-specific concepts can
|
||||
be used::
|
||||
|
||||
using namespace si::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
constexpr Length auto d = 123q_km; // si::length<si::kilometre, std::int64_t>
|
||||
|
||||
.. note::
|
||||
@@ -80,8 +80,8 @@ assume that the user wants to implement an ``avg_speed`` function that will
|
||||
be calculating the average speed based on provided distance and duration
|
||||
quantities. The usage of such a function can look as follows::
|
||||
|
||||
using namespace si::literals;
|
||||
using namespace international::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
using namespace units::physical::international::literals;
|
||||
constexpr Velocity auto v1 = avg_speed(220q_km, 2q_h);
|
||||
constexpr Velocity auto v2 = avg_speed(140q_mi, 2q_h);
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ Output Streams
|
||||
The easiest way to print a quantity is to provide its object to the output
|
||||
stream::
|
||||
|
||||
using namespace si::literals;
|
||||
using namespace international::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
using namespace units::physical::international::literals;
|
||||
constexpr Velocity auto v1 = avg_speed(220.q_km, 2q_h);
|
||||
constexpr Velocity auto v2 = avg_speed(140.q_mi, 2q_h);
|
||||
std::cout << v1 << '\n'; // 110 km/h
|
||||
|
||||
@@ -161,8 +161,8 @@ of ``N/m``):
|
||||
:emphasize-lines: 2
|
||||
|
||||
struct dim_surface_tension : derived_dimension<dim_surface_tension, newton_per_metre,
|
||||
exp<si::dim_force, 1>,
|
||||
exp<si::dim_length, -1>> {}; // N/m
|
||||
exp<si::dim_force, 1>,
|
||||
exp<si::dim_length, -1>> {}; // N/m
|
||||
|
||||
If we defined the above in terms of base units we would end up with
|
||||
a ``kg/s²`` derived unit symbol.
|
||||
@@ -361,7 +361,7 @@ and user should not instantiate it by him/her-self. However the user can sometim
|
||||
observe this type in case an unit/dimension conversion expression will end up with an
|
||||
unknown/undefined unit type like in the below example::
|
||||
|
||||
using namespace si::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
|
||||
Length auto l = 100q_km_per_h * 10q_s;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ of basic library features::
|
||||
#include <units/physical/international/velocity.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ of basic library features::
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace si::literals;
|
||||
using namespace units::physical::si::literals;
|
||||
Velocity auto v1 = avg_speed(220q_km, 2q_h);
|
||||
Velocity auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
|
||||
Velocity auto v3 = quantity_cast<si::metre_per_second>(v2);
|
||||
|
||||
@@ -8,7 +8,7 @@ Systems
|
||||
SI
|
||||
--
|
||||
|
||||
.. doxygennamespace:: units::si
|
||||
.. doxygennamespace:: units::physical::si
|
||||
:members:
|
||||
:undoc-members:
|
||||
:outline:
|
||||
|
||||
@@ -6,6 +6,7 @@ Use Cases
|
||||
For brevity all the code examples in this chapter assume::
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
@@ -21,7 +21,7 @@ pass it to the library's output:
|
||||
#include "legacy.h"
|
||||
#include <units/physical/si/velocity.h>
|
||||
|
||||
using namespace units;
|
||||
using namespace units::physical;
|
||||
|
||||
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user