forked from mpusz/mp-units
Custom representation types chapter updated
This commit is contained in:
@@ -33,9 +33,9 @@ The difference between the above types is that ``impl`` class is implicitly cons
|
|||||||
from values of type ``T`` while ``expl`` is not. To create quantities using those types as
|
from values of type ``T`` while ``expl`` is not. To create quantities using those types as
|
||||||
representation types we have to obey similar rules::
|
representation types we have to obey similar rules::
|
||||||
|
|
||||||
si::length<si::metre, impl<int>> d1(123); // OK
|
si::length<si::metre, impl<int>> d1(123); // OK
|
||||||
si::length<si::metre, expl<int>> d2(123); // Compile-time error
|
si::length<si::metre, expl<int>> d2(123); // Compile-time error
|
||||||
si::length<si::metre, expl<int>> d3(expl(123)); // OK
|
si::length<si::metre, expl<int>> d3(expl(123)); // OK
|
||||||
|
|
||||||
This also applies when we want to create a quantity with a custom representation type
|
This also applies when we want to create a quantity with a custom representation type
|
||||||
from a regular quantity value::
|
from a regular quantity value::
|
||||||
@@ -50,7 +50,10 @@ Conversions of Quantities with Custom Representation Types
|
|||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
|
|
||||||
Again let's assume two types but this time let's scope on converting operators rather
|
Again let's assume two types but this time let's scope on converting operators rather
|
||||||
than on constructors::
|
than on constructors:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
:emphasize-lines: 5, 13
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class impl {
|
class impl {
|
||||||
@@ -68,13 +71,13 @@ than on constructors::
|
|||||||
// the rest of the representation type implementation
|
// the rest of the representation type implementation
|
||||||
};
|
};
|
||||||
|
|
||||||
If we have instances of the above types we can construct quantities in the folLowing way::
|
If we have instances of the above types we can construct quantities in the following way::
|
||||||
|
|
||||||
impl<int> v_impl(1);
|
impl<int> v_impl(1);
|
||||||
expl<int> v_expl(1);
|
expl<int> v_expl(1);
|
||||||
si::length<si::metre, int> d1(v_impl); // OK
|
si::length<si::metre, int> d1(v_impl); // OK
|
||||||
si::length<si::metre, int> d2(v_expl); // Compile-time error
|
si::length<si::metre, int> d2(v_expl); // Compile-time error
|
||||||
si::length<si::metre, int> d3(int(v_expl); // OK
|
si::length<si::metre, int> d3(int(v_expl); // OK
|
||||||
|
|
||||||
Similarly, when we have quantities of above types we can create quantities of other
|
Similarly, when we have quantities of above types we can create quantities of other
|
||||||
representation types with::
|
representation types with::
|
||||||
@@ -96,4 +99,4 @@ Customization points
|
|||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
For more examples of custom representation types usage please refer to
|
For more examples of custom representation types usage please refer to
|
||||||
:ref:`Linear Algebra of Quantities` chapter and `measurement` example.
|
:ref:`Linear Algebra of Quantities` chapter and :ref:`measurement` example.
|
Reference in New Issue
Block a user