From e42e568f44e073385a043db9ab02d800879b7105 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 9 Sep 2024 14:37:22 +0200 Subject: [PATCH 1/3] fix: conversion operator to `std::chrono` types fixed Resolves #609 --- .../include/mp-units/framework/quantity.h | 24 +++++-------------- test/static/chrono_test.cpp | 9 +++++++ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index c9614266..af641474 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -314,25 +314,13 @@ public: convert_explicitly> || !std::convertible_to::rep>) constexpr // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) - operator Q_() const& noexcept( - noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && - std::is_nothrow_copy_constructible_v) + operator Q_() const + noexcept(noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && + std::is_nothrow_copy_constructible_v) { - return quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_).value; - } - - template> - requires detail::QuantityConvertibleTo> - [[nodiscard]] explicit(is_specialization_of::from_numerical_value( - numerical_value_is_an_implementation_detail_)), - convert_explicitly> || - !std::convertible_to::rep>) constexpr - // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) - operator Q_() && noexcept( - noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && - std::is_nothrow_move_constructible_v) - { - return quantity_like_traits::from_numerical_value(std::move(numerical_value_is_an_implementation_detail_)).value; + return quantity_like_traits::from_numerical_value( + numerical_value_in(get_unit(quantity_like_traits::reference))) + .value; } // member unary operators diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 9f3b1901..8c532390 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -127,6 +127,15 @@ static_assert(quantity{std::chrono::weeks{1}} == 7 * d); static_assert(quantity{std::chrono::months{1}} == 2629746 * s); static_assert(quantity{std::chrono::years{1}} == 31556952 * s); +// conversion from chrono +static_assert(quantity{1ns} == 1 * ns); +static_assert(quantity{1s} == 1 * s); +static_assert(quantity{1ms} == 1 * ms); + +// conversion to chrono +static_assert(std::chrono::nanoseconds(quantity{1 * ns}) == 1ns); +static_assert(std::chrono::nanoseconds(quantity{1 * s}) == 1s); + // operators static_assert(quantity{1s} + 1 * s == 2 * s); static_assert(quantity{1s} + 1 * min == 61 * s); From e792eb303cd5fc72aef1f8584e11f06d5da4dedc Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 9 Sep 2024 14:39:36 +0200 Subject: [PATCH 2/3] chore: .gitignore updated to account also for the `docs/api_reference/gen` symbolic link --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d0a116be..2699986c 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,4 @@ CMakeUserPresets.json # cxxdraft-htmlgen docs/api_reference/src/source/ -docs/api_reference/gen/ +docs/api_reference/gen From 32d4821f4aa376cddb7cd6d9719a7a4621634387 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 9 Sep 2024 18:19:16 +0000 Subject: [PATCH 3/3] chore: Dockerfile updated for gitpod --- .gitpod/Dockerfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitpod/Dockerfile b/.gitpod/Dockerfile index cb1c901e..c26d34d2 100644 --- a/.gitpod/Dockerfile +++ b/.gitpod/Dockerfile @@ -17,3 +17,18 @@ RUN sudo install-packages \ libjpeg-dev \ libpng-dev \ libz-dev + +# Install API reference dependencies +RUN sudo install-packages \ + haskell-stack \ + graphviz \ + nodejs \ + npm \ + ghc \ + cabal-install +RUN npm install split mathjax-full mathjax-node-sre +RUN cabal update + +# Install MathJax-Node-CLI +git clone https://github.com/mathjax/mathjax-node-cli --depth=1 +echo "export PATH=\"$PWD/mathjax-node-cli/bin:\$PATH\"" >> ~/.bashrc