diff --git a/conanfile.py b/conanfile.py index 5476b79d..d91d4f78 100644 --- a/conanfile.py +++ b/conanfile.py @@ -30,7 +30,10 @@ class UnitsConan(ConanFile): url = "https://github.com/mpusz/units" description = "Physical Units library for C++" settings = "os", "compiler", "build_type", "arch" - requires = ( "cmcstl2/2019.03.18@mpusz/stable" ) + requires = ( + "cmcstl2/2019.03.18@mpusz/stable", + "gsl-lite/0.33.0@nonstd-lite/stable" + ) generators = "cmake" def build(self): diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 388721c5..dcdcde01 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ target_compile_features(units INTERFACE cxx_std_20) target_link_libraries(units INTERFACE CONAN_PKG::cmcstl2 + CONAN_PKG::gsl-lite ) target_include_directories(units INTERFACE diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index bc4e018f..e7e9ce51 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -24,6 +24,7 @@ #include "unit.h" #include +#include namespace units { @@ -262,6 +263,8 @@ namespace units { constexpr operator/(const Rep1& v, const quantity& q) { + Expects(q != std::decay_t(0)); + using dim = dim_invert_t; using ret = quantity>>, std::common_type_t>; using den = quantity>; @@ -273,6 +276,8 @@ namespace units { constexpr operator/(const quantity& q, const Rep2& v) { + Expects(v != Rep2{0}); + using ret = quantity>; return ret(ret(q).count() / v); } @@ -282,6 +287,8 @@ namespace units { constexpr operator/(const quantity& lhs, const quantity& rhs) { + Expects(rhs != std::decay_t(0)); + using cq = std::common_type_t, quantity>; return cq(lhs).count() / cq(rhs).count(); } @@ -292,6 +299,8 @@ namespace units { constexpr operator/(const quantity& lhs, const quantity& rhs) { + Expects(rhs != std::decay_t(0)); + using dim = dimension_divide_t; using ret = quantity>>, std::common_type_t>; return ret(lhs.count() / rhs.count());