forked from mpusz/mp-units
refactor: quantity cration helpers are not opt-out rather than opt-in
Resolves #277
This commit is contained in:
+1
-1
@@ -6,7 +6,6 @@
|
||||
- (!) refactor: Refactored the library file tree
|
||||
- (!) refactor: `quantity::count()` renamed to `quantity::number()`
|
||||
- (!) refactor: `data` system renamed to `isq::iec80000` (quantity names renamed too)
|
||||
- (!) refactor: quantity UDLs support has to be enabled with `UNITS_LITERALS` preprocessor define
|
||||
- refactor: quantity (kind) point updated to reflect latest changes to `quantity`
|
||||
- refactor: basic concepts, `quantity` and `quantity_cast` refactored
|
||||
- refactor: `abs()` definition refactored to be more explicit about the return type
|
||||
@@ -17,6 +16,7 @@
|
||||
- feat: CTAD for dimensionless quantity added
|
||||
- feat: `modulation_rate` support added (thanks [@go2sh](https://github.com/go2sh))
|
||||
- feat: SI prefixes for `isq::iec80000` support added (thanks [@go2sh](https://github.com/go2sh))
|
||||
- feat: a possibility to disable quantity UDLs support with `UNITS_NO_LITERALS` preprocessor define
|
||||
- perf: preconditions check do not influence the runtime performance of a Release build
|
||||
- perf: `quantity_cast()` generates less assembly instructions
|
||||
- perf: temporary string creation removed from `quantity::op<<()`
|
||||
|
||||
@@ -91,15 +91,3 @@ WARN_AS_ERROR = NO
|
||||
# The default value is: NO.
|
||||
|
||||
QUIET = YES
|
||||
|
||||
# The PREDEFINED tag can be used to specify one or more macro names that are
|
||||
# defined before the preprocessor is started (similar to the -D option of e.g.
|
||||
# gcc). The argument of the tag is a list of macros of the form: name or
|
||||
# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
|
||||
# is assumed. To prevent a macro definition from being undefined via #undef or
|
||||
# recursively expanded use the := operator instead of the = operator.
|
||||
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
|
||||
|
||||
PREDEFINED = UNITS_REFERENCES \
|
||||
UNITS_LITERALS \
|
||||
UNITS_ALIASES
|
||||
|
||||
@@ -70,7 +70,7 @@ Unit-Specific Aliases (Experimental)
|
||||
Additionally to the dimension-specific aliases there are also ones provided for
|
||||
each and every :term:`unit` in the library::
|
||||
|
||||
#ifdef UNITS_ALIASES
|
||||
#ifndef UNITS_NO_ALIASES
|
||||
|
||||
namespace units::aliases::isq::si::inline length {
|
||||
|
||||
@@ -86,7 +86,7 @@ each and every :term:`unit` in the library::
|
||||
|
||||
}
|
||||
|
||||
#endif // UNITS_ALIASES
|
||||
#endif // UNITS_NO_ALIASES
|
||||
|
||||
Using the above our code can look as follows::
|
||||
|
||||
@@ -116,7 +116,7 @@ Quantity References (Experimental)
|
||||
Quantity References provide an alternative and simplified way to create quantities.
|
||||
They are defined using the `reference` class template::
|
||||
|
||||
#ifdef UNITS_REFERENCES
|
||||
#ifndef UNITS_NO_REFERENCES
|
||||
|
||||
namespace length_references {
|
||||
|
||||
@@ -131,7 +131,7 @@ They are defined using the `reference` class template::
|
||||
|
||||
} // namespace references
|
||||
|
||||
#endif // UNITS_REFERENCES
|
||||
#endif // UNITS_NO_REFERENCES
|
||||
|
||||
With the above our code can look as follows::
|
||||
|
||||
@@ -157,7 +157,7 @@ User Defined Literals (Experimental)
|
||||
Alternatively, to construct quantities with compile-time known values the library provides
|
||||
:abbr:`UDL (User Defined Literal)` s for each :term:`unit` of every :term:`dimension`::
|
||||
|
||||
#ifdef UNITS_LITERALS
|
||||
#ifndef UNITS_NO_LITERALS
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
@@ -169,7 +169,7 @@ Alternatively, to construct quantities with compile-time known values the librar
|
||||
|
||||
}
|
||||
|
||||
#endif // UNITS_LITERALS
|
||||
#endif // UNITS_NO_LITERALS
|
||||
|
||||
Thanks to them the same code can be as simple as::
|
||||
|
||||
@@ -185,13 +185,6 @@ Thanks to them the same code can be as simple as::
|
||||
language (i.e. ``F`` (farad), ``J`` (joule), ``W`` (watt), ``K`` (kelvin),
|
||||
``d`` (day), ``l`` or ``L`` (litre), ``erg``, ``ergps``). This is why the
|
||||
``_q_`` prefix was consistently applied to all the UDLs.
|
||||
|
||||
.. important::
|
||||
|
||||
As one can read in the next section UDLs, are considered to be inferior to `Quantity References`_
|
||||
and their definition affects compile-time performance a lot. This is why they are an opt-in feature
|
||||
of the library and in order to use them one has to provide a `UNITS_LITERALS` preprocessor definition.
|
||||
|
||||
|
||||
UDLs vs Quantity References
|
||||
+++++++++++++++++++++++++++
|
||||
@@ -473,6 +466,19 @@ Summary
|
||||
+-----------------------------------------------+-------------+------------+---------------+
|
||||
|
||||
|
||||
Don't pay for what you don't use (compile-time performance)
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
As noted in the previous chapter, each quantity creation helper has a different impact on the compile-time
|
||||
performance. Aliases tend to be the fastest to compile but even their definition can be expensive for some
|
||||
if it is not used in the source code. This is why it is possible to opt-out from each or every quantity
|
||||
creation helper with the following preprocessor defines::
|
||||
|
||||
#define UNITS_NO_ALIASES
|
||||
#define UNITS_NO_REFERENCES
|
||||
#define UNITS_NO_LITERALS
|
||||
|
||||
|
||||
Dimension-specific Concepts
|
||||
---------------------------
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ Quick Start
|
||||
|
||||
Here is a small example of possible operations::
|
||||
|
||||
#define UNITS_REFERENCES
|
||||
|
||||
#include <units/isq/si/area.h>
|
||||
#include <units/isq/si/frequency.h>
|
||||
#include <units/isq/si/length.h>
|
||||
@@ -34,7 +32,7 @@ Here is a small example of possible operations::
|
||||
|
||||
.. admonition:: Try it on Compiler Explorer
|
||||
|
||||
`Example #1 <https://godbolt.org/z/53bTahKd8>`_
|
||||
`Example #1 <https://godbolt.org/z/5dvY8Woh1>`_
|
||||
|
||||
This library requires some C++20 features (concepts, classes as
|
||||
:abbr:`NTTP (Non-Type Template Parameter)`, ...). Thanks to them the user gets a powerful
|
||||
@@ -42,10 +40,6 @@ but still easy to use interface where all unit conversions and dimensional analy
|
||||
performed without sacrificing on accuracy. Please see the below example for a quick preview
|
||||
of basic library features::
|
||||
|
||||
#define UNITS_ALIASES
|
||||
#define UNITS_LITERALS
|
||||
#define UNITS_REFERENCES
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h>
|
||||
@@ -92,7 +86,7 @@ of basic library features::
|
||||
|
||||
.. admonition:: Try it on Compiler Explorer
|
||||
|
||||
`Example #2 <https://godbolt.org/z/jKnPPPEx6>`_
|
||||
`Example #2 <https://godbolt.org/z/9fnzfbhb6>`_
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user