mirror of
https://github.com/mpusz/mp-units.git
synced 2026-02-09 00:25:28 +01:00
refactor: 💥 make_xxx factory functions replaced with two-parameter constructors
Resolves #521
This commit is contained in:
@@ -50,15 +50,15 @@ quantity q = 42 * m;
|
||||
namespace.
|
||||
|
||||
In case someone doesn't like the multiply syntax or there is an ambiguity between `operator*`
|
||||
provided by this and other libraries, a quantity can also be created with a dedicated factory
|
||||
function:
|
||||
provided by this and other libraries, a quantity can also be created with a two-parameter
|
||||
constructor:
|
||||
|
||||
```cpp
|
||||
#include <mp-units/systems/si/si.h>
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
quantity q = make_quantity<si::metre>(42);
|
||||
quantity q{42, si::metre};
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -191,10 +191,10 @@ Quantity auto q = la_vector{1, 2, 3} * isq::velocity[m / s];
|
||||
In case there is an ambiguity of `operator*` between **mp-units** and a linear algebra library, we can
|
||||
either:
|
||||
|
||||
- use `make_quantity` factory function
|
||||
- use two-parameter constructor
|
||||
|
||||
```cpp
|
||||
Quantity auto q = make_quantity<isq::velocity[m / s]>(la_vector{1, 2, 3});
|
||||
Quantity auto q = quantity{la_vector{1, 2, 3}, isq::velocity[m / s]};
|
||||
```
|
||||
|
||||
- provide a dedicated overload of `operator*` that will resolve the ambiguity and wrap the above
|
||||
@@ -203,7 +203,7 @@ either:
|
||||
template<Reference R>
|
||||
Quantity auto operator*(la_vector rep, R)
|
||||
{
|
||||
return make_quantity<R{}>(rep);
|
||||
return quantity{rep, R{}};
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -102,11 +102,11 @@ quantity_point qp3 = mean_sea_level - 42 * m;
|
||||
|
||||
Similarly to [creation of a quantity](../../getting_started/quick_start.md#creating-a-quantity),
|
||||
if someone does not like the operator-based syntax to create a `quantity_point`, the same results
|
||||
can be achieved with `make_quantity_point` factory function:
|
||||
can be achieved with two-parameter constructor:
|
||||
|
||||
```cpp
|
||||
quantity_point qp4 = make_quantity_point<mean_sea_level>(42 * m);
|
||||
quantity_point qp5 = make_quantity_point<mean_sea_level>(-42 * m);
|
||||
quantity_point qp4{42 * m, mean_sea_level};
|
||||
quantity_point qp5{-42 * m, mean_sea_level};
|
||||
```
|
||||
|
||||
The provided `quantity` representing an offset from the origin is stored inside the `quantity_point`
|
||||
|
||||
Reference in New Issue
Block a user