Skip to content

Commit

Permalink
Merge branch 'master' into feature/more-value-casts
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz authored Jun 14, 2024
2 parents da17b01 + f49b4c6 commit b113f6a
Show file tree
Hide file tree
Showing 102 changed files with 1,301 additions and 1,029 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
### 2.2.0 <small>WIP</small> { id="2.2.0" }

- (!) feat: C++ modules support added by [@JohelEGP](https://github.com/JohelEGP)
- (!) feat: formatting grammar improved and units formatting support added
- (!) feat: New formatting specification implemented
- (!) feat: `has_unit_symbol` support removed
- (!) feat: ABI concerns resolved with introduction of u8 strings for symbols
- (!) feat: API-related Conan, CMake, and preprocessor options redesigned
- (!) feat: :boom: `core.h` removed
- (!) feat: `core.h` removed
- (!) feat: from now on units, dimensions, quantity specifications, and point origins have to be marked as `final`
- feat: implicit point origins support added
- feat: unit default point origin support added
- feat: `fma`, `isfinite`, `isinf`, and `isnan` math function added by [@NAThompson](https://github.com/NAThompson)
Expand All @@ -29,10 +30,10 @@
- feat: unit text output support added
- feat: formatting error messages improved
- feat: improve types readability by eliminating extraneous `()` in references, prefixes, and `kind_of`
- feat: dimension text output added
- feat: dimension and unit text output added
- feat: some light and radiation ISQ quantities added
- feat: New formatting specification implemented
- feat: allow configuring GSL library use
- feat: freestanding support added
- (!) refactor: `zero_Fahrenheit` renamed to `zeroth_degree_Fahrenheit`
- (!) refactor: SI-related trigonometric functions moved to the `si` subnamespace
- (!) refactor: `math.h` header file broke up to smaller pieces
Expand All @@ -47,13 +48,18 @@
- (!) refactor: `framework.h` introduced
- (!) refactor: type list tools made an implementation detail of the library
- (!) refactor: header files with the entire system definitions moved up in the directory tree
- (!) refactor: `absolute_point_origin` does not use CRTP anymore
- refactor: system's units do not inherit from one another anymore
- refactor: all units made `final`
- refactor: math functions constraints refactored
- refactor: `si_quantities.h` added to improve compile-times
- refactor: `validate_ascii_string` refactored to `is_basic_literal_character_set`
- refactor: `underlying_type` split to `wrapped_type` and `value_type` and used in code
- refactor: code refactored to comply with clang-tidy
- refactor: remove dependency on `<ranges>` header and switch to use an iterator-based `copy` algorithm
- refactor: `terminate` replaced with `abort` and a header file added
- refactor: most `std::remove_const_t` removed and some replaced with the GCC-specific workaround
- refactor: not needed `remove_reference_t` and `remove_cvref_t` removed
- fix: `QuantityLike` conversions required `Q::rep` instead of using one provided by `quantity_like_traits`
- fix: `QuantitySpec[Unit]` replaced with `make_reference` in `value_cast`
- fix: `ice_point` is now defined with the integral offset from `absolute_zero`
Expand Down Expand Up @@ -82,6 +88,7 @@
- docs: "Text Output" chapter updated with the recent formatting changes
- docs: formatting grammar language changed to EBNF
- docs: "Project structure" chapter expanded
- docs: CITATION.cff updated
- (!) build: Conan and CMake options refactored
- (!) build: `MP_UNITS_AS_SYSTEM_HEADERS` renamed to `MP_UNITS_BUILD_AS_SYSTEM_HEADERS`
- (!) build: `MP_UNITS_BUILD_LA` and `MP_UNITS_IWYU` CMake options now have `_DEV_` in the name
Expand All @@ -97,6 +104,7 @@
- build(conan): `can_run` check added before running tests
- ci: Conan and CMake CI now use different cache names
- ci: gcc-14 added
- ci: `clang-tidy` CI added

### 2.1.1 <small>May 16, 2024</small> { id="2.1.1" }

Expand Down
59 changes: 44 additions & 15 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,13 @@ def set_version(self):
self.version = version.strip()

def requirements(self):
if self.options.contracts == "gsl-lite":
self.requires("gsl-lite/0.41.0")
elif self.options.contracts == "ms-gsl":
self.requires("ms-gsl/4.0.0")
if self._use_fmtlib and not self.options.freestanding:
self.requires("fmt/10.2.1")
if not self.options.freestanding:
if self.options.contracts == "gsl-lite":
self.requires("gsl-lite/0.41.0")
elif self.options.contracts == "ms-gsl":
self.requires("ms-gsl/4.0.0")
if self._use_fmtlib:
self.requires("fmt/10.2.1")

def build_requirements(self):
if self._build_all:
Expand Down Expand Up @@ -248,17 +249,19 @@ def generate(self):
tc.cache_variables["MP_UNITS_BUILD_CXX_MODULES"] = str(
self.options.cxx_modules
).upper()
tc.cache_variables["MP_UNITS_API_STD_FORMAT"] = str(
self.options.std_format
).upper()
if self.options.freestanding:
tc.cache_variables["MP_UNITS_API_FREESTANDING"] = True
else:
tc.cache_variables["MP_UNITS_API_STD_FORMAT"] = str(
self.options.std_format
).upper()
tc.cache_variables["MP_UNITS_API_STRING_VIEW_RET"] = str(
self.options.string_view_ret
).upper()
tc.cache_variables["MP_UNITS_API_NO_CRTP"] = str(self.options.no_crtp).upper()
tc.cache_variables["MP_UNITS_API_CONTRACTS"] = str(
self.options.contracts
).upper()
tc.cache_variables["MP_UNITS_API_FREESTANDING"] = self.options.freestanding
tc.generate()
deps = CMakeDeps(self)
deps.generate()
Expand All @@ -285,13 +288,39 @@ def package(self):

def package_info(self):
compiler = self.settings.compiler
self.cpp_info.components["core"]
if self.options.contracts == "gsl-lite":
self.cpp_info.components["core"].requires = ["gsl-lite::gsl-lite"]

# handle contracts
if self.options.contracts == "none":
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=0")
elif self.options.contracts == "gsl-lite":
self.cpp_info.components["core"].requires.append("gsl-lite::gsl-lite")
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=2")
elif self.options.contracts == "ms-gsl":
self.cpp_info.components["core"].requires = ["ms-gsl::ms-gsl"]
if self._use_fmtlib and not self.options.freestanding:
self.cpp_info.components["core"].requires.append("ms-gsl::ms-gsl")
self.cpp_info.components["core"].defines.append("MP_UNITS_API_CONTRACTS=3")

# handle API options
if self.options.string_view_ret != "auto":
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_STRING_VIEW_RET="
+ str(int(self.options.string_view_ret == True))
)
if self.options.no_crtp != "auto":
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_NO_CRTP=" + str(int(self.options.no_crtp == True))
)
if self.options.std_format != "auto":
self.cpp_info.components["core"].defines.append(
"MP_UNITS_API_STD_FORMAT=" + str(int(self.options.std_format == True))
)
if self._use_fmtlib:
self.cpp_info.components["core"].requires.append("fmt::fmt")

