forked from mpusz/mp-units
feat: add module mp_units
This commit is contained in:
committed by
Mateusz Pusz
parent
f3ad392123
commit
7cb2099af5
+16
-10
@@ -22,15 +22,25 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# find dependencies
|
||||
if(NOT TARGET gsl::gsl-lite)
|
||||
find_package(gsl-lite CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
add_library(example_utils INTERFACE)
|
||||
target_include_directories(example_utils INTERFACE include)
|
||||
target_link_libraries(example_utils INTERFACE gsl::gsl-lite)
|
||||
|
||||
#
|
||||
# add_example(target <depependencies>...)
|
||||
# add_example(target <mp-units-depependencies>...)
|
||||
#
|
||||
function(add_example target)
|
||||
add_executable(${target} ${target}.cpp)
|
||||
target_link_libraries(${target} PRIVATE ${ARGN})
|
||||
if(TARGET mp-units::modules)
|
||||
target_link_libraries(${target} PRIVATE mp-units::modules)
|
||||
else()
|
||||
target_link_libraries(${target} PRIVATE ${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_example(avg_speed mp-units::core-io mp-units::si mp-units::cgs mp-units::usc)
|
||||
@@ -49,7 +59,8 @@ add_example(
|
||||
add_example(conversion_factor mp-units::core-fmt mp-units::core-io mp-units::si)
|
||||
add_example(currency mp-units::core-io)
|
||||
add_example(foot_pound_second mp-units::core-fmt mp-units::international mp-units::imperial)
|
||||
add_example(glide_computer mp-units::core-fmt mp-units::international mp-units::utility glide_computer_lib)
|
||||
add_example(glide_computer mp-units::core-fmt mp-units::international mp-units::utility)
|
||||
target_link_libraries(glide_computer PRIVATE glide_computer_lib)
|
||||
add_example(hello_units mp-units::core-fmt mp-units::core-io mp-units::si mp-units::usc)
|
||||
add_example(measurement mp-units::core-io mp-units::si)
|
||||
add_example(si_constants mp-units::core-fmt mp-units::si)
|
||||
@@ -60,14 +71,9 @@ add_example(
|
||||
)
|
||||
add_example(total_energy mp-units::core-io mp-units::si mp-units::natural mp-units::utility)
|
||||
add_example(
|
||||
unmanned_aerial_vehicle
|
||||
mp-units::core-fmt
|
||||
mp-units::core-io
|
||||
mp-units::si
|
||||
mp-units::international
|
||||
mp-units::utility
|
||||
example_utils
|
||||
unmanned_aerial_vehicle mp-units::core-fmt mp-units::core-io mp-units::si mp-units::international mp-units::utility
|
||||
)
|
||||
target_link_libraries(unmanned_aerial_vehicle PRIVATE example_utils)
|
||||
|
||||
add_subdirectory(glide_computer_lib)
|
||||
add_subdirectory(kalman_filter)
|
||||
|
||||
@@ -25,13 +25,17 @@
|
||||
// !!! renders correctly in the documentation "Examples" section. !!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/cgs/cgs.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/isq.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -20,11 +20,15 @@
|
||||
physical_quantities
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/math.h> // IWYU pragma: keep
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/isq/electromagnetism.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
along with this program. If not, see http://www.gnu.org/licenses./
|
||||
*/
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/iau/iau.h>
|
||||
@@ -24,7 +29,7 @@
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <mp-units/systems/typographic/typographic.h>
|
||||
#include <mp-units/systems/usc/usc.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
along with this program. If not, see http://www.gnu.org/licenses./
|
||||
*/
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <mp-units/systems/si/units.h>
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
#endif
|
||||
|
||||
/*
|
||||
get conversion factor from one dimensionally equivalent
|
||||
|
||||
@@ -20,11 +20,16 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <mp-units/quantity_spec_macro.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units.core_io;
|
||||
#else
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/quantity.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
|
||||
@@ -20,14 +20,19 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/imperial/imperial.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/mechanics.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
using namespace mp_units;
|
||||
using namespace mp_units::international::unit_symbols;
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
|
||||
#include "glide_computer_lib.h"
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <mp-units/chrono.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -33,6 +29,14 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/chrono.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -23,5 +23,10 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
add_library(glide_computer_lib STATIC glide_computer_lib.cpp include/glide_computer_lib.h)
|
||||
target_link_libraries(glide_computer_lib PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils)
|
||||
if(TARGET mp-units::modules)
|
||||
target_link_libraries(glide_computer_lib PUBLIC gsl::gsl-lite mp-units::modules)
|
||||
else()
|
||||
target_link_libraries(glide_computer_lib PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility)
|
||||
endif()
|
||||
target_link_libraries(glide_computer_lib PUBLIC example_utils)
|
||||
target_include_directories(glide_computer_lib PUBLIC include)
|
||||
|
||||
@@ -21,10 +21,14 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "glide_computer_lib.h"
|
||||
#include <mp-units/format.h>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <string_view>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units.core_fmt;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#endif
|
||||
|
||||
namespace glide_computer {
|
||||
|
||||
|
||||
@@ -22,11 +22,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/quantity_spec_macro.h>
|
||||
//
|
||||
#include "geographic.h"
|
||||
#include <mp-units/chrono.h>
|
||||
#include <mp-units/math.h> // IWYU pragma: keep
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
@@ -35,6 +33,14 @@
|
||||
#include <ranges>
|
||||
#include <string> // IWYU pragma: keep
|
||||
#include <vector>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/chrono.h>
|
||||
#include <mp-units/math.h> // IWYU pragma: keep
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#endif
|
||||
|
||||
// An example of a really simplified tactical glide computer
|
||||
// Simplifications:
|
||||
|
||||
@@ -25,12 +25,17 @@
|
||||
// !!! renders correctly in the documentation "Examples" section. !!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/isq.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
|
||||
#include "ranged_representation.h"
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <compare>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <ostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/compare.h>
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
@@ -31,10 +38,7 @@
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/units.h>
|
||||
#include <compare>
|
||||
#include <limits>
|
||||
#include <numbers>
|
||||
#include <ostream>
|
||||
#endif
|
||||
|
||||
namespace geographic {
|
||||
|
||||
|
||||
@@ -24,11 +24,15 @@
|
||||
|
||||
#include "validated_type.h"
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <algorithm>
|
||||
#include <concepts>
|
||||
#include <type_traits>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units.core;
|
||||
#else
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#endif
|
||||
|
||||
template<std::movable T, MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
|
||||
MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
|
||||
|
||||
@@ -23,11 +23,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units.core_fmt;
|
||||
#else
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <mp-units/customization_points.h>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
inline constexpr struct validated_tag {
|
||||
} validated;
|
||||
|
||||
@@ -27,7 +27,11 @@ cmake_minimum_required(VERSION 3.5)
|
||||
#
|
||||
function(add_example target)
|
||||
add_executable(${target} ${target}.cpp)
|
||||
target_link_libraries(${target} PRIVATE ${ARGN})
|
||||
if(TARGET mp-units::modules)
|
||||
target_link_libraries(${target} PRIVATE mp-units::modules)
|
||||
else()
|
||||
target_link_libraries(${target} PRIVATE ${ARGN})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_example(kalman_filter-example_1 mp-units::core-fmt mp-units::si mp-units::utility)
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <tuple>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/quantity.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <tuple>
|
||||
#endif
|
||||
|
||||
namespace kalman {
|
||||
|
||||
|
||||
@@ -21,11 +21,15 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex1
|
||||
|
||||
|
||||
@@ -21,11 +21,15 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex2
|
||||
|
||||
|
||||
@@ -21,11 +21,15 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex3
|
||||
|
||||
|
||||
@@ -21,11 +21,15 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/alphabeta.html#ex4
|
||||
|
||||
|
||||
@@ -21,12 +21,16 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex5
|
||||
|
||||
|
||||
@@ -21,13 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/thermodynamics.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex6
|
||||
|
||||
|
||||
@@ -21,13 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/thermodynamics.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex7
|
||||
|
||||
|
||||
@@ -21,13 +21,17 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "kalman.h"
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/isq/thermodynamics.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// Based on: https://www.kalmanfilter.net/kalman1d.html#ex8
|
||||
|
||||
|
||||
@@ -20,13 +20,17 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <mp-units/systems/si/units.h>
|
||||
#include <cmath>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -25,9 +25,14 @@
|
||||
// !!! renders correctly in the documentation "Examples" section. !!!
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
requires mp_units::is_scalar<T>
|
||||
|
||||
@@ -20,11 +20,16 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/systems/isq/isq.h>
|
||||
#include <mp-units/systems/si/si.h>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
#endif
|
||||
|
||||
// This example implements a table of units provided in the following article
|
||||
// http://cds.cern.ch/record/1481609/files/978-3-642-18018-7_BookBackMatter.pdf
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <mp-units/quantity_spec_macro.h>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <numbers>
|
||||
#include <utility>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/chrono.h>
|
||||
#include <mp-units/format.h>
|
||||
#include <mp-units/math.h>
|
||||
@@ -28,11 +38,7 @@
|
||||
#include <mp-units/systems/si/constants.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <mp-units/systems/si/units.h>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <numbers>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
// allows standard gravity (acceleration) and weight (force) to be expressed with scalar representation
|
||||
// types instead of requiring the usage of Linear Algebra library for this simple example
|
||||
|
||||
@@ -20,11 +20,15 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/isq_angle/isq_angle.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
requires mp_units::is_scalar<T>
|
||||
|
||||
+10
-16
@@ -20,14 +20,18 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/math.h>
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/systems/isq/mechanics.h>
|
||||
#include <mp-units/systems/natural/natural.h>
|
||||
#include <mp-units/systems/si/constants.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
requires mp_units::is_scalar<T>
|
||||
@@ -56,31 +60,21 @@ void si_example()
|
||||
|
||||
std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n";
|
||||
|
||||
std::cout << "\n[in `GeV` and `c`]\n"
|
||||
<< "p = " << p1 << "\n"
|
||||
<< "m = " << m1 << "\n"
|
||||
<< "E = " << E << "\n";
|
||||
std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" << "E = " << E << "\n";
|
||||
|
||||
const auto p2 = p1.in(GeV / (m / s));
|
||||
const auto m2 = m1.in(GeV / pow<2>(m / s));
|
||||
const auto E2 = total_energy(p2, m2, c).in(GeV);
|
||||
|
||||
std::cout << "\n[in `GeV`]\n"
|
||||
<< "p = " << p2 << "\n"
|
||||
<< "m = " << m2 << "\n"
|
||||
<< "E = " << E2 << "\n";
|
||||
std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" << "m = " << m2 << "\n" << "E = " << E2 << "\n";
|
||||
|
||||
const auto p3 = p1.in(kg * m / s);
|
||||
const auto m3 = m1.in(kg);
|
||||
const auto E3 = total_energy(p3, m3, c).in(J);
|
||||
|
||||
std::cout << "\n[in SI base units]\n"
|
||||
<< "p = " << p3 << "\n"
|
||||
<< "m = " << m3 << "\n"
|
||||
<< "E = " << E3 << "\n";
|
||||
std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" << "m = " << m3 << "\n" << "E = " << E3 << "\n";
|
||||
|
||||
std::cout << "\n[converted from SI units back to GeV]\n"
|
||||
<< "E = " << E3.force_in(GeV) << "\n";
|
||||
std::cout << "\n[converted from SI units back to GeV]\n" << "E = " << E3.force_in(GeV) << "\n";
|
||||
}
|
||||
|
||||
void natural_example()
|
||||
|
||||
@@ -21,13 +21,18 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include "geographic.h"
|
||||
#include <mp-units/bits/fmt_hacks.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
import mp_units;
|
||||
#else
|
||||
#include <mp-units/ostream.h>
|
||||
#include <mp-units/quantity_point.h>
|
||||
#include <mp-units/systems/international/international.h>
|
||||
#include <mp-units/systems/isq/space_and_time.h>
|
||||
#include <mp-units/systems/si/unit_symbols.h>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
using namespace mp_units;
|
||||
using namespace geographic;
|
||||
|
||||
Reference in New Issue
Block a user