forked from mpusz/mp-units
refactor: ms-gsl replaced with gsl-lite
This commit is contained in:
@@ -47,7 +47,7 @@ class UnitsConan(ConanFile):
|
|||||||
settings = "compiler", "build_type"
|
settings = "compiler", "build_type"
|
||||||
requires = (
|
requires = (
|
||||||
"fmt/7.0.3",
|
"fmt/7.0.3",
|
||||||
"ms-gsl/3.1.0"
|
"gsl-lite/0.37.0"
|
||||||
)
|
)
|
||||||
options = {
|
options = {
|
||||||
"downcast_mode": ["off", "on", "auto"],
|
"downcast_mode": ["off", "on", "auto"],
|
||||||
@@ -135,7 +135,7 @@ class UnitsConan(ConanFile):
|
|||||||
self.cpp_info.names["cmake_find_package"] = "mp"
|
self.cpp_info.names["cmake_find_package"] = "mp"
|
||||||
self.cpp_info.names["cmake_find_package_multi"] = "mp"
|
self.cpp_info.names["cmake_find_package_multi"] = "mp"
|
||||||
self.cpp_info.components["units"].name = "units"
|
self.cpp_info.components["units"].name = "units"
|
||||||
self.cpp_info.components["units"].requires = ["fmt::fmt", "ms-gsl::ms-gsl"]
|
self.cpp_info.components["units"].requires = ["fmt::fmt", "gsl::gsl-lite"]
|
||||||
|
|
||||||
compiler = self.settings.compiler
|
compiler = self.settings.compiler
|
||||||
version = Version(self.settings.compiler.version)
|
version = Version(self.settings.compiler.version)
|
||||||
|
@@ -18,7 +18,7 @@ This repository contains three independent CMake-based projects:
|
|||||||
but until then it depends on:
|
but until then it depends on:
|
||||||
|
|
||||||
- `{fmt} <https://github.com/fmtlib/fmt>`_ to provide text formatting of quantities.
|
- `{fmt} <https://github.com/fmtlib/fmt>`_ to provide text formatting of quantities.
|
||||||
- `ms-gsl <https://github.com/microsoft/GSL>`_ to verify runtime contracts with ``Expects`` macro.
|
- `gsl-lite <https://github.com/gsl-lite/gsl-lite>`_ to verify runtime contracts with ``Expects`` macro.
|
||||||
|
|
||||||
- *.*
|
- *.*
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ set_property(CACHE UNITS_DOWNCAST_MODE PROPERTY STRINGS AUTO ON OFF)
|
|||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
|
||||||
|
|
||||||
find_package(fmt CONFIG REQUIRED)
|
find_package(fmt CONFIG REQUIRED)
|
||||||
find_package(Microsoft.GSL CONFIG REQUIRED)
|
find_package(gsl-lite CONFIG REQUIRED)
|
||||||
|
|
||||||
# library definition
|
# library definition
|
||||||
add_library(mp-units INTERFACE)
|
add_library(mp-units INTERFACE)
|
||||||
@@ -42,7 +42,7 @@ target_compile_features(mp-units INTERFACE cxx_std_20)
|
|||||||
target_link_libraries(mp-units
|
target_link_libraries(mp-units
|
||||||
INTERFACE
|
INTERFACE
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
Microsoft.GSL::GSL
|
gsl::gsl-lite
|
||||||
)
|
)
|
||||||
target_include_directories(mp-units
|
target_include_directories(mp-units
|
||||||
INTERFACE
|
INTERFACE
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gsl/gsl_assert>
|
#include <gsl/gsl-lite.hpp>
|
||||||
#include <units/bits/math_concepts.h>
|
#include <units/bits/math_concepts.h>
|
||||||
#include <units/bits/pow.h>
|
#include <units/bits/pow.h>
|
||||||
#include <units/bits/ratio_maths.h>
|
#include <units/bits/ratio_maths.h>
|
||||||
@@ -65,7 +65,7 @@ struct decimal_fp {
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] constexpr double constexpr_log(double v) noexcept
|
[[nodiscard]] constexpr double constexpr_log(double v) noexcept
|
||||||
{
|
{
|
||||||
Expects(v > 0);
|
gsl_Expects(v > 0);
|
||||||
|
|
||||||
// lookup table to speed up convergence for all significant values
|
// lookup table to speed up convergence for all significant values
|
||||||
// significant values of 7 and greater benefit mostly as they now converge in 5 terms compared to O(10)-O(100)
|
// significant values of 7 and greater benefit mostly as they now converge in 5 terms compared to O(10)-O(100)
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <gsl/gsl_assert>
|
#include <gsl/gsl-lite.hpp>
|
||||||
|
|
||||||
namespace units::detail {
|
namespace units::detail {
|
||||||
|
|
||||||
@@ -183,10 +183,10 @@ constexpr void normalize(std::intmax_t& num, std::intmax_t& den, std::intmax_t&
|
|||||||
const std::intmax_t b0 = detail::abs(rhs) % c;
|
const std::intmax_t b0 = detail::abs(rhs) % c;
|
||||||
const std::intmax_t b1 = detail::abs(rhs) / c;
|
const std::intmax_t b1 = detail::abs(rhs) / c;
|
||||||
|
|
||||||
Expects(a1 == 0 || b1 == 0); // overflow in multiplication
|
gsl_Expects(a1 == 0 || b1 == 0); // overflow in multiplication
|
||||||
Expects(a0 * b1 + b0 * a1 < (c >> 1)); // overflow in multiplication
|
gsl_Expects(a0 * b1 + b0 * a1 < (c >> 1)); // overflow in multiplication
|
||||||
Expects(b0 * a0 <= INTMAX_MAX); // overflow in multiplication
|
gsl_Expects(b0 * a0 <= INTMAX_MAX); // overflow in multiplication
|
||||||
Expects((a0 * b1 + b0 * a1) * c <= INTMAX_MAX - b0 * a0); // overflow in multiplication
|
gsl_Expects((a0 * b1 + b0 * a1) * c <= INTMAX_MAX - b0 * a0); // overflow in multiplication
|
||||||
|
|
||||||
return lhs * rhs;
|
return lhs * rhs;
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gsl/gsl_assert>
|
#include <gsl/gsl-lite.hpp>
|
||||||
#include <units/bits/constexpr_math.h>
|
#include <units/bits/constexpr_math.h>
|
||||||
#include <units/bits/math_concepts.h>
|
#include <units/bits/math_concepts.h>
|
||||||
#include <units/bits/pow.h>
|
#include <units/bits/pow.h>
|
||||||
@@ -38,7 +38,7 @@ template<std::intmax_t N, typename F>
|
|||||||
if constexpr (N == 1) {
|
if constexpr (N == 1) {
|
||||||
return v;
|
return v;
|
||||||
} else {
|
} else {
|
||||||
Expects(v >= 0);
|
gsl_Expects(v >= 0);
|
||||||
if (v == 0) {
|
if (v == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
|
struct invalid_one_rep {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A representation type to be used for unit constants
|
* @brief A representation type to be used for unit constants
|
||||||
*
|
*
|
||||||
@@ -88,11 +90,22 @@ struct one_rep {
|
|||||||
|
|
||||||
[[nodiscard]] bool operator==(const one_rep&) const = default;
|
[[nodiscard]] bool operator==(const one_rep&) const = default;
|
||||||
[[nodiscard]] auto operator<=>(const one_rep&) const = default;
|
[[nodiscard]] auto operator<=>(const one_rep&) const = default;
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr bool operator==(const invalid_one_rep&) const { return false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct quantity_values<one_rep> {
|
||||||
|
static constexpr invalid_one_rep zero() noexcept { return invalid_one_rep{}; }
|
||||||
|
static constexpr one_rep one() noexcept { return one_rep{}; }
|
||||||
|
static constexpr one_rep min() noexcept { return one(); }
|
||||||
|
static constexpr one_rep max() noexcept { return one(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace units
|
} // namespace units
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct common_type<units::one_rep, units::one_rep> {
|
struct common_type<units::one_rep, units::one_rep> {
|
||||||
using type = units::one_rep;
|
using type = units::one_rep;
|
||||||
|
@@ -270,7 +270,7 @@ public:
|
|||||||
invoke_result_convertible_to_<rep, std::divides<>, rep, const Value&>
|
invoke_result_convertible_to_<rep, std::divides<>, rep, const Value&>
|
||||||
[[nodiscard]] friend constexpr Quantity auto operator/(const quantity& q, const Value& v)
|
[[nodiscard]] friend constexpr Quantity auto operator/(const quantity& q, const Value& v)
|
||||||
{
|
{
|
||||||
// Expects(v != zero().count());
|
gsl_ExpectsAudit(v != quantity_values<Value>::zero());
|
||||||
using ret = quantity<D, U, std::invoke_result_t<std::divides<>, rep, Value>>;
|
using ret = quantity<D, U, std::invoke_result_t<std::divides<>, rep, Value>>;
|
||||||
return ret(q.count() / v);
|
return ret(q.count() / v);
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ public:
|
|||||||
invoke_result_convertible_to_<rep, std::divides<>, const Value&, rep>
|
invoke_result_convertible_to_<rep, std::divides<>, const Value&, rep>
|
||||||
[[nodiscard]] friend constexpr Quantity auto operator/(const Value& v, const quantity& q)
|
[[nodiscard]] friend constexpr Quantity auto operator/(const Value& v, const quantity& q)
|
||||||
{
|
{
|
||||||
// Expects(q.count() != zero().count());
|
gsl_ExpectsAudit(q.count() != quantity_values<rep>::zero());
|
||||||
using dim = dim_invert<D>;
|
using dim = dim_invert<D>;
|
||||||
using ret_unit = downcast_unit<dim, inverse(U::ratio)>;
|
using ret_unit = downcast_unit<dim, inverse(U::ratio)>;
|
||||||
using ret = quantity<dim, ret_unit, std::invoke_result_t<std::divides<>, Value, rep>>;
|
using ret = quantity<dim, ret_unit, std::invoke_result_t<std::divides<>, Value, rep>>;
|
||||||
@@ -354,7 +354,7 @@ template<typename D1, typename U1, typename Rep1, typename D2, typename U2, type
|
|||||||
requires quantity_value_for_<std::divides<>, Rep1, Rep2>
|
requires quantity_value_for_<std::divides<>, Rep1, Rep2>
|
||||||
[[nodiscard]] constexpr Quantity auto operator/(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
[[nodiscard]] constexpr Quantity auto operator/(const quantity<D1, U1, Rep1>& lhs, const quantity<D2, U2, Rep2>& rhs)
|
||||||
{
|
{
|
||||||
// Expects(rhs.count() != zero().count());
|
gsl_ExpectsAudit(rhs.count() != (quantity_values<Rep2>::zero()));
|
||||||
using dim = dimension_divide<D1, D2>;
|
using dim = dimension_divide<D1, D2>;
|
||||||
using unit = downcast_unit<dim, (U1::ratio / dimension_unit<D1>::ratio) / (U2::ratio / dimension_unit<D2>::ratio) * dimension_unit<dim>::ratio>;
|
using unit = downcast_unit<dim, (U1::ratio / dimension_unit<D1>::ratio) / (U2::ratio / dimension_unit<D2>::ratio) * dimension_unit<dim>::ratio>;
|
||||||
using ret = quantity<dim, unit, std::invoke_result_t<std::divides<>, Rep1, Rep2>>;
|
using ret = quantity<dim, unit, std::invoke_result_t<std::divides<>, Rep1, Rep2>>;
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <gsl/gsl_assert>
|
#include <gsl/gsl-lite.hpp>
|
||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ struct ratio {
|
|||||||
|
|
||||||
explicit constexpr ratio(std::intmax_t n, std::intmax_t d = 1, std::intmax_t e = 0): num(n), den(d), exp(e)
|
explicit constexpr ratio(std::intmax_t n, std::intmax_t d = 1, std::intmax_t e = 0): num(n), den(d), exp(e)
|
||||||
{
|
{
|
||||||
Expects(den != 0);
|
gsl_Expects(den != 0);
|
||||||
detail::normalize(num, den, exp);
|
detail::normalize(num, den, exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ namespace detail {
|
|||||||
|
|
||||||
[[nodiscard]] constexpr auto make_exp_align(const ratio& r, std::intmax_t alignment)
|
[[nodiscard]] constexpr auto make_exp_align(const ratio& r, std::intmax_t alignment)
|
||||||
{
|
{
|
||||||
Expects(alignment > 0);
|
gsl_Expects(alignment > 0);
|
||||||
const std::intmax_t rem = r.exp % alignment;
|
const std::intmax_t rem = r.exp % alignment;
|
||||||
|
|
||||||
if (rem == 0) { // already aligned
|
if (rem == 0) { // already aligned
|
||||||
|
@@ -24,14 +24,14 @@
|
|||||||
|
|
||||||
#include <units/bits/external/fixed_string.h>
|
#include <units/bits/external/fixed_string.h>
|
||||||
#include <units/bits/external/hacks.h>
|
#include <units/bits/external/hacks.h>
|
||||||
#include <gsl/gsl_assert>
|
#include <gsl/gsl-lite.hpp>
|
||||||
#include <compare>
|
#include <compare>
|
||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
constexpr void validate_ascii_char([[maybe_unused]] char c) noexcept { Expects((c & 0x80) == 0); }
|
constexpr void validate_ascii_char([[maybe_unused]] char c) noexcept { gsl_Expects((c & 0x80) == 0); }
|
||||||
|
|
||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) noexcept
|
constexpr void validate_ascii_string([[maybe_unused]] const char (&s)[N + 1]) noexcept
|
||||||
|
@@ -22,6 +22,6 @@
|
|||||||
|
|
||||||
include(CMakeFindDependencyMacro)
|
include(CMakeFindDependencyMacro)
|
||||||
find_dependency(fmt)
|
find_dependency(fmt)
|
||||||
find_dependency(Microsoft.GSL)
|
find_dependency(gsl-lite)
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/mp-unitsTargets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/mp-unitsTargets.cmake")
|
||||||
|
Reference in New Issue
Block a user