diff --git a/example/alternative_namespaces/box_example.cpp b/example/alternative_namespaces/box_example.cpp index bdfb4038..18e597a9 100644 --- a/example/alternative_namespaces/box_example.cpp +++ b/example/alternative_namespaces/box_example.cpp @@ -1,4 +1,5 @@ +#include #include "./length.h" #include "./acceleration.h" #include "./density.h" diff --git a/example/alternative_namespaces/capacitor_time_curve.cpp b/example/alternative_namespaces/capacitor_time_curve.cpp index c6590808..6d833d16 100644 --- a/example/alternative_namespaces/capacitor_time_curve.cpp +++ b/example/alternative_namespaces/capacitor_time_curve.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "./voltage.h" #include diff --git a/example/alternative_namespaces/clcpp_response.cpp b/example/alternative_namespaces/clcpp_response.cpp index a7c4c2fc..ac2336ba 100644 --- a/example/alternative_namespaces/clcpp_response.cpp +++ b/example/alternative_namespaces/clcpp_response.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "./length.h" #include "./volume.h" diff --git a/example/alternative_namespaces/conversion_factor.cpp b/example/alternative_namespaces/conversion_factor.cpp index 6c5a46b3..685f45b4 100644 --- a/example/alternative_namespaces/conversion_factor.cpp +++ b/example/alternative_namespaces/conversion_factor.cpp @@ -18,6 +18,7 @@ #include "./units_str.h" #include "./length.h" +#include #include /* diff --git a/example/alternative_namespaces/timer.cpp b/example/alternative_namespaces/timer.cpp index 520a1f72..50bd4984 100644 --- a/example/alternative_namespaces/timer.cpp +++ b/example/alternative_namespaces/timer.cpp @@ -1,4 +1,5 @@ +#include #include #include "./timer.h" diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index cde2eb99..48c68fb2 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace { diff --git a/example/box_example.cpp b/example/box_example.cpp index 6ebafbe2..00923a81 100644 --- a/example/box_example.cpp +++ b/example/box_example.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace { diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index b08a0da4..677f875f 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include int main() diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 37bace5a..e32037b8 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace { diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index 0df01fa4..1e0b45a1 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -17,6 +17,7 @@ #include #include +#include #include /* diff --git a/example/custom_systems.cpp b/example/custom_systems.cpp index d4e73e24..ea2c47ba 100644 --- a/example/custom_systems.cpp +++ b/example/custom_systems.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include +#include #include #include diff --git a/example/experimental_angle.cpp b/example/experimental_angle.cpp index 19ae993f..49f17054 100644 --- a/example/experimental_angle.cpp +++ b/example/experimental_angle.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include using namespace units; diff --git a/example/hello_units.cpp b/example/hello_units.cpp index 1c907134..71b45e4f 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include using namespace units::physical; diff --git a/example/linear_algebra.cpp b/example/linear_algebra.cpp index 6dfe06c9..119cd30f 100644 --- a/example/linear_algebra.cpp +++ b/example/linear_algebra.cpp @@ -24,13 +24,14 @@ #include #include #include +#include #include #include -namespace { +namespace STD_LA { template -std::ostream& operator<<(std::ostream& os, const std::math::vector& v) +std::ostream& operator<<(std::ostream& os, const vector& v) { os << "|"; for (auto i = 0U; i < v.size(); ++i) { @@ -41,7 +42,7 @@ std::ostream& operator<<(std::ostream& os, const std::math::vector& v) } template -std::ostream& operator<<(std::ostream& os, const std::math::matrix& v) +std::ostream& operator<<(std::ostream& os, const matrix& v) { for (auto i = 0U; i < v.rows(); ++i) { os << "|"; @@ -53,6 +54,9 @@ std::ostream& operator<<(std::ostream& os, const std::math::matrix& v) return os; } +} // namespace STD_LA + +namespace { using namespace units::physical; using namespace units::physical::si::literals; @@ -345,7 +349,7 @@ void quantity_of_matrix_tests() quantity_of_matrix_divide_by_scalar(); } -} +} // namespace int main() { diff --git a/example/measurement.cpp b/example/measurement.cpp index 2ab40053..cc42c436 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include #include #include diff --git a/example/total_energy.cpp b/example/total_energy.cpp index fff77463..8bc0de90 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace { diff --git a/example/unknown_dimension.cpp b/example/unknown_dimension.cpp index 19c527e2..9d898423 100644 --- a/example/unknown_dimension.cpp +++ b/example/unknown_dimension.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include namespace { diff --git a/src/include/units/bits/external/fixed_string.h b/src/include/units/bits/external/fixed_string.h index 18adc0bd..9a20954a 100644 --- a/src/include/units/bits/external/fixed_string.h +++ b/src/include/units/bits/external/fixed_string.h @@ -23,11 +23,11 @@ #pragma once #include -#include #include -#include #include +// TODO use when moved to C++20 modules (parsing takes too long for each translation unit) + namespace units { /** @@ -52,14 +52,15 @@ struct basic_fixed_string { } [[nodiscard]] constexpr std::size_t size() const noexcept { return N; } - [[nodiscard]] constexpr const CharT* c_str() const noexcept { return data_; } - [[nodiscard]] constexpr const CharT& operator[](std::size_t index) const noexcept { return data_[index]; } - [[nodiscard]] constexpr CharT operator[](std::size_t index) noexcept { return data_[index]; } + [[nodiscard]] constexpr const CharT* data() const noexcept { return data_; } + [[nodiscard]] constexpr const CharT* c_str() const noexcept { return data(); } + [[nodiscard]] constexpr const CharT& operator[](std::size_t index) const noexcept { return data()[index]; } + [[nodiscard]] constexpr CharT operator[](std::size_t index) noexcept { return data()[index]; } - [[nodiscard]] constexpr iterator begin() noexcept { return std::begin(data_); } - [[nodiscard]] constexpr const_iterator begin() const noexcept { return std::begin(data_); } - [[nodiscard]] constexpr iterator end() noexcept { return std::end(data_); } - [[nodiscard]] constexpr const_iterator end() const noexcept { return std::end(data_); } + [[nodiscard]] constexpr iterator begin() noexcept { return data(); } + [[nodiscard]] constexpr const_iterator begin() const noexcept { return data(); } + [[nodiscard]] constexpr iterator end() noexcept { return data() + size(); } + [[nodiscard]] constexpr const_iterator end() const noexcept { return data() + size(); } template [[nodiscard]] constexpr friend basic_fixed_string operator+( @@ -75,7 +76,14 @@ struct basic_fixed_string { [[nodiscard]] constexpr bool operator==(const basic_fixed_string& other) const { - return std::ranges::equal(*this, other); + if (size() != other.size()) + return false; + for (size_t i = 0; i != size(); ++i) { + if ((*this)[i] != other[i]) + return false; + } + return true; + // return std::ranges::equal(*this, other); } template @@ -84,14 +92,20 @@ struct basic_fixed_string { template [[nodiscard]] friend constexpr auto operator<=>(const basic_fixed_string& lhs, const basic_fixed_string& rhs) { - return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); - } + auto first1 = lhs.begin(); + const auto last1 = lhs.end(); + auto first2 = rhs.begin(); + const auto last2 = rhs.end(); + auto comp = std::compare_three_way(); - template - friend std::basic_ostream& operator<<(std::basic_ostream& os, - const basic_fixed_string& txt) - { - return os << txt.c_str(); + for (; first1 != last1 && first2 != last2; ++first1, ++first2) + if (auto cmp = comp(*first1, *first2); cmp != 0) + return cmp; + + return first1 != last1 ? std::strong_ordering::greater : + first2 != last2 ? std::strong_ordering::less : + std::strong_ordering::equal; + // return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } }; diff --git a/src/include/units/bits/external/fixed_string_io.h b/src/include/units/bits/external/fixed_string_io.h new file mode 100644 index 00000000..59728791 --- /dev/null +++ b/src/include/units/bits/external/fixed_string_io.h @@ -0,0 +1,36 @@ +// 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 + +#include +#include + +namespace units { + +template +std::basic_ostream& operator<<(std::basic_ostream& os, const basic_fixed_string& txt) +{ + return os << txt.c_str(); +} + +} // namespace units diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index df6fcc25..3fda0cc2 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -314,21 +314,6 @@ public: #endif [[nodiscard]] friend constexpr bool operator==(const quantity& lhs, const quantity& rhs) = default; - - template - friend std::basic_ostream& operator<<(std::basic_ostream& os, const quantity& q) - requires requires { os << q.count(); } - { - if(os.width()) { - // std::setw() applies to the whole quantity output so it has to be first put into std::string - std::basic_ostringstream s; - detail::to_stream(s, q); - return os << s.str(); - } - - detail::to_stream(os, q); - return os; - } }; // CTAD diff --git a/src/include/units/quantity_io.h b/src/include/units/quantity_io.h new file mode 100644 index 00000000..beb3edf7 --- /dev/null +++ b/src/include/units/quantity_io.h @@ -0,0 +1,46 @@ + +// 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 + +#include +#include + +namespace units { + +template +std::basic_ostream& operator<<(std::basic_ostream& os, const quantity& q) + requires requires { os << q.count(); } +{ + if(os.width()) { + // std::setw() applies to the whole quantity output so it has to be first put into std::string + std::basic_ostringstream s; + detail::to_stream(s, q); + return os << s.str(); + } + + detail::to_stream(os, q); + return os; +} + +} // namespace units diff --git a/test/unit_test/runtime/digital_info_test.cpp b/test/unit_test/runtime/digital_info_test.cpp index beea87f7..d1f269dc 100644 --- a/test/unit_test/runtime/digital_info_test.cpp +++ b/test/unit_test/runtime/digital_info_test.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include #include diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 683c0491..0ce466f5 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -20,10 +20,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#include "units/format.h" -#include "units/math.h" -#include "units/physical/si/si.h" -#include "units/physical/si/cgs/cgs.h" +#include +#include +#include +#include +#include #include #include #include diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index b4fabcb5..c3097598 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -21,6 +21,7 @@ // SOFTWARE. #include +#include #include using namespace units;