docs: Documentation now prefers refrences over UDLs

This commit is contained in:
Mateusz Pusz
2021-04-02 13:11:20 +02:00
parent 7cc34646b9
commit c4e9ff7f66
12 changed files with 211 additions and 175 deletions
@@ -92,7 +92,7 @@ representation types we have to obey similar rules::
This also applies when we want to create a quantity with a custom representation type
from a regular quantity value::
Length auto d = 123_q_m;
Length auto d = 123 * m;
si::length<si::metre, impl> d1(d); // OK
si::length<si::metre, expl> d2(d); // Compile-time error
si::length<si::metre, expl> d3(quantity_cast<expl>(d)); // OK
+1 -1
View File
@@ -130,7 +130,7 @@ coherent unit::
With the above we can now check what is the production rate::
DeskRate auto rate = quantity_cast<desk_per_hour>(3._d / 20_q_min);
DeskRate auto rate = quantity_cast<desk_per_hour>(3._d / (20 * min));
std::cout << "Desk rate: " << rate << '\n'; // prints 'Desk rate: 9 desk/h'
and how much wood is being consumed over a unit of time::
+4 -4
View File
@@ -38,9 +38,9 @@ such an explicit conversion::
using namespace std::chrono_literals;
static_assert(quantity{1s} + 1_q_s == 2_q_s);
static_assert(quantity{1s} + 1_q_min == 61_q_s);
static_assert(10_q_m / quantity{2s} == 5_q_m_per_s);
static_assert(quantity{1s} + 1 * s == 2 * s);
static_assert(quantity{1s} + 1 * min == 61 * s);
static_assert(10 * m / quantity{2s} == 5 * (m / s));
.. note::
@@ -63,4 +63,4 @@ provide a deduction guide from `QuantityPointLike`::
using namespace std::chrono_literals;
static_assert(quantity_point{std::chrono::sys_seconds{1s}} + 1_q_s == quantity_point{2s});
static_assert(quantity_point{std::chrono::sys_seconds{1s}} + 1 * s == quantity_point{2s});
+6 -6
View File
@@ -27,9 +27,9 @@ The official :term:`quantity` definition states:
So the most common use case would be to create a vector or matrix of quantities::
fs_vector<si::length<si::metre>, 3> v = { 1_q_m, 2_q_m, 3_q_m };
fs_vector<si::length<si::metre>, 3> u = { 3_q_m, 2_q_m, 1_q_m };
fs_vector<si::length<si::kilometre>, 3> t = { 3_q_km, 2_q_km, 1_q_km };
fs_vector<si::length<si::metre>, 3> v = { 1 * m, 2 * m, 3 * m };
fs_vector<si::length<si::metre>, 3> u = { 3 * m, 2 * m, 1 * m };
fs_vector<si::length<si::kilometre>, 3> t = { 3 * km, 2 * km, 1 * km };
Having such definitions we can perform full dimensional analysis operations for the operations
allowed by the Linear Algebra rules. For example::
@@ -38,7 +38,7 @@ allowed by the Linear Algebra rules. For example::
std::cout << "v + t = " << v + t << "\n";
std::cout << "t[m] = " << fs_vector<si::length<si::metre>, 3>(t) << "\n";
std::cout << "v * u = " << v * u << "\n";
std::cout << "2_q_m * v = " << 2_q_m * v << "\n";
std::cout << "2 * m * v = " << 2 * m * v << "\n";
The above code works as expected and produces the following output:
@@ -48,7 +48,7 @@ The above code works as expected and produces the following output:
v + t = | 3001 m 2002 m 1003 m |
t[m] = | 3000 m 2000 m 1000 m |
v * u = 10 m²
2_q_m * v = | 2 m² 4 m² 6 m² |
2 * m * v = | 2 m² 4 m² 6 m² |
Quantities of Linear Algebra Types
@@ -79,7 +79,7 @@ output:
v + t = | 3001 2002 1003 | m
t[m] = | 3000 2000 1000 | m
v * u = 10 m²
2_q_m * v = | 2 4 6 | m²
2 * m * v = | 2 4 6 | m²
.. seealso::
+7 -5
View File
@@ -25,8 +25,9 @@ The same applies to the resulting unit. For example:
#include <units/isq/si/si.h>
using namespace units::isq::si;
using namespace units::isq::si::references;
constexpr auto result = 144_q_km / 2_q_h;
constexpr auto result = 144 * km / (2 * h);
static_assert(std::is_same_v<decltype(result)::dimension,
dim_speed>);
static_assert(std::is_same_v<decltype(result)::unit,
@@ -45,8 +46,9 @@ dimensions used in the division operation:
#include <units/isq/si/time.h>
using namespace units::isq::si;
using namespace units::isq::si::references;
constexpr auto result = 144_q_km / 2_q_h;
constexpr auto result = 144 * km / (2 * h);
static_assert(std::is_same_v<decltype(result)::dimension,
unknown_dimension<exponent<dim_length, 1>, exponent<dim_time, -1>>>);
static_assert(std::is_same_v<decltype(result)::unit,
@@ -103,10 +105,10 @@ in your program. A typical example here are temporary results of a long calculat
{
Speed auto s1 = avg_speed(d, t);
auto temp1 = s1 * 200_q_km; // intermediate unknown dimension
auto temp1 = s1 * (200 * km); // intermediate unknown dimension
Speed auto s2 = temp1 / 50_q_km; // back to known dimensions again
Length auto d2 = s2 * 4_q_h;
Speed auto s2 = temp1 / (50 * km); // back to known dimensions again
Length auto d2 = s2 * (4 * h);
// ...
}