# handle hosted configuration
if not self.options.freestanding:
self.cpp_info.components["core"].defines.append("MP_UNITS_HOSTED=1")

if compiler == "msvc":
self.cpp_info.components["core"].cxxflags = ["/utf-8"]

self.cpp_info.components["systems"].requires = ["core"]
61 changes: 55 additions & 6 deletions docs/blog/posts/2.2.0-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Additionally, some CMake options were renamed to better express the impact on ou
Before this release, the library always depended on [gsl-lite](https://github.com/gsl-lite/gsl-lite)
to perform runtime contract and asserts checking. In this release we introduced new options
to control if contract checking should be based on [gsl-lite](https://github.com/gsl-lite/gsl-lite),
[ms-gsl](https://github.com/microsoft/GSL), or maybe completely disabled.
[ms-gsl](https://github.com/microsoft/GSL), or may be completely disabled.


## Freestanding support
Expand Down Expand Up @@ -205,7 +205,7 @@ origins. For example:
=== "Before"

```cpp
constexpr struct zero : absolute_point_origin<zero, currency> {} zero;
constexpr struct zero final : absolute_point_origin<currency> {} zero;

quantity_point price_usd = zero + 100 * USD;
```
Expand Down Expand Up @@ -260,6 +260,16 @@ named with its corresponding unit and with the `si::zeroth_degree_Celsius`

## Changes to units definitions

There were several known issues when units were deriving from each other
(e.g., [#512](https://github.com/mpusz/mp-units/issues/512) and
[#537](https://github.com/mpusz/mp-units/issues/537)). We could either highly complicate the
framework to allow these which could result in much longer compilation times or disallow inheriting
from units at all. We chose the second option.

With this release all of of the units must be marked as `final`. To enforce this we have changed
the definition of the `Unit<T>` concept, which now requires type `T` to be `final`
(:boom: **breaking change** :boom:).

[WG21 Study Group 16 (Unicode) raised concerns](https://github.com/sg16-unicode/sg16-meetings#january-24th-2024)
about potential ABI issues when different translation units are compiled with different ordinary
literal encodings. Those issues were resolved with a change to units definitions
Expand All @@ -272,7 +282,7 @@ is why it was renamed to `symbol_text` (:boom: **breaking change** :boom:).
=== "Now"

```cpp
inline constexpr struct ohm : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
inline constexpr struct ohm final : named_unit<symbol_text{u8"Ω", "ohm"}, volt / ampere> {} ohm;
```

=== "Before"
Expand All @@ -286,9 +296,48 @@ is why it was renamed to `symbol_text` (:boom: **breaking change** :boom:).
On C++20-compliant compilers it should be enough to type the following in the unit's definition:

```cpp
inline constexpr struct ohm : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
inline constexpr struct ohm final : named_unit<{u8"Ω", "ohm"}, volt / ampere> {} ohm;
```


## Changes to dimension, quantity specification, and point origins definitions

Similarly to units, now also all dimensions, quantity specifications, and point origins have to be
marked `final` (:boom: **breaking change** :boom:).

=== "Now"

```cpp
inline constexpr struct dim_length final : base_dimension<"L"> {} dim_length;
inline constexpr struct length final : quantity_spec<dim_length> {} length;

inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
inline constexpr auto zeroth_kelvin = absolute_zero;
inline constexpr struct kelvin final : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;

inline constexpr struct ice_point final : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
inline constexpr auto zeroth_degree_Celsius = ice_point;
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"°C", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
```

=== "Before"

```cpp
inline constexpr struct dim_length : base_dimension<"L"> {} dim_length;
inline constexpr struct length : quantity_spec<dim_length> {} length;

inline constexpr struct absolute_zero : absolute_point_origin<absolute_zero, isq::thermodynamic_temperature> {} absolute_zero;
inline constexpr struct zeroth_kelvin : decltype(absolute_zero) {} zeroth_kelvin;
inline constexpr struct kelvin : named_unit<"K", kind_of<isq::thermodynamic_temperature>, zeroth_kelvin> {} kelvin;

inline constexpr struct ice_point : relative_point_origin<quantity_point{273'150 * milli<kelvin>}> {} ice_point;
inline constexpr struct zeroth_degree_Celsius : decltype(ice_point) {} zeroth_degree_Celsius;
inline constexpr struct degree_Celsius : named_unit<symbol_text{u8"°C", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;
```

Please also note, that the `absolute_point_origin` does not use CRTP idiom anymore (:boom: **breaking change** :boom:).


## Improved text output

With this release, we can print not only whole quantities but also just their units or dimensions.
Expand Down Expand Up @@ -461,8 +510,8 @@ conversion factor. Here is a comparison of the code with previous and current de
=== "Now"

```cpp
inline constexpr struct yard : named_unit<"yd", mag_ratio<9'144, 10'000> * si::metre> {} yard;
inline constexpr struct foot : named_unit<"ft", mag_ratio<1, 3> * yard> {} foot;
inline constexpr struct yard final : named_unit<"yd", mag_ratio<9'144, 10'000> * si::metre> {} yard;
inline constexpr struct foot final : named_unit<"ft", mag_ratio<1, 3> * yard> {} foot;
```

=== "Before"
Expand Down
6 changes: 3 additions & 3 deletions docs/getting_started/installation_and_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

[`MP_UNITS_API_STD_FORMAT`](#MP_UNITS_API_STD_FORMAT){ #MP_UNITS_API_STD_FORMAT }

: [:octicons-tag-24: 2.2.0][use fmtlib support] · :octicons-milestone-24: `AUTO`/`ON`/`OFF` (Default: `AUTO`)
: [:octicons-tag-24: 2.2.0][use fmtlib support] · :octicons-milestone-24: `AUTO`/`TRUE`/`FALSE` (Default: `AUTO`)

Enables the usage of [`std::format`](https://en.cppreference.com/w/cpp/utility/format/format)
and associated facilities for text formatting. If it is not supported, then
Expand All @@ -352,7 +352,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

[`MP_UNITS_API_STRING_VIEW_RET`](#MP_UNITS_API_STRING_VIEW_RET){ #MP_UNITS_API_STRING_VIEW_RET }

: [:octicons-tag-24: 2.2.0][cmake returning string_view] · :octicons-milestone-24: `AUTO`/`ON`/`OFF` (Default: `AUTO`)
: [:octicons-tag-24: 2.2.0][cmake returning string_view] · :octicons-milestone-24: `AUTO`/`TRUE`/`FALSE` (Default: `AUTO`)

Enables returning `std::string_view` from the
[`unit_symbol()`](../users_guide/framework_basics/text_output.md#unit_symbol)
Expand All @@ -364,7 +364,7 @@ tools.build:compiler_executables={"c": "gcc-12", "cpp": "g++-12"}

[`MP_UNITS_API_NO_CRTP`](#MP_UNITS_API_NO_CRTP){ #MP_UNITS_API_NO_CRTP }

: [:octicons-tag-24: 2.2.0][cmake no crtp support] · :octicons-milestone-24: `AUTO`/`ON`/`OFF` (Default: `AUTO`)
: [:octicons-tag-24: 2.2.0][cmake no crtp support] · :octicons-milestone-24: `AUTO`/`TRUE`/`FALSE` (Default: `AUTO`)

Removes the need for the usage of the CRTP idiom in the
[`quantity_spec` definitions](../users_guide/framework_basics/systems_of_quantities.md#defining-quantities).
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units)

using namespace mp_units;

inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot;
inline constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
Expand All @@ -53,7 +53,7 @@ The library source code is hosted on [GitHub](https://github.com/mpusz/mp-units)

using namespace mp_units;

inline constexpr struct smoot : named_unit<"smoot", mag<67> * usc::inch> {} smoot;
inline constexpr struct smoot final : named_unit<"smoot", mag<67> * usc::inch> {} smoot;

int main()
{
Expand All @@ -69,7 +69,7 @@ Output:
Harvard Bridge length = 364.4 smoot (2034.6 ft, 620.14 m) ± 1 εar
```

!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/zsW1f6Tn1)"
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/f8f4KnKh8)"

??? question "What is `smoot`?"

Expand Down
2 changes: 1 addition & 1 deletion docs/users_guide/examples/avg_speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tags:

# `avg_speed`

!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/EYo7879qd)"
!!! example "[Try it on Compiler Explorer](https://godbolt.org/z/TnqGa4sdn)"

Let's continue the previous example. This time, our purpose will not be to showcase as many
library features as possible, but we will scope on different interfaces one can provide
Expand Down
Loading

0 comments on commit b113f6a

Please sign in to comment.