diff --git a/docs/users_guide/examples/hello_units.md b/docs/users_guide/examples/hello_units.md index c77f2287..c33e9034 100644 --- a/docs/users_guide/examples/hello_units.md +++ b/docs/users_guide/examples/hello_units.md @@ -18,20 +18,20 @@ First, we either import the `mp_units` module or include the headers for: - text formatting and stream output support ```cpp title="hello_units.cpp" linenums="1" ---8<-- "example/hello_units.cpp:28:40" +--8<-- "example/hello_units.cpp:28:41" ``` Also, to shorten the definitions, we "import" all the symbols from the `mp_units` namespace. -```cpp title="hello_units.cpp" linenums="13" ---8<-- "example/hello_units.cpp:41:42" +```cpp title="hello_units.cpp" linenums="14" +--8<-- "example/hello_units.cpp:42:43" ``` Next, we define a simple function that calculates the average speed based on the provided arguments of length and time: -```cpp title="hello_units.cpp" linenums="14" ---8<-- "example/hello_units.cpp:43:46" +```cpp title="hello_units.cpp" linenums="15" +--8<-- "example/hello_units.cpp:44:47" ``` The above function template takes any quantities implicitly convertible to `isq::length` @@ -45,37 +45,37 @@ that its quantity type is implicitly convertible to `isq::speed`. type is beneficial for users of such a function as it provides more information of what to expect from a function than just using `auto`. -```cpp title="hello_units.cpp" linenums="18" ---8<-- "example/hello_units.cpp:48:51" +```cpp title="hello_units.cpp" linenums="19" +--8<-- "example/hello_units.cpp:49:52" ``` The above lines explicitly opt into using unit symbols from two systems of units. As this introduces a lot of short identifiers into the current scope, it is not done implicitly while including a header file. -```cpp title="hello_units.cpp" linenums="22" ---8<-- "example/hello_units.cpp:53:59" +```cpp title="hello_units.cpp" linenums="23" +--8<-- "example/hello_units.cpp:54:60" ``` -- Lines `21` & `22` create a quantity of kind `isq::length / isq::time` with the numbers +- Lines `23` & `24` create a quantity of kind `isq::length / isq::time` with the numbers and units provided. Such quantities can be converted or assigned to any other quantity with a matching kind. -- Line `23` calls our function template with quantities of kind `isq::length` and +- Line `25` calls our function template with quantities of kind `isq::length` and `isq::time` and number and units provided. -- Line `24` explicitly provides quantity types of the quantities passed to a function template. +- Line `26` explicitly provides quantity types of the quantities passed to a function template. This time, those will not be quantity kinds anymore and will have [more restrictive conversion rules](../framework_basics/simple_and_typed_quantities.md#quantity_cast-to-force-unsafe-conversions). -- Line `25` changes the unit of a quantity `v3` to `m / s` in a +- Line `27` changes the unit of a quantity `v3` to `m / s` in a [value-preserving way](../framework_basics/value_conversions.md#value-preserving-conversions) (floating-point representations are considered to be value-preserving). -- Line `26` does a similar operation, but this time, it would also succeed for +- Line `28` does a similar operation, but this time, it would also succeed for [value-truncating cases](../framework_basics/value_conversions.md#value-truncating-conversions) (if that was the case). -- Line `27` does a [value-truncating conversion](../framework_basics/value_conversions.md#value-truncating-conversions) +- Line `29` does a [value-truncating conversion](../framework_basics/value_conversions.md#value-truncating-conversions) of changing the underlying representation type from `double` to `int`. -```cpp title="hello_units.cpp" linenums="29" ---8<-- "example/hello_units.cpp:61" +```cpp title="hello_units.cpp" linenums="30" +--8<-- "example/hello_units.cpp:62" ``` The above presents [various ways to print a quantity](../framework_basics/text_output.md). diff --git a/docs/users_guide/examples/si_constants.md b/docs/users_guide/examples/si_constants.md index ab331bc6..0a2f5496 100644 --- a/docs/users_guide/examples/si_constants.md +++ b/docs/users_guide/examples/si_constants.md @@ -13,7 +13,7 @@ how [Faster-than-lightspeed Constants](../framework_basics/faster_than_lightspee work in practice. ```cpp title="si_constants.cpp" linenums="1" ---8<-- "example/si_constants.cpp:28:39" +--8<-- "example/si_constants.cpp:28:40" ``` As always, we start with the inclusion of all the needed header files. After that, for @@ -21,8 +21,8 @@ the simplicity of this example, we [hack the character of quantities](../framework_basics/character_of_a_quantity.md#hacking-the-character) to be able to express vector quantities with simple scalar types. -```cpp title="si_constants.cpp" linenums="13" ---8<-- "example/si_constants.cpp:41:" +```cpp title="si_constants.cpp" linenums="14" +--8<-- "example/si_constants.cpp:42:" ``` The main part of the example prints all of the SI-defining constants. While analyzing the output of diff --git a/docs/users_guide/use_cases/wide_compatibility.md b/docs/users_guide/use_cases/wide_compatibility.md index b8e7d465..c8aa6211 100644 --- a/docs/users_guide/use_cases/wide_compatibility.md +++ b/docs/users_guide/use_cases/wide_compatibility.md @@ -96,6 +96,7 @@ your code using **mp-units**: ```cpp #include + #include #ifdef MP_UNITS_MODULES #include import mp_units; @@ -158,6 +159,13 @@ This macro resolves to either the `std` or `fmt` namespace, depending on the val [MP_UNITS_API_STD_FORMAT](../../getting_started/installation_and_usage.md#MP_UNITS_API_STD_FORMAT) CMake option. +To include the header files of the underlying text formatting framework, the following include +should be used: + +```cpp +#include +``` + ### Contracts The mp-units library internally does contract checking by default. It can be disabled with a Conan diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index dbdca1e3..a1f252ad 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index b95c018e..cc5ff291 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include #include diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index f62804f5..2bb1e7d0 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include #include #include diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index 4da86872..e263d149 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -24,6 +24,7 @@ #include "glide_computer_lib.h" #include #include +#include #include #include #include diff --git a/example/glide_computer_lib/glide_computer_lib.cpp b/example/glide_computer_lib/glide_computer_lib.cpp index 7c144939..6342a905 100644 --- a/example/glide_computer_lib/glide_computer_lib.cpp +++ b/example/glide_computer_lib/glide_computer_lib.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "glide_computer_lib.h" +#include #include #include #include diff --git a/example/hello_units.cpp b/example/hello_units.cpp index 283b223e..f11f8a3a 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -26,6 +26,7 @@ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/include/geographic.h b/example/include/geographic.h index 5366303c..53e086e3 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -24,6 +24,7 @@ #include "ranged_representation.h" #include +#include #include #include #include diff --git a/example/include/ranged_representation.h b/example/include/ranged_representation.h index 9fc493cd..350a3b04 100644 --- a/example/include/ranged_representation.h +++ b/example/include/ranged_representation.h @@ -25,6 +25,7 @@ #include "validated_type.h" #include #include +#include #include #include #include diff --git a/example/include/validated_type.h b/example/include/validated_type.h index a0a7b91c..30722c50 100644 --- a/example/include/validated_type.h +++ b/example/include/validated_type.h @@ -25,6 +25,7 @@ #include #include #include +#include #include // IWYU pragma: export #include #include diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 86659065..501dd2cc 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -23,6 +23,7 @@ #pragma once #include +#include #include #include #include diff --git a/example/kalman_filter/kalman_filter-example_1.cpp b/example/kalman_filter/kalman_filter-example_1.cpp index a5f8778a..7bfb370a 100644 --- a/example/kalman_filter/kalman_filter-example_1.cpp +++ b/example/kalman_filter/kalman_filter-example_1.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman_filter-example_2.cpp b/example/kalman_filter/kalman_filter-example_2.cpp index d9fab7f9..f1fffedd 100644 --- a/example/kalman_filter/kalman_filter-example_2.cpp +++ b/example/kalman_filter/kalman_filter-example_2.cpp @@ -23,6 +23,7 @@ #include "kalman.h" #include #include +#include #ifdef MP_UNITS_MODULES import mp_units; #else diff --git a/example/kalman_filter/kalman_filter-example_3.cpp b/example/kalman_filter/kalman_filter-example_3.cpp index 931cba60..a69c39e6 100644 --- a/example/kalman_filter/kalman_filter-example_3.cpp +++ b/example/kalman_filter/kalman_filter-example_3.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman_filter-example_4.cpp b/example/kalman_filter/kalman_filter-example_4.cpp index 073bc4a1..b04ae971 100644 --- a/example/kalman_filter/kalman_filter-example_4.cpp +++ b/example/kalman_filter/kalman_filter-example_4.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman_filter-example_5.cpp b/example/kalman_filter/kalman_filter-example_5.cpp index 8a594ded..d12a22fe 100644 --- a/example/kalman_filter/kalman_filter-example_5.cpp +++ b/example/kalman_filter/kalman_filter-example_5.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman_filter-example_6.cpp b/example/kalman_filter/kalman_filter-example_6.cpp index 96cc1d38..7e17b23c 100644 --- a/example/kalman_filter/kalman_filter-example_6.cpp +++ b/example/kalman_filter/kalman_filter-example_6.cpp @@ -23,6 +23,7 @@ #include "kalman.h" #include #include +#include #ifdef MP_UNITS_MODULES import mp_units; #else diff --git a/example/kalman_filter/kalman_filter-example_7.cpp b/example/kalman_filter/kalman_filter-example_7.cpp index ecf52f96..62ce652b 100644 --- a/example/kalman_filter/kalman_filter-example_7.cpp +++ b/example/kalman_filter/kalman_filter-example_7.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/kalman_filter/kalman_filter-example_8.cpp b/example/kalman_filter/kalman_filter-example_8.cpp index e9e06da0..760212ec 100644 --- a/example/kalman_filter/kalman_filter-example_8.cpp +++ b/example/kalman_filter/kalman_filter-example_8.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include "kalman.h" +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/si_constants.cpp b/example/si_constants.cpp index f88b08fe..56b016a8 100644 --- a/example/si_constants.cpp +++ b/example/si_constants.cpp @@ -26,6 +26,7 @@ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index ae12080b..e64eee8f 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include #include #ifdef MP_UNITS_MODULES diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 3622e081..7e004cf0 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include #include #include diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 23b05ccf..914de0db 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -23,6 +23,7 @@ #include "geographic.h" #include "ranged_representation.h" #include +#include #include #include #include @@ -30,6 +31,7 @@ #ifdef MP_UNITS_MODULES import mp_units; #else +#include #include #include #include diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 733e3586..1a48573b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -46,6 +46,7 @@ add_mp_units_module( include/mp-units/ext/algorithm.h include/mp-units/ext/contracts.h include/mp-units/ext/fixed_string.h + include/mp-units/ext/format.h include/mp-units/ext/prime.h include/mp-units/ext/type_name.h include/mp-units/ext/type_traits.h diff --git a/src/core/include/mp-units/bits/core_gmf.h b/src/core/include/mp-units/bits/core_gmf.h index 08defcae..c920c6ae 100644 --- a/src/core/include/mp-units/bits/core_gmf.h +++ b/src/core/include/mp-units/bits/core_gmf.h @@ -45,23 +45,13 @@ #include #if MP_UNITS_HOSTED +#include #include #include #include #include #include #include - -#if MP_UNITS_USE_FMTLIB -MP_UNITS_DIAGNOSTIC_PUSH -MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE -MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW -#include -MP_UNITS_DIAGNOSTIC_POP -#else -#include -#endif - #endif #if __cpp_lib_text_encoding diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index bc3197e0..610be604 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -41,6 +41,7 @@ #include #include #include +#include #endif // most of the below code is based on/copied from fmtlib diff --git a/src/core/include/mp-units/compat_macros.h b/src/core/include/mp-units/compat_macros.h index 1d9aff34..81931dc2 100644 --- a/src/core/include/mp-units/compat_macros.h +++ b/src/core/include/mp-units/compat_macros.h @@ -83,18 +83,6 @@ #ifndef MP_UNITS_IN_MODULE_INTERFACE -// IWYU pragma: begin_exports -#if MP_UNITS_USE_FMTLIB -MP_UNITS_DIAGNOSTIC_PUSH -MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE -MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW -#include -MP_UNITS_DIAGNOSTIC_POP -#else -#include -#endif -// IWYU pragma: end_exports - #endif #endif // MP_UNITS_HOSTED diff --git a/src/core/include/mp-units/ext/format.h b/src/core/include/mp-units/ext/format.h new file mode 100644 index 00000000..72aca3a9 --- /dev/null +++ b/src/core/include/mp-units/ext/format.h @@ -0,0 +1,42 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#ifndef MP_UNITS_IN_MODULE_INTERFACE + +#include +// +#include +#include + +#if MP_UNITS_USE_FMTLIB +MP_UNITS_DIAGNOSTIC_PUSH +MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE +MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW +#include +MP_UNITS_DIAGNOSTIC_POP +#else +#include +#endif + +#endif diff --git a/test/runtime/almost_equals.h b/test/runtime/almost_equals.h index 373e7943..0cc03e8e 100644 --- a/test/runtime/almost_equals.h +++ b/test/runtime/almost_equals.h @@ -22,6 +22,7 @@ #include #include +#include #include #ifdef MP_UNITS_MODULES import mp_units; diff --git a/test/runtime/fixed_string_test.cpp b/test/runtime/fixed_string_test.cpp index 7efae3df..621118cb 100644 --- a/test/runtime/fixed_string_test.cpp +++ b/test/runtime/fixed_string_test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef MP_UNITS_MODULES import mp_units; #else diff --git a/test/runtime/fmt_test.cpp b/test/runtime/fmt_test.cpp index 8c26ee28..b776edce 100644 --- a/test/runtime/fmt_test.cpp +++ b/test/runtime/fmt_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/test/runtime/linear_algebra_test.cpp b/test/runtime/linear_algebra_test.cpp index 4afb70d1..e55815fd 100644 --- a/test/runtime/linear_algebra_test.cpp +++ b/test/runtime/linear_algebra_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef MP_UNITS_MODULES import mp_units; #else diff --git a/test/runtime/truncation_test.cpp b/test/runtime/truncation_test.cpp index 6b05b767..af780d80 100644 --- a/test/runtime/truncation_test.cpp +++ b/test/runtime/truncation_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #ifdef MP_UNITS_MODULES