refactor: code refactored to comply with clang-tidy
This commit is contained in:
1 parent
901b5e5394
commit
75f719add7
46 files changed
+489
-380
No files matched your search
@@ -27,13 +27,16 @@
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-union-access)
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/compat_macros.h>
|
||||
#include <mp-units/ext/algorithm.h>
|
||||
|
||||
#ifndef MP_UNITS_IN_MODULE_INTERFACE
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <string_view>
|
||||
#endif
|
||||
@@ -42,8 +45,8 @@
|
||||
|
||||
namespace mp_units::detail {
|
||||
|
||||
enum class fmt_align { none, left, right, center, numeric };
|
||||
enum class fmt_arg_id_kind {
|
||||
enum class fmt_align : std::int8_t { none, left, right, center, numeric };
|
||||
enum class fmt_arg_id_kind : std::int8_t {
|
||||
none,
|
||||
#if MP_UNITS_USE_FMTLIB
|
||||
name,
|
||||
@@ -61,7 +64,7 @@ struct fmt_arg_ref {
|
||||
#endif
|
||||
|
||||
constexpr value() {}
|
||||
constexpr value(int idx) : index(idx) {}
|
||||
constexpr explicit value(int idx) : index(idx) {}
|
||||
#if MP_UNITS_USE_FMTLIB
|
||||
constexpr value(std::basic_string_view<Char> n) : name(n) {}
|
||||
#endif
|
||||
@@ -86,7 +89,7 @@ struct fill_t {
|
||||
private:
|
||||
static constexpr size_t max_size = 4 / sizeof(Char);
|
||||
// At most one codepoint (so one char32_t or four utf-8 char8_t)
|
||||
Char data_[max_size] = {Char{' '}};
|
||||
std::array<Char, max_size> data_ = {Char{' '}};
|
||||
unsigned char size_ = 1;
|
||||
|
||||
public:
|
||||
@@ -100,15 +103,15 @@ public:
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr size_t size() const { return size_; }
|
||||
[[nodiscard]] constexpr const Char* data() const { return data_; }
|
||||
[[nodiscard]] constexpr const Char* data() const { return data_.data(); }
|
||||
|
||||
[[nodiscard]] constexpr Char& operator[](size_t index) { return data_[index]; }
|
||||
[[nodiscard]] constexpr const Char& operator[](size_t index) const { return data_[index]; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_integer = std::is_integral<T>::value && !std::is_same<T, bool>::value &&
|
||||
!std::is_same<T, char>::value && !std::is_same<T, wchar_t>::value;
|
||||
inline constexpr bool is_integer =
|
||||
std::is_integral_v<T> && !std::is_same_v<T, bool> && !std::is_same_v<T, char> && !std::is_same_v<T, wchar_t>;
|
||||
|
||||
// Converts a character to ASCII. Returns a number > 127 on conversion failure.
|
||||
template<std::integral Char>
|
||||
@@ -211,7 +214,7 @@ template<typename Char>
|
||||
}
|
||||
|
||||
template<typename Char, typename Handler>
|
||||
[[nodiscard]] constexpr const Char* do_parse_arg_id(const Char* begin, const Char* end, Handler&& handler)
|
||||
[[nodiscard]] constexpr const Char* do_parse_arg_id(const Char* begin, const Char* end, Handler& handler)
|
||||
{
|
||||
Char c = *begin;
|
||||
if (c >= '0' && c <= '9') {
|
||||
@@ -223,8 +226,7 @@ template<typename Char, typename Handler>
|
||||
++begin;
|
||||
if (begin == end || (*begin != '}' && *begin != ':'))
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
|
||||
else
|
||||
handler.on_index(index);
|
||||
handler.on_index(index);
|
||||
return begin;
|
||||
}
|
||||
if (c == '%') return begin; // mp-units extension
|
||||
@@ -246,7 +248,7 @@ template<typename Char, typename Handler>
|
||||
}
|
||||
|
||||
template<typename Char, typename Handler>
|
||||
[[nodiscard]] constexpr const Char* parse_arg_id(const Char* begin, const Char* end, Handler&& handler)
|
||||
[[nodiscard]] constexpr const Char* parse_arg_id(const Char* begin, const Char* end, Handler& handler)
|
||||
{
|
||||
gsl_Expects(begin != end);
|
||||
Char c = *begin;
|
||||
@@ -262,7 +264,7 @@ struct dynamic_spec_id_handler {
|
||||
|
||||
constexpr void on_auto()
|
||||
{
|
||||
int id = MP_UNITS_FMT_FROM_ARG_ID(ctx.next_arg_id());
|
||||
const int id = MP_UNITS_FMT_FROM_ARG_ID(ctx.next_arg_id());
|
||||
ref = fmt_arg_ref<Char>(id);
|
||||
#if MP_UNITS_USE_FMTLIB || __cpp_lib_format >= 202305L
|
||||
ctx.check_dynamic_spec(id);
|
||||
@@ -292,7 +294,7 @@ template<typename Char>
|
||||
{
|
||||
gsl_Expects(begin != end);
|
||||
if ('0' <= *begin && *begin <= '9') {
|
||||
int val = ::mp_units::detail::parse_nonnegative_int(begin, end, -1);
|
||||
const int val = ::mp_units::detail::parse_nonnegative_int(begin, end, -1);
|
||||
if (val != -1)
|
||||
value = val;
|
||||
else
|
||||
@@ -312,9 +314,9 @@ template<std::input_iterator It>
|
||||
constexpr int code_point_length(It begin)
|
||||
{
|
||||
if constexpr (sizeof(std::iter_value_t<It>) != 1) return 1;
|
||||
constexpr char lengths[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 0};
|
||||
int len = lengths[static_cast<unsigned char>(*begin) >> 3];
|
||||
constexpr std::array lengths = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 0};
|
||||
const int len = lengths[static_cast<unsigned char>(*begin) >> 3];
|
||||
|
||||
// Compute the pointer to the next character early so that the next
|
||||
// iteration can start working on the next character. Neither Clang
|
||||
@@ -357,9 +359,8 @@ template<typename Char, typename Specs>
|
||||
++begin;
|
||||
}
|
||||
break;
|
||||
} else if (p == begin) {
|
||||
break;
|
||||
}
|
||||
if (p == begin) break;
|
||||
p = begin;
|
||||
}
|
||||
if (align == fmt_align::none) align = default_align; // mp-units extension
|
||||
@@ -368,3 +369,4 @@ template<typename Char, typename Specs>
|
||||
}
|
||||
|
||||
} // namespace mp_units::detail
|
||||
// NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-union-access)
|
||||
@@ -20,6 +20,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// NOLINTBEGIN(bugprone-reserved-identifier, cppcoreguidelines-macro-usage)
|
||||
#pragma once
|
||||
|
||||
#ifndef MP_UNITS_IN_MODULE_INTERFACE
|
||||
@@ -122,3 +123,4 @@
|
||||
#define MP_UNITS_API_NO_CRTP 1
|
||||
|
||||
#endif
|
||||
// NOLINTEND(bugprone-reserved-identifier, cppcoreguidelines-macro-usage)
|
||||
@@ -42,17 +42,18 @@ template<typename T>
|
||||
|
||||
[[nodiscard]] consteval std::intmax_t safe_multiply(std::intmax_t lhs, std::intmax_t rhs)
|
||||
{
|
||||
constexpr std::intmax_t c = std::uintmax_t(1) << (sizeof(std::intmax_t) * 4);
|
||||
constexpr std::intmax_t c = std::uintmax_t{1} << (sizeof(std::intmax_t) * 4);
|
||||
|
||||
const std::intmax_t a0 = abs(lhs) % c;
|
||||
const std::intmax_t a1 = abs(lhs) / c;
|
||||
const std::intmax_t b0 = abs(rhs) % c;
|
||||
const std::intmax_t b1 = abs(rhs) / c;
|
||||
|
||||
gsl_Assert(a1 == 0 || b1 == 0); // overflow in multiplication
|
||||
gsl_Assert(a0 * b1 + b0 * a1 < (c >> 1)); // overflow in multiplication
|
||||
gsl_Assert(b0 * a0 <= INTMAX_MAX); // overflow in multiplication
|
||||
gsl_Assert((a0 * b1 + b0 * a1) * c <= INTMAX_MAX - b0 * a0); // overflow in multiplication
|
||||
// overflow in multiplication
|
||||
gsl_Assert(a1 == 0 || b1 == 0);
|
||||
gsl_Assert(a0 * b1 + b0 * a1 < (c >> 1)); // NOLINT(hicpp-signed-bitwise)
|
||||
gsl_Assert(b0 * a0 <= INTMAX_MAX);
|
||||
gsl_Assert((a0 * b1 + b0 * a1) * c <= INTMAX_MAX - b0 * a0);
|
||||
|
||||
return lhs * rhs;
|
||||
}
|
||||
@@ -68,13 +69,14 @@ MP_UNITS_EXPORT struct ratio {
|
||||
std::intmax_t num;
|
||||
std::intmax_t den;
|
||||
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
MP_UNITS_CONSTEVAL explicit(false) ratio(std::intmax_t n, std::intmax_t d = 1) : num{n}, den{d}
|
||||
{
|
||||
gsl_Expects(den != 0);
|
||||
if (num == 0)
|
||||
den = 1;
|
||||
else {
|
||||
std::intmax_t gcd = std::gcd(num, den);
|
||||
const std::intmax_t gcd = std::gcd(num, den);
|
||||
num = num * (den < 0 ? -1 : 1) / gcd;
|
||||
den = detail::abs(den) / gcd;
|
||||
}
|
||||
@@ -114,9 +116,9 @@ MP_UNITS_EXPORT struct ratio {
|
||||
gsl_Assert(std::numeric_limits<std::intmax_t>::max() / r2.num > r1.den);
|
||||
gsl_Assert(std::numeric_limits<std::intmax_t>::max() / r1.den > r2.den);
|
||||
|
||||
std::intmax_t num = std::gcd(r1.num * r2.den, r2.num * r1.den);
|
||||
std::intmax_t den = r1.den * r2.den;
|
||||
std::intmax_t gcd = std::gcd(num, den);
|
||||
const std::intmax_t num = std::gcd(r1.num * r2.den, r2.num * r1.den);
|
||||
const std::intmax_t den = r1.den * r2.den;
|
||||
const std::intmax_t gcd = std::gcd(num, den);
|
||||
return ratio{num / gcd, den / gcd};
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ constexpr Out copy(const symbol_text<N, M>& txt, text_encoding encoding, Out out
|
||||
if constexpr (is_same_v<CharT, char8_t>)
|
||||
return copy(txt.unicode(), out).out;
|
||||
else if constexpr (is_same_v<CharT, char>) {
|
||||
for (char8_t ch : txt.unicode()) *out++ = static_cast<char>(ch);
|
||||
for (const char8_t ch : txt.unicode()) *out++ = static_cast<char>(ch);
|
||||
return out;
|
||||
} else
|
||||
throw std::invalid_argument("Unicode text can't be copied to CharT output");
|
||||
@@ -130,20 +130,17 @@ constexpr Out copy_symbol_exponent(text_encoding encoding, bool negative_power,
|
||||
constexpr auto txt =
|
||||
symbol_text("^-(") + regular<r.num>() + symbol_text("/") + regular<r.den>() + symbol_text(")");
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
} else {
|
||||
constexpr auto txt =
|
||||
symbol_text("^(") + regular<r.num>() + symbol_text("/") + regular<r.den>() + symbol_text(")");
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
}
|
||||
constexpr auto txt = symbol_text("^(") + regular<r.num>() + symbol_text("/") + regular<r.den>() + symbol_text(")");
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
} else if constexpr (r.num != 1) {
|
||||
// add exponent part
|
||||
if (negative_power) {
|
||||
constexpr auto txt = superscript<-r.num>();
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
} else {
|
||||
constexpr auto txt = superscript<r.num>();
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
}
|
||||
constexpr auto txt = superscript<r.num>();
|
||||
return copy<CharT>(txt, encoding, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
// IWYU pragma: always_keep
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
|
||||
#pragma once
|
||||
|
||||
#include <mp-units/bits/hacks.h>
|
||||
@@ -103,3 +103,4 @@ MP_UNITS_DIAGNOSTIC_POP
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
#endif
|
||||
// NOLINTEND(cppcoreguidelines-macro-usage)
|
||||
@@ -36,6 +36,24 @@
|
||||
|
||||
namespace mp_units::detail {
|
||||
|
||||
template<class InputIt, class UnaryPred>
|
||||
constexpr InputIt find_if(InputIt first, InputIt last, UnaryPred p)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (p(*first)) return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template<class InputIt, class UnaryPred>
|
||||
constexpr InputIt find_if_not(InputIt first, InputIt last, UnaryPred q)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (!q(*first)) return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template<class InputIt, class ForwardIt>
|
||||
constexpr InputIt find_first_of(InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last)
|
||||
{
|
||||
@@ -49,6 +67,12 @@ constexpr InputIt find_first_of(InputIt first, InputIt last, ForwardIt s_first,
|
||||
return last;
|
||||
}
|
||||
|
||||
template<class InputIt, class UnaryPred>
|
||||
constexpr bool all_of(InputIt first, InputIt last, UnaryPred p)
|
||||
{
|
||||
return find_if_not(first, last, p) == last;
|
||||
}
|
||||
|
||||
template<class InputIt1, class InputIt2>
|
||||
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
|
||||
{
|
||||
@@ -61,30 +85,31 @@ constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
|
||||
}
|
||||
|
||||
template<class I1, class I2, class Cmp>
|
||||
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp comp) -> decltype(comp(*f1, *f2))
|
||||
constexpr auto lexicographical_compare_three_way(I1 first1, I1 last1, I2 first2, I2 last2, Cmp comp)
|
||||
-> decltype(comp(*first1, *first2))
|
||||
{
|
||||
using ret_t = decltype(comp(*f1, *f2));
|
||||
using ret_t = decltype(comp(*first1, *first2));
|
||||
static_assert(std::disjunction_v<std::is_same<ret_t, std::strong_ordering>, std::is_same<ret_t, std::weak_ordering>,
|
||||
std::is_same<ret_t, std::partial_ordering>>,
|
||||
"The return type must be a comparison category type.");
|
||||
|
||||
bool exhaust1 = (f1 == l1);
|
||||
bool exhaust2 = (f2 == l2);
|
||||
bool exhaust1 = (first1 == last1);
|
||||
bool exhaust2 = (first2 == last2);
|
||||
MP_UNITS_DIAGNOSTIC_PUSH
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
for (; !exhaust1 && !exhaust2; exhaust1 = (++f1 == l1), exhaust2 = (++f2 == l2))
|
||||
if (auto c = comp(*f1, *f2); c != 0) return c;
|
||||
for (; !exhaust1 && !exhaust2; exhaust1 = (++first1 == last1), exhaust2 = (++first2 == last2))
|
||||
if (auto c = comp(*first1, *first2); c != 0) return c;
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
|
||||
return !exhaust1 ? std::strong_ordering::greater
|
||||
: !exhaust2 ? std::strong_ordering::less
|
||||
: std::strong_ordering::equal;
|
||||
if (!exhaust1) return std::strong_ordering::greater;
|
||||
if (!exhaust2) return std::strong_ordering::less;
|
||||
return std::strong_ordering::equal;
|
||||
}
|
||||
|
||||
template<class I1, class I2>
|
||||
constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2)
|
||||
constexpr auto lexicographical_compare_three_way(I1 first1, I1 last1, I2 first2, I2 last2)
|
||||
{
|
||||
return ::mp_units::detail::lexicographical_compare_three_way(f1, l1, f2, l2, std::compare_three_way());
|
||||
return ::mp_units::detail::lexicographical_compare_three_way(first1, last1, first2, last2, std::compare_three_way());
|
||||
}
|
||||
|
||||
template<class ForwardIt>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
// To be replaced with:
|
||||
// P3094: std::basic_fixed_string
|
||||
|
||||
// NOLINTBEGIN(*-avoid-c-arrays)
|
||||
#pragma once
|
||||
|
||||
// TODO use <algorithm> when moved to C++20 modules (parsing takes too long for each translation unit)
|
||||
@@ -84,7 +85,7 @@ struct basic_fixed_string {
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const noexcept { return N == 0; }
|
||||
[[nodiscard]] constexpr size_type size() const noexcept { return N; }
|
||||
[[nodiscard]] constexpr const_pointer data() const noexcept { return data_; }
|
||||
[[nodiscard]] constexpr const_pointer data() const noexcept { return static_cast<const_pointer>(data_); }
|
||||
[[nodiscard]] constexpr const CharT* c_str() const noexcept { return data(); }
|
||||
[[nodiscard]] constexpr value_type operator[](size_type index) const noexcept
|
||||
{
|
||||
@@ -97,7 +98,8 @@ struct basic_fixed_string {
|
||||
[[nodiscard]] constexpr const_iterator end() const noexcept { return data() + size(); }
|
||||
[[nodiscard]] constexpr const_iterator cend() const noexcept { return data() + size(); }
|
||||
|
||||
[[nodiscard]] constexpr operator std::basic_string_view<CharT>() const noexcept
|
||||
// NOLINTNEXTLINE(*-explicit-conversions, google-explicit-constructor)
|
||||
[[nodiscard]] constexpr explicit(false) operator std::basic_string_view<CharT>() const noexcept
|
||||
{
|
||||
return std::basic_string_view<CharT>(cbegin(), cend());
|
||||
}
|
||||
@@ -169,3 +171,4 @@ struct MP_UNITS_STD_FMT::formatter<mp_units::basic_fixed_string<CharT, N>> : for
|
||||
return formatter<std::basic_string_view<CharT>>::format(std::basic_string_view<CharT>(str), ctx);
|
||||
}
|
||||
};
|
||||
// NOLINTEND(*-avoid-c-arrays)
|
||||
@@ -65,7 +65,7 @@ namespace mp_units::detail {
|
||||
template<std::size_t N>
|
||||
[[nodiscard]] consteval std::array<std::uintmax_t, N> first_n_primes()
|
||||
{
|
||||
std::array<std::uintmax_t, N> primes;
|
||||
std::array<std::uintmax_t, N> primes{};
|
||||
primes[0] = 2;
|
||||
for (std::size_t i = 1; i < N; ++i) {
|
||||
primes[i] = primes[i - 1] + 1;
|
||||
@@ -77,7 +77,7 @@ template<std::size_t N>
|
||||
}
|
||||
|
||||
template<std::size_t N, typename Callable>
|
||||
consteval void call_for_coprimes_up_to(std::uintmax_t n, const std::array<std::uintmax_t, N>& basis, Callable&& call)
|
||||
consteval void call_for_coprimes_up_to(std::uintmax_t n, const std::array<std::uintmax_t, N>& basis, Callable call)
|
||||
{
|
||||
for (std::uintmax_t i = 0u; i < n; ++i) {
|
||||
if (std::apply([&i](auto... primes) { return ((i % primes != 0) && ...); }, basis)) {
|
||||
@@ -97,7 +97,7 @@ template<std::size_t N>
|
||||
template<std::size_t ResultSize, std::size_t N>
|
||||
[[nodiscard]] consteval auto coprimes_up_to(std::size_t n, const std::array<std::uintmax_t, N>& basis)
|
||||
{
|
||||
std::array<std::uintmax_t, ResultSize> coprimes;
|
||||
std::array<std::uintmax_t, ResultSize> coprimes{};
|
||||
std::size_t i = 0u;
|
||||
|
||||
call_for_coprimes_up_to(n, basis, [&coprimes, &i](std::uintmax_t cp) { coprimes[i++] = cp; });
|
||||
@@ -120,7 +120,7 @@ constexpr std::invoke_result_t<UnaryFunction, std::iter_value_t<InputIt>> get_fi
|
||||
UnaryFunction f)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (auto opt = f(*first)) return *opt;
|
||||
if (auto opt = f(*first)) return opt;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ template<typename T>
|
||||
template<typename T1, typename T2>
|
||||
[[nodiscard]] consteval auto better_type_name(T1 v1, T2 v2)
|
||||
{
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (type_name<T1>().size() < type_name<T2>().size())
|
||||
return v1;
|
||||
else if constexpr (type_name<T2>().size() < type_name<T1>().size())
|
||||
@@ -44,6 +45,7 @@ template<typename T1, typename T2>
|
||||
return v1;
|
||||
else
|
||||
return v2;
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
} // namespace mp_units::detail
|
||||
@@ -44,7 +44,7 @@ struct fill_align_width_format_specs {
|
||||
template<typename Char>
|
||||
[[nodiscard]] constexpr const Char* at_most_one_of(const Char* begin, const Char* end, std::string_view modifiers)
|
||||
{
|
||||
auto it = find_first_of(begin, end, modifiers.begin(), modifiers.end());
|
||||
const Char* const it = find_first_of(begin, end, modifiers.begin(), modifiers.end());
|
||||
if (it != end && find_first_of(it + 1, end, modifiers.begin(), modifiers.end()) != end)
|
||||
throw MP_UNITS_STD_FMT::format_error("only one of '" + std::string(modifiers) +
|
||||
"' unit modifiers may be used in the format spec");
|
||||
@@ -141,17 +141,16 @@ public:
|
||||
auto specs = specs_;
|
||||
mp_units::detail::handle_dynamic_spec<mp_units::detail::width_checker>(specs.width, specs.width_ref, ctx);
|
||||
|
||||
if (specs.width == 0) {
|
||||
if (specs.width == 0)
|
||||
// Avoid extra copying if width is not specified
|
||||
return mp_units::dimension_symbol_to<Char>(ctx.out(), d, specs);
|
||||
} else {
|
||||
std::basic_string<Char> unit_buffer;
|
||||
mp_units::dimension_symbol_to<Char>(std::back_inserter(unit_buffer), d, specs);
|
||||
std::basic_string<Char> unit_buffer;
|
||||
mp_units::dimension_symbol_to<Char>(std::back_inserter(unit_buffer), d, specs);
|
||||
|
||||
std::basic_string<Char> global_format_buffer = "{:" + std::basic_string<Char>{fill_align_width_format_str_} + "}";
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
MP_UNITS_STD_FMT::make_format_args(unit_buffer));
|
||||
}
|
||||
const std::basic_string<Char> global_format_buffer =
|
||||
"{:" + std::basic_string<Char>{fill_align_width_format_str_} + "}";
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
MP_UNITS_STD_FMT::make_format_args(unit_buffer));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -231,17 +230,16 @@ public:
|
||||
auto specs = specs_;
|
||||
mp_units::detail::handle_dynamic_spec<mp_units::detail::width_checker>(specs.width, specs.width_ref, ctx);
|
||||
|
||||
if (specs.width == 0) {
|
||||
if (specs.width == 0)
|
||||
// Avoid extra copying if width is not specified
|
||||
return mp_units::unit_symbol_to<Char>(ctx.out(), u, specs);
|
||||
} else {
|
||||
std::basic_string<Char> unit_buffer;
|
||||
mp_units::unit_symbol_to<Char>(std::back_inserter(unit_buffer), u, specs);
|
||||
std::basic_string<Char> unit_buffer;
|
||||
mp_units::unit_symbol_to<Char>(std::back_inserter(unit_buffer), u, specs);
|
||||
|
||||
std::basic_string<Char> global_format_buffer = "{:" + std::basic_string<Char>{fill_align_width_format_str_} + "}";
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
MP_UNITS_STD_FMT::make_format_args(unit_buffer));
|
||||
}
|
||||
const std::basic_string<Char> global_format_buffer =
|
||||
"{:" + std::basic_string<Char>{fill_align_width_format_str_} + "}";
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
MP_UNITS_STD_FMT::make_format_args(unit_buffer));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -327,7 +325,7 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
|
||||
quantity_formatter(const formatter&, OutputIt, Args...) -> quantity_formatter<OutputIt>;
|
||||
|
||||
template<typename Handler>
|
||||
constexpr const Char* parse_quantity_specs(const Char* begin, const Char* end, Handler&& handler) const
|
||||
constexpr const Char* parse_quantity_specs(const Char* begin, const Char* end, Handler& handler) const
|
||||
{
|
||||
if (begin == end || *begin == ':' || *begin == '}') return begin;
|
||||
if (*begin != '%')
|
||||
@@ -342,9 +340,9 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
|
||||
handler.on_text(begin, ++ptr); // account for ':'
|
||||
++ptr; // consume the second ':'
|
||||
continue;
|
||||
} else
|
||||
// default specs started
|
||||
break;
|
||||
}
|
||||
// default specs started
|
||||
break;
|
||||
}
|
||||
if (c != '%') {
|
||||
++ptr;
|
||||
@@ -383,9 +381,9 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
|
||||
template<typename Formatter>
|
||||
constexpr const Char* parse_default_spec(const Char* begin, const Char* end, Formatter& f, std::string& format_str)
|
||||
{
|
||||
if (begin == end || *begin++ != '[')
|
||||
if (begin == end || *begin != '[')
|
||||
throw MP_UNITS_STD_FMT::format_error("`default-spec` should contain a `[` character");
|
||||
auto it = begin;
|
||||
auto it = ++begin;
|
||||
for (int nested_brackets = 0; it != end && !(*it == ']' && nested_brackets == 0); it++) {
|
||||
if (*it == '[') ++nested_brackets;
|
||||
if (*it == ']') {
|
||||
@@ -428,19 +426,18 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
|
||||
template<typename OutputIt, typename FormatContext>
|
||||
OutputIt format_quantity(OutputIt out, const quantity_t& q, FormatContext& ctx) const
|
||||
{
|
||||
std::locale locale = MP_UNITS_FMT_LOCALE(ctx.locale());
|
||||
const std::locale locale = MP_UNITS_FMT_LOCALE(ctx.locale());
|
||||
if (modifiers_format_str_.empty()) {
|
||||
// default
|
||||
out = MP_UNITS_STD_FMT::vformat_to(out, locale, rep_format_str_,
|
||||
MP_UNITS_STD_FMT::make_format_args(q.numerical_value_ref_in(q.unit)));
|
||||
if constexpr (mp_units::space_before_unit_symbol<unit>) *out++ = ' ';
|
||||
return MP_UNITS_STD_FMT::vformat_to(out, locale, unit_format_str_, MP_UNITS_STD_FMT::make_format_args(q.unit));
|
||||
} else {
|
||||
// user provided format
|
||||
quantity_formatter f{*this, out, q, locale};
|
||||
parse_quantity_specs(modifiers_format_str_.begin(), modifiers_format_str_.end(), f);
|
||||
return f.out;
|
||||
}
|
||||
// user provided format
|
||||
quantity_formatter f{*this, out, q, locale};
|
||||
parse_quantity_specs(modifiers_format_str_.begin(), modifiers_format_str_.end(), f);
|
||||
return f.out;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -451,15 +448,15 @@ public:
|
||||
begin = parse_fill_align_width(ctx, begin, end, specs_, mp_units::detail::fmt_align::right);
|
||||
if (begin == end) return begin;
|
||||
|
||||
format_checker checker{};
|
||||
const format_checker checker{};
|
||||
auto it = parse_quantity_specs(begin, end, checker);
|
||||
modifiers_format_str_ = {begin, it};
|
||||
|
||||
return parse_defaults_specs(it, end);
|
||||
}
|
||||
|
||||
template<typename FormatContext>
|
||||
auto format(const quantity_t& q, FormatContext& ctx) const -> decltype(ctx.out())
|
||||
template<typename OutIt>
|
||||
OutIt format(const quantity_t& q, MP_UNITS_STD_FMT::basic_format_context<OutIt, Char>& ctx) const
|
||||
{
|
||||
auto specs = specs_;
|
||||
mp_units::detail::handle_dynamic_spec<mp_units::detail::width_checker>(specs.width, specs.width_ref, ctx);
|
||||
@@ -468,14 +465,13 @@ public:
|
||||
// Avoid extra copying if width is not specified
|
||||
format_quantity(ctx.out(), q, ctx);
|
||||
return ctx.out();
|
||||
} else {
|
||||
std::basic_string<Char> quantity_buffer;
|
||||
format_quantity(std::back_inserter(quantity_buffer), q, ctx);
|
||||
|
||||
std::basic_string<Char> fill_align_width_format_str;
|
||||
mp_units::detail::format_global_buffer(std::back_inserter(fill_align_width_format_str), specs);
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), fill_align_width_format_str,
|
||||
MP_UNITS_STD_FMT::make_format_args(quantity_buffer));
|
||||
}
|
||||
std::basic_string<Char> quantity_buffer;
|
||||
format_quantity(std::back_inserter(quantity_buffer), q, ctx);
|
||||
|
||||
std::basic_string<Char> fill_align_width_format_str;
|
||||
mp_units::detail::format_global_buffer(std::back_inserter(fill_align_width_format_str), specs);
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), fill_align_width_format_str,
|
||||
MP_UNITS_STD_FMT::make_format_args(quantity_buffer));
|
||||
}
|
||||
};
|
||||
@@ -239,13 +239,13 @@ namespace detail {
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, Dimension D>
|
||||
requires requires { D::symbol; }
|
||||
constexpr Out dimension_symbol_impl(Out out, D, dimension_symbol_formatting fmt, bool negative_power)
|
||||
constexpr Out dimension_symbol_impl(Out out, D, const dimension_symbol_formatting& fmt, bool negative_power)
|
||||
{
|
||||
return copy_symbol<CharT>(D::symbol, fmt.encoding, negative_power, out);
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, typename F, int Num, int... Den>
|
||||
constexpr auto dimension_symbol_impl(Out out, const power<F, Num, Den...>&, dimension_symbol_formatting fmt,
|
||||
constexpr auto dimension_symbol_impl(Out out, const power<F, Num, Den...>&, const dimension_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
out = dimension_symbol_impl<CharT>(out, F{}, fmt, false); // negative power component will be added below if needed
|
||||
@@ -253,7 +253,7 @@ constexpr auto dimension_symbol_impl(Out out, const power<F, Num, Den...>&, dime
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, DerivedDimensionExpr... Ms>
|
||||
constexpr Out dimension_symbol_impl(Out out, const type_list<Ms...>&, dimension_symbol_formatting fmt,
|
||||
constexpr Out dimension_symbol_impl(Out out, const type_list<Ms...>&, const dimension_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
return (..., (out = dimension_symbol_impl<CharT>(out, Ms{}, fmt, negative_power)));
|
||||
@@ -261,7 +261,7 @@ constexpr Out dimension_symbol_impl(Out out, const type_list<Ms...>&, dimension_
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, DerivedDimensionExpr... Nums, DerivedDimensionExpr... Dens>
|
||||
constexpr Out dimension_symbol_impl(Out out, const type_list<Nums...>& nums, const type_list<Dens...>& dens,
|
||||
dimension_symbol_formatting fmt)
|
||||
const dimension_symbol_formatting& fmt)
|
||||
{
|
||||
if constexpr (sizeof...(Nums) == 0 && sizeof...(Dens) == 0) {
|
||||
// dimensionless quantity
|
||||
@@ -277,7 +277,7 @@ constexpr Out dimension_symbol_impl(Out out, const type_list<Nums...>& nums, con
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, typename... Expr>
|
||||
constexpr Out dimension_symbol_impl(Out out, const derived_dimension<Expr...>&, dimension_symbol_formatting fmt,
|
||||
constexpr Out dimension_symbol_impl(Out out, const derived_dimension<Expr...>&, const dimension_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
gsl_Expects(negative_power == false);
|
||||
@@ -289,7 +289,7 @@ constexpr Out dimension_symbol_impl(Out out, const derived_dimension<Expr...>&,
|
||||
} // namespace detail
|
||||
|
||||
MP_UNITS_EXPORT template<typename CharT = char, std::output_iterator<CharT> Out, Dimension D>
|
||||
constexpr Out dimension_symbol_to(Out out, D d, dimension_symbol_formatting fmt = dimension_symbol_formatting{})
|
||||
constexpr Out dimension_symbol_to(Out out, D d, const dimension_symbol_formatting& fmt = dimension_symbol_formatting{})
|
||||
{
|
||||
return detail::dimension_symbol_impl<CharT>(out, d, fmt, false);
|
||||
}
|
||||
|
||||
@@ -374,6 +374,7 @@ namespace detail {
|
||||
// Divide a number by a given base raised to some power.
|
||||
//
|
||||
// Undefined unless base > 1, pow >= 0, and (base ^ pow) evenly divides n.
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
[[nodiscard]] consteval std::intmax_t remove_power(std::intmax_t base, std::intmax_t pow, std::intmax_t n)
|
||||
{
|
||||
while (pow-- > 0) {
|
||||
@@ -795,8 +796,9 @@ template<std::intmax_t N>
|
||||
struct prime_factorization {
|
||||
[[nodiscard]] static consteval std::intmax_t get_or_compute_first_factor()
|
||||
{
|
||||
if constexpr (known_first_factor<N>.has_value()) {
|
||||
return known_first_factor<N>.value();
|
||||
constexpr auto opt = known_first_factor<N>;
|
||||
if constexpr (opt.has_value()) {
|
||||
return opt.value(); // NOLINT(bugprone-unchecked-optional-access)
|
||||
} else {
|
||||
return static_cast<std::intmax_t>(factorizer::find_first_factor(N));
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ public:
|
||||
quantity() = default;
|
||||
quantity(const quantity&) = default;
|
||||
quantity(quantity&&) = default;
|
||||
~quantity() = default;
|
||||
|
||||
template<typename Value>
|
||||
requires std::same_as<std::remove_cvref_t<Value>, Rep>
|
||||
@@ -227,6 +228,7 @@ public:
|
||||
numerical_value_is_an_implementation_detail_)),
|
||||
convert_explicitly> ||
|
||||
!std::convertible_to<Rep, typename quantity_like_traits<Q>::rep>) constexpr
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
operator Q_() const& noexcept(
|
||||
noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_is_an_implementation_detail_)) &&
|
||||
std::is_nothrow_copy_constructible_v<rep>)
|
||||
@@ -241,6 +243,7 @@ public:
|
||||
numerical_value_is_an_implementation_detail_)),
|
||||
convert_explicitly> ||
|
||||
!std::convertible_to<Rep, typename quantity_like_traits<Q>::rep>) constexpr
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
operator Q_() && noexcept(
|
||||
noexcept(quantity_like_traits<Q>::from_numerical_value(numerical_value_is_an_implementation_detail_)) &&
|
||||
std::is_nothrow_move_constructible_v<rep>)
|
||||
@@ -529,19 +532,15 @@ MP_UNITS_EXPORT_END
|
||||
|
||||
} // namespace mp_units
|
||||
|
||||
namespace std {
|
||||
|
||||
template<mp_units::Quantity Q1, mp_units::Quantity Q2>
|
||||
requires requires {
|
||||
{
|
||||
mp_units::common_reference(Q1::reference, Q2::reference)
|
||||
} -> mp_units::Reference;
|
||||
typename common_type_t<typename Q1::rep, typename Q2::rep>;
|
||||
typename std::common_type_t<typename Q1::rep, typename Q2::rep>;
|
||||
}
|
||||
struct common_type<Q1, Q2> {
|
||||
struct std::common_type<Q1, Q2> {
|
||||
public:
|
||||
using type = mp_units::quantity<mp_units::common_reference(Q1::reference, Q2::reference),
|
||||
common_type_t<typename Q1::rep, typename Q2::rep>>;
|
||||
std::common_type_t<typename Q1::rep, typename Q2::rep>>;
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
@@ -36,6 +36,7 @@
|
||||
namespace mp_units {
|
||||
|
||||
MP_UNITS_EXPORT template<typename Derived, QuantitySpec auto QS>
|
||||
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
|
||||
struct absolute_point_origin {
|
||||
static constexpr QuantitySpec auto quantity_spec = QS;
|
||||
using _type_ = absolute_point_origin;
|
||||
@@ -157,6 +158,7 @@ public:
|
||||
quantity_point() = default;
|
||||
quantity_point(const quantity_point&) = default;
|
||||
quantity_point(quantity_point&&) = default;
|
||||
~quantity_point() = default;
|
||||
|
||||
template<typename Q>
|
||||
requires QuantityOf<std::remove_cvref_t<Q>, get_quantity_spec(R)> && std::constructible_from<quantity_type, Q> &&
|
||||
@@ -290,6 +292,7 @@ public:
|
||||
convert_explicitly> ||
|
||||
!std::convertible_to<quantity_type, quantity<quantity_point_like_traits<QP>::reference,
|
||||
typename quantity_point_like_traits<QP>::rep>>) constexpr
|
||||
// NOLINTNEXTLINE(*-explicit-conversions, google-explicit-constructor)
|
||||
operator QP_() const& noexcept(
|
||||
noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_is_an_implementation_detail_)) &&
|
||||
std::is_nothrow_copy_constructible_v<rep>)
|
||||
@@ -307,6 +310,7 @@ public:
|
||||
convert_explicitly> ||
|
||||
!std::convertible_to<quantity_type, quantity<quantity_point_like_traits<QP>::reference,
|
||||
typename quantity_point_like_traits<QP>::rep>>) constexpr
|
||||
// NOLINTNEXTLINE(*-explicit-conversions, google-explicit-constructor)
|
||||
operator QP_() && noexcept(
|
||||
noexcept(quantity_point_like_traits<QP>::from_quantity(quantity_from_origin_is_an_implementation_detail_)) &&
|
||||
std::is_nothrow_move_constructible_v<rep>)
|
||||
|
||||
@@ -595,7 +595,7 @@ MP_UNITS_EXPORT_END
|
||||
|
||||
namespace detail {
|
||||
|
||||
enum class specs_convertible_result { no, cast, explicit_conversion, yes };
|
||||
enum class specs_convertible_result : std::int8_t { no, cast, explicit_conversion, yes };
|
||||
|
||||
template<QuantitySpec Q>
|
||||
[[nodiscard]] consteval int get_complexity(Q);
|
||||
@@ -634,9 +634,7 @@ template<QuantitySpec Q>
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs)
|
||||
{
|
||||
if constexpr (lhs == rhs)
|
||||
return false;
|
||||
else if constexpr (lhs == dimension_one)
|
||||
if constexpr (lhs == rhs || lhs == dimension_one)
|
||||
return false;
|
||||
else if constexpr (rhs == dimension_one)
|
||||
return true;
|
||||
@@ -775,7 +773,7 @@ template<int Complexity, QuantitySpec Q, typename Den, typename... Dens>
|
||||
template<int Complexity, QuantitySpec Q>
|
||||
[[nodiscard]] consteval auto explode(Q, type_list<>, type_list<>)
|
||||
{
|
||||
return explode_result{dimensionless};
|
||||
return explode_result{.quantity = dimensionless};
|
||||
}
|
||||
|
||||
template<int Complexity, IntermediateDerivedQuantitySpec Q>
|
||||
@@ -868,11 +866,11 @@ template<typename... DensFrom>
|
||||
[[nodiscard]] consteval specs_convertible_result are_ingredients_convertible(type_list<>, type_list<>, type_list<>,
|
||||
type_list<>);
|
||||
|
||||
enum class prepend_rest { no, first, second };
|
||||
enum class prepend_rest : std::int8_t { no, first, second };
|
||||
|
||||
template<QuantitySpec From = struct dimensionless, QuantitySpec To = struct dimensionless, typename Elem = int>
|
||||
struct extract_results {
|
||||
bool same_dimension;
|
||||
bool same_dimension{};
|
||||
From from{};
|
||||
To to{};
|
||||
prepend_rest prepend{};
|
||||
@@ -914,7 +912,7 @@ template<typename From, typename To>
|
||||
constexpr auto to_factor = std::get<0>(to_norm);
|
||||
constexpr auto to_exp = std::get<1>(to_norm);
|
||||
if constexpr (from_factor.dimension != to_factor.dimension)
|
||||
return extract_results{false};
|
||||
return extract_results{.same_dimension = false};
|
||||
else if constexpr (from_exp > to_exp)
|
||||
return extract_results{true, pow<to_exp.num, to_exp.den>(from_factor), pow<to_exp.num, to_exp.den>(to_factor),
|
||||
prepend_rest::first,
|
||||
@@ -926,30 +924,37 @@ template<typename From, typename To>
|
||||
}
|
||||
}
|
||||
|
||||
enum class process_entities { numerators, denominators, from, to };
|
||||
enum class process_entities : std::int8_t { numerators, denominators, from, to };
|
||||
|
||||
template<process_entities Entities, auto Ext, TypeList NumFrom, TypeList DenFrom, TypeList NumTo, TypeList DenTo>
|
||||
[[nodiscard]] consteval specs_convertible_result process_num_den(NumFrom num_from, DenFrom den_from, NumTo num_to,
|
||||
DenTo den_to)
|
||||
{
|
||||
constexpr auto res = convertible_impl(Ext.from, Ext.to);
|
||||
if constexpr (Ext.prepend == prepend_rest::no)
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, num_to, den_to));
|
||||
else {
|
||||
using elem = std::remove_cvref_t<decltype(Ext.elem)>;
|
||||
if constexpr (Entities == process_entities::numerators) {
|
||||
if constexpr (Ext.prepend == prepend_rest::first)
|
||||
return min(res, are_ingredients_convertible(type_list_push_front<NumFrom, elem>{}, den_from, num_to, den_to));
|
||||
else
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, type_list_push_front<NumTo, elem>{}, den_to));
|
||||
} else {
|
||||
if constexpr (Ext.prepend == prepend_rest::first)
|
||||
return min(res, are_ingredients_convertible(num_from, type_list_push_front<DenFrom, elem>{}, num_to, den_to));
|
||||
else
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, num_to, type_list_push_front<DenTo, elem>{}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<process_entities Entities, auto Ext, TypeList NumFrom, TypeList DenFrom, TypeList NumTo, TypeList DenTo>
|
||||
[[nodiscard]] consteval specs_convertible_result process_extracted(NumFrom num_from, DenFrom den_from, NumTo num_to,
|
||||
DenTo den_to)
|
||||
{
|
||||
if constexpr (Entities == process_entities::numerators || Entities == process_entities::denominators) {
|
||||
constexpr auto res = convertible_impl(Ext.from, Ext.to);
|
||||
if constexpr (Ext.prepend == prepend_rest::no)
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, num_to, den_to));
|
||||
else {
|
||||
using elem = std::remove_cvref_t<decltype(Ext.elem)>;
|
||||
if constexpr (Entities == process_entities::numerators) {
|
||||
if constexpr (Ext.prepend == prepend_rest::first)
|
||||
return min(res, are_ingredients_convertible(type_list_push_front<NumFrom, elem>{}, den_from, num_to, den_to));
|
||||
else
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, type_list_push_front<NumTo, elem>{}, den_to));
|
||||
} else {
|
||||
if constexpr (Ext.prepend == prepend_rest::first)
|
||||
return min(res, are_ingredients_convertible(num_from, type_list_push_front<DenFrom, elem>{}, num_to, den_to));
|
||||
else
|
||||
return min(res, are_ingredients_convertible(num_from, den_from, num_to, type_list_push_front<DenTo, elem>{}));
|
||||
}
|
||||
}
|
||||
return process_num_den<Entities, Ext>(num_from, den_from, num_to, den_to);
|
||||
} else {
|
||||
if constexpr (Ext.prepend == prepend_rest::no)
|
||||
return are_ingredients_convertible(num_from, den_from, num_to, den_to);
|
||||
@@ -1330,50 +1335,63 @@ template<NamedQuantitySpec From, IntermediateDerivedQuantitySpec To>
|
||||
type_list_sort<typename To::_den_, type_list_of_ingredients_less>{});
|
||||
}
|
||||
|
||||
template<QuantitySpec From, QuantitySpec To>
|
||||
[[nodiscard]] consteval specs_convertible_result convertible_kinds(From from_kind, To to_kind)
|
||||
{
|
||||
constexpr auto exploded_kind_result = [](specs_convertible_result res) {
|
||||
using enum specs_convertible_result;
|
||||
return res == no ? no : yes;
|
||||
};
|
||||
if constexpr ((NamedQuantitySpec<std::remove_cvref_t<decltype(from_kind)>> &&
|
||||
NamedQuantitySpec<std::remove_cvref_t<decltype(to_kind)>>) ||
|
||||
get_complexity(from_kind) == get_complexity(to_kind))
|
||||
return convertible_impl(from_kind, to_kind);
|
||||
else if constexpr (get_complexity(from_kind) > get_complexity(to_kind))
|
||||
return exploded_kind_result(
|
||||
convertible_impl(get_kind_tree_root(explode<get_complexity(to_kind)>(from_kind).quantity), to_kind));
|
||||
else
|
||||
return exploded_kind_result(
|
||||
convertible_impl(from_kind, get_kind_tree_root(explode<get_complexity(from_kind)>(to_kind).quantity)));
|
||||
}
|
||||
|
||||
template<NamedQuantitySpec From, NamedQuantitySpec To>
|
||||
[[nodiscard]] consteval specs_convertible_result convertible_named(From from, To to)
|
||||
{
|
||||
using enum specs_convertible_result;
|
||||
|
||||
if constexpr (have_common_base(From{}, To{})) {
|
||||
if constexpr (std::derived_from<From, To>) return yes;
|
||||
if constexpr (std::derived_from<To, From>) return explicit_conversion;
|
||||
if constexpr (get_kind(From{}) == get_kind(To{})) return cast;
|
||||
return no;
|
||||
} else if constexpr (get_kind(From{}) != get_kind(To{}))
|
||||
return no;
|
||||
else if constexpr (get_complexity(From{}) != get_complexity(To{})) {
|
||||
if constexpr (get_complexity(From{}) > get_complexity(To{}))
|
||||
return convertible_impl(explode<get_complexity(to)>(from).quantity, to);
|
||||
else {
|
||||
auto res = explode<get_complexity(from)>(to);
|
||||
return min(res.result, convertible_impl(from, res.quantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<QuantitySpec From, QuantitySpec To>
|
||||
[[nodiscard]] consteval specs_convertible_result convertible_impl(From from, To to)
|
||||
{
|
||||
using enum specs_convertible_result;
|
||||
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (From::dimension != To::dimension)
|
||||
return no;
|
||||
else if constexpr (From{} == To{})
|
||||
return yes;
|
||||
else if constexpr (QuantityKindSpec<From> || QuantityKindSpec<To>) {
|
||||
constexpr auto from_kind = get_kind_tree_root(From{});
|
||||
constexpr auto to_kind = get_kind_tree_root(To{});
|
||||
constexpr auto exploded_kind_result = [](specs_convertible_result res) {
|
||||
using enum specs_convertible_result;
|
||||
return res == no ? no : yes;
|
||||
};
|
||||
if constexpr ((NamedQuantitySpec<std::remove_cvref_t<decltype(from_kind)>> &&
|
||||
NamedQuantitySpec<std::remove_cvref_t<decltype(to_kind)>>) ||
|
||||
get_complexity(from_kind) == get_complexity(to_kind))
|
||||
return convertible_impl(from_kind, to_kind);
|
||||
else if constexpr (get_complexity(from_kind) > get_complexity(to_kind))
|
||||
return exploded_kind_result(
|
||||
convertible_impl(get_kind_tree_root(explode<get_complexity(to_kind)>(from_kind).quantity), to_kind));
|
||||
else
|
||||
return exploded_kind_result(
|
||||
convertible_impl(from_kind, get_kind_tree_root(explode<get_complexity(from_kind)>(to_kind).quantity)));
|
||||
return convertible_kinds(get_kind_tree_root(from), get_kind_tree_root(to));
|
||||
} else if constexpr (NestedQuantityKindSpecOf<get_kind_tree_root(To{}), from> && get_kind_tree_root(To{}) == To{})
|
||||
return yes;
|
||||
else if constexpr (NamedQuantitySpec<From> && NamedQuantitySpec<To>) {
|
||||
if constexpr (have_common_base(From{}, To{})) {
|
||||
if (std::derived_from<From, To>)
|
||||
return yes;
|
||||
else
|
||||
return std::derived_from<To, From> ? explicit_conversion : (get_kind(from) == get_kind(to) ? cast : no);
|
||||
} else if constexpr (get_kind(From{}) != get_kind(To{}))
|
||||
return no;
|
||||
else if constexpr (get_complexity(From{}) != get_complexity(To{})) {
|
||||
if constexpr (get_complexity(From{}) > get_complexity(To{}))
|
||||
return convertible_impl(explode<get_complexity(to)>(from).quantity, to);
|
||||
else {
|
||||
auto res = explode<get_complexity(from)>(to);
|
||||
return min(res.result, convertible_impl(from, res.quantity));
|
||||
}
|
||||
}
|
||||
return convertible_named(from, to);
|
||||
} else if constexpr (IntermediateDerivedQuantitySpec<From> && IntermediateDerivedQuantitySpec<To>) {
|
||||
return are_ingredients_convertible(from, to);
|
||||
} else if constexpr (IntermediateDerivedQuantitySpec<From>) {
|
||||
@@ -1394,6 +1412,7 @@ template<QuantitySpec From, QuantitySpec To>
|
||||
else
|
||||
return min(res.result, are_ingredients_convertible(from, to));
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
return no;
|
||||
}
|
||||
|
||||
@@ -1454,6 +1473,7 @@ template<QuantitySpec Q>
|
||||
return false;
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (detail::QuantityKindSpec<Q>) {
|
||||
return remove_kind(q);
|
||||
} else if constexpr (defined_as_kind(Q{})) {
|
||||
@@ -1467,6 +1487,7 @@ template<QuantitySpec Q>
|
||||
// root quantity
|
||||
return q;
|
||||
}
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
@@ -1488,6 +1509,8 @@ template<QuantitySpec Q1, QuantitySpec Q2>
|
||||
{
|
||||
using QQ1 = std::remove_const_t<decltype(detail::remove_kind(q1))>;
|
||||
using QQ2 = std::remove_const_t<decltype(detail::remove_kind(q2))>;
|
||||
|
||||
// NOLINTBEGIN(bugprone-branch-clone)
|
||||
if constexpr (is_same_v<Q1, Q2>)
|
||||
return q1;
|
||||
else if constexpr (detail::NestedQuantityKindSpecOf<Q1{}, Q2{}>)
|
||||
@@ -1512,6 +1535,7 @@ template<QuantitySpec Q1, QuantitySpec Q2>
|
||||
return get_kind_tree_root(q2);
|
||||
else
|
||||
return get_kind_tree_root(q1);
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2,
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace mp_units {
|
||||
* For example, the Cauchy stress tensor possess magnitude, direction,
|
||||
* and orientation qualities.
|
||||
*/
|
||||
MP_UNITS_EXPORT enum class quantity_character { scalar, vector, tensor };
|
||||
MP_UNITS_EXPORT enum class quantity_character : std::int8_t { scalar, vector, tensor };
|
||||
|
||||
namespace detail {
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// NOLINTBEGIN(*-avoid-c-arrays)
|
||||
#pragma once
|
||||
|
||||
// IWYU pragma: private, include <mp-units/framework.h>
|
||||
@@ -43,6 +44,7 @@ static_assert(std::text_encoding::literal().mib() == std::text_encoding::id::UTF
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
// NOLINTNEXTLINE(readability-enum-initial-value)
|
||||
MP_UNITS_EXPORT enum class text_encoding : std::int8_t {
|
||||
unicode, // µs; m³; L²MT⁻³
|
||||
ascii, // us; m^3; L^2MT^-3
|
||||
@@ -60,9 +62,7 @@ constexpr bool is_basic_literal_character_set_char(char ch)
|
||||
template<std::size_t N>
|
||||
constexpr bool is_basic_literal_character_set(const char (&txt)[N]) noexcept
|
||||
{
|
||||
for (auto ch : txt)
|
||||
if (!is_basic_literal_character_set_char(ch)) return false;
|
||||
return true;
|
||||
return detail::all_of(std::begin(txt), std::end(txt), is_basic_literal_character_set_char);
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
@@ -94,6 +94,7 @@ struct symbol_text {
|
||||
gsl_Expects(detail::is_basic_literal_character_set_char(ch));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(*-avoid-c-arrays)
|
||||
constexpr explicit(false) symbol_text(const char (&txt)[N + 1]) :
|
||||
unicode_(detail::to_u8string(basic_fixed_string{txt})), ascii_(txt)
|
||||
{
|
||||
@@ -106,6 +107,7 @@ struct symbol_text {
|
||||
gsl_Expects(detail::is_basic_literal_character_set(txt.data_));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(*-avoid-c-arrays)
|
||||
constexpr symbol_text(const char8_t (&u)[N + 1], const char (&a)[M + 1]) : unicode_(u), ascii_(a)
|
||||
{
|
||||
gsl_Expects(u[N] == char8_t{});
|
||||
@@ -166,3 +168,4 @@ template<std::size_t N, std::size_t M>
|
||||
symbol_text(const fixed_u8string<N>&, const fixed_string<M>&) -> symbol_text<N, M>;
|
||||
|
||||
} // namespace mp_units
|
||||
// NOLINTEND(*-avoid-c-arrays)
|
||||
@@ -688,6 +688,7 @@ inline constexpr bool space_before_unit_symbol<per_mille> = false;
|
||||
|
||||
// get_unit_symbol
|
||||
|
||||
// NOLINTNEXTLINE(readability-enum-initial-value)
|
||||
enum class unit_symbol_solidus : std::int8_t {
|
||||
one_denominator, // m/s; kg m⁻¹ s⁻¹
|
||||
always, // m/s; kg/(m s)
|
||||
@@ -695,6 +696,7 @@ enum class unit_symbol_solidus : std::int8_t {
|
||||
default_denominator = one_denominator
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-enum-initial-value)
|
||||
enum class unit_symbol_separator : std::int8_t {
|
||||
space, // kg m²/s²
|
||||
half_high_dot, // kg⋅m²/s² (valid only for unicode encoding)
|
||||
@@ -712,7 +714,7 @@ MP_UNITS_EXPORT_END
|
||||
namespace detail {
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out>
|
||||
constexpr Out print_separator(Out out, unit_symbol_formatting fmt)
|
||||
constexpr Out print_separator(Out out, const unit_symbol_formatting& fmt)
|
||||
{
|
||||
if (fmt.separator == unit_symbol_separator::half_high_dot) {
|
||||
if (fmt.encoding != text_encoding::unicode)
|
||||
@@ -727,13 +729,14 @@ constexpr Out print_separator(Out out, unit_symbol_formatting fmt)
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, Unit U>
|
||||
requires requires { U::symbol; }
|
||||
constexpr Out unit_symbol_impl(Out out, U, unit_symbol_formatting fmt, bool negative_power)
|
||||
constexpr Out unit_symbol_impl(Out out, U, const unit_symbol_formatting& fmt, bool negative_power)
|
||||
{
|
||||
return copy_symbol<CharT>(U::symbol, fmt.encoding, negative_power, out);
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, auto M, typename U>
|
||||
constexpr Out unit_symbol_impl(Out out, const scaled_unit<M, U>& u, unit_symbol_formatting fmt, bool negative_power)
|
||||
constexpr Out unit_symbol_impl(Out out, const scaled_unit<M, U>& u, const unit_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
if constexpr (M == mag<1>) {
|
||||
// no ratio/prefix
|
||||
@@ -748,14 +751,15 @@ constexpr Out unit_symbol_impl(Out out, const scaled_unit<M, U>& u, unit_symbol_
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, typename F, int Num, int... Den>
|
||||
constexpr auto unit_symbol_impl(Out out, const power<F, Num, Den...>&, unit_symbol_formatting fmt, bool negative_power)
|
||||
constexpr auto unit_symbol_impl(Out out, const power<F, Num, Den...>&, const unit_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
out = unit_symbol_impl<CharT>(out, F{}, fmt, false); // negative power component will be added below if needed
|
||||
return copy_symbol_exponent<CharT, Num, Den...>(fmt.encoding, negative_power, out);
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, DerivedUnitExpr M>
|
||||
constexpr Out unit_symbol_impl(Out out, M m, std::size_t Idx, unit_symbol_formatting fmt, bool negative_power)
|
||||
constexpr Out unit_symbol_impl(Out out, M m, std::size_t Idx, const unit_symbol_formatting& fmt, bool negative_power)
|
||||
{
|
||||
if (Idx > 0) out = print_separator<CharT>(out, fmt);
|
||||
return unit_symbol_impl<CharT>(out, m, fmt, negative_power);
|
||||
@@ -763,14 +767,14 @@ constexpr Out unit_symbol_impl(Out out, M m, std::size_t Idx, unit_symbol_format
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, DerivedUnitExpr... Ms, std::size_t... Idxs>
|
||||
constexpr Out unit_symbol_impl(Out out, const type_list<Ms...>&, std::index_sequence<Idxs...>,
|
||||
unit_symbol_formatting fmt, bool negative_power)
|
||||
const unit_symbol_formatting& fmt, bool negative_power)
|
||||
{
|
||||
return (..., (out = unit_symbol_impl<CharT>(out, Ms{}, Idxs, fmt, negative_power)));
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, DerivedUnitExpr... Nums, DerivedUnitExpr... Dens>
|
||||
constexpr Out unit_symbol_impl(Out out, const type_list<Nums...>& nums, const type_list<Dens...>& dens,
|
||||
unit_symbol_formatting fmt)
|
||||
const unit_symbol_formatting& fmt)
|
||||
{
|
||||
if constexpr (sizeof...(Nums) == 0 && sizeof...(Dens) == 0) {
|
||||
// dimensionless quantity
|
||||
@@ -792,7 +796,7 @@ constexpr Out unit_symbol_impl(Out out, const type_list<Nums...>& nums, const ty
|
||||
}
|
||||
|
||||
if (fmt.solidus == always && sizeof...(Dens) > 1) *out++ = '(';
|
||||
bool negative_power = fmt.solidus == never || (fmt.solidus == one_denominator && sizeof...(Dens) > 1);
|
||||
const bool negative_power = fmt.solidus == never || (fmt.solidus == one_denominator && sizeof...(Dens) > 1);
|
||||
out = unit_symbol_impl<CharT>(out, dens, std::index_sequence_for<Dens...>(), fmt, negative_power);
|
||||
if (fmt.solidus == always && sizeof...(Dens) > 1) *out++ = ')';
|
||||
return out;
|
||||
@@ -800,7 +804,8 @@ constexpr Out unit_symbol_impl(Out out, const type_list<Nums...>& nums, const ty
|
||||
}
|
||||
|
||||
template<typename CharT, std::output_iterator<CharT> Out, typename... Expr>
|
||||
constexpr Out unit_symbol_impl(Out out, const derived_unit<Expr...>&, unit_symbol_formatting fmt, bool negative_power)
|
||||
constexpr Out unit_symbol_impl(Out out, const derived_unit<Expr...>&, const unit_symbol_formatting& fmt,
|
||||
bool negative_power)
|
||||
{
|
||||
gsl_Expects(negative_power == false);
|
||||
return unit_symbol_impl<CharT>(out, typename derived_unit<Expr...>::_num_{}, typename derived_unit<Expr...>::_den_{},
|
||||
@@ -810,7 +815,7 @@ constexpr Out unit_symbol_impl(Out out, const derived_unit<Expr...>&, unit_symbo
|
||||
} // namespace detail
|
||||
|
||||
MP_UNITS_EXPORT template<typename CharT = char, std::output_iterator<CharT> Out, Unit U>
|
||||
constexpr Out unit_symbol_to(Out out, U u, unit_symbol_formatting fmt = unit_symbol_formatting{})
|
||||
constexpr Out unit_symbol_to(Out out, U u, const unit_symbol_formatting& fmt = unit_symbol_formatting{})
|
||||
{
|
||||
return detail::unit_symbol_impl<CharT>(out, u, fmt, false);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ std::vector<typename Q::rep> i_qty_to_rep(InputIt first, InputIt last)
|
||||
{
|
||||
std::vector<typename Q::rep> intervals_rep;
|
||||
intervals_rep.reserve(static_cast<size_t>(std::distance(first, last)));
|
||||
for (auto itr = first; itr != last; ++itr) {
|
||||
for (InputIt itr = first; itr != last; ++itr) {
|
||||
intervals_rep.push_back(itr->numerical_value_ref_in(Q::unit));
|
||||
}
|
||||
return intervals_rep;
|
||||
@@ -106,11 +106,11 @@ struct uniform_int_distribution : public std::uniform_int_distribution<typename
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
[[nodiscard]] Q a() const { return base::a() * Q::reference; }
|
||||
[[nodiscard]] Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -131,11 +131,11 @@ struct uniform_real_distribution : public std::uniform_real_distribution<typenam
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
[[nodiscard]] Q a() const { return base::a() * Q::reference; }
|
||||
[[nodiscard]] Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -153,10 +153,10 @@ struct binomial_distribution : public std::binomial_distribution<typename Q::rep
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q t() const { return base::t() * Q::reference; }
|
||||
[[nodiscard]] Q t() const { return base::t() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -174,10 +174,10 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q k() const { return base::k() * Q::reference; }
|
||||
[[nodiscard]] Q k() const { return base::k() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -187,7 +187,7 @@ struct geometric_distribution : public std::geometric_distribution<typename Q::r
|
||||
using base = MP_UNITS_TYPENAME std::geometric_distribution<rep>;
|
||||
|
||||
geometric_distribution() : base() {}
|
||||
geometric_distribution(double p) : base(p) {}
|
||||
explicit geometric_distribution(double p) : base(p) {}
|
||||
|
||||
template<typename Generator>
|
||||
Q operator()(Generator& g)
|
||||
@@ -195,8 +195,8 @@ struct geometric_distribution : public std::geometric_distribution<typename Q::r
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -214,8 +214,8 @@ struct poisson_distribution : public std::poisson_distribution<typename Q::rep>
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -233,8 +233,8 @@ struct exponential_distribution : public std::exponential_distribution<typename
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -252,8 +252,8 @@ struct gamma_distribution : public std::gamma_distribution<typename Q::rep> {
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -271,8 +271,8 @@ struct weibull_distribution : public std::weibull_distribution<typename Q::rep>
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -290,10 +290,10 @@ struct extreme_value_distribution : public std::extreme_value_distribution<typen
|
||||
return Q(base::operator()(g));
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
[[nodiscard]] Q a() const { return base::a() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -314,11 +314,11 @@ struct normal_distribution : public std::normal_distribution<typename Q::rep> {
|
||||
return Q(base::operator()(g));
|
||||
}
|
||||
|
||||
Q mean() const { return base::mean() * Q::reference; }
|
||||
Q stddev() const { return base::stddev() * Q::reference; }
|
||||
[[nodiscard]] Q mean() const { return base::mean() * Q::reference; }
|
||||
[[nodiscard]] Q stddev() const { return base::stddev() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -339,11 +339,11 @@ struct lognormal_distribution : public std::lognormal_distribution<typename Q::r
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q m() const { return base::m() * Q::reference; }
|
||||
Q s() const { return base::s() * Q::reference; }
|
||||
[[nodiscard]] Q m() const { return base::m() * Q::reference; }
|
||||
[[nodiscard]] Q s() const { return base::s() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -361,8 +361,8 @@ struct chi_squared_distribution : public std::chi_squared_distribution<typename
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -383,11 +383,11 @@ struct cauchy_distribution : public std::cauchy_distribution<typename Q::rep> {
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q a() const { return base::a() * Q::reference; }
|
||||
Q b() const { return base::b() * Q::reference; }
|
||||
[[nodiscard]] Q a() const { return base::a() * Q::reference; }
|
||||
[[nodiscard]] Q b() const { return base::b() * Q::reference; }
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -405,8 +405,8 @@ struct fisher_f_distribution : public std::fisher_f_distribution<typename Q::rep
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -424,8 +424,8 @@ struct student_t_distribution : public std::student_t_distribution<typename Q::r
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -455,8 +455,8 @@ struct discrete_distribution : public std::discrete_distribution<typename Q::rep
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -503,9 +503,9 @@ public:
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
std::vector<Q> intervals() const
|
||||
[[nodiscard]] std::vector<Q> intervals() const
|
||||
{
|
||||
std::vector<rep> intervals_rep = base::intervals();
|
||||
const std::vector<rep> intervals_rep = base::intervals();
|
||||
std::vector<Q> intervals_qty;
|
||||
intervals_qty.reserve(intervals_rep.size());
|
||||
for (const rep& val : intervals_rep) {
|
||||
@@ -514,8 +514,8 @@ public:
|
||||
return intervals_qty;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
template<Quantity Q>
|
||||
@@ -562,9 +562,9 @@ public:
|
||||
return base::operator()(g) * Q::reference;
|
||||
}
|
||||
|
||||
std::vector<Q> intervals() const
|
||||
[[nodiscard]] std::vector<Q> intervals() const
|
||||
{
|
||||
std::vector<rep> intervals_rep = base::intervals();
|
||||
const std::vector<rep> intervals_rep = base::intervals();
|
||||
std::vector<Q> intervals_qty;
|
||||
intervals_qty.reserve(intervals_rep.size());
|
||||
for (const rep& val : intervals_rep) {
|
||||
@@ -573,8 +573,8 @@ public:
|
||||
return intervals_qty;
|
||||
}
|
||||
|
||||
Q min() const { return base::min() * Q::reference; }
|
||||
Q max() const { return base::max() * Q::reference; }
|
||||
[[nodiscard]] Q min() const { return base::min() * Q::reference; }
|
||||
[[nodiscard]] Q max() const { return base::max() * Q::reference; }
|
||||
};
|
||||
|
||||
MP_UNITS_EXPORT_END
|
||||
|
||||
@@ -59,7 +59,7 @@ inline constexpr struct lunar_distance : named_unit<"LD", mag<384'399> * si::kil
|
||||
inline constexpr struct light_year : named_unit<"ly", mag<9'460'730'472'580'800> * si::metre> {} light_year;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Parsec
|
||||
inline constexpr struct parsec : named_unit<"pc", astronomical_unit / (mag_ratio<1, 60 * 60> * si::degree)> {} parsec;
|
||||
inline constexpr struct parsec : named_unit<"pc", astronomical_unit / (mag_ratio<1, 3600> * si::degree)> {} parsec;
|
||||
|
||||
// https://en.wikipedia.org/wiki/Angstrom
|
||||
inline constexpr struct angstrom : named_unit<symbol_text{u8"Å", "A"}, mag_power<10, -10> * si::metre> {} angstrom;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mp_units {
|
||||
namespace detail {
|
||||
|
||||
template<typename Period>
|
||||
[[nodiscard]] inline consteval auto time_unit_from_chrono_period()
|
||||
[[nodiscard]] consteval auto time_unit_from_chrono_period()
|
||||
{
|
||||
using namespace si;
|
||||
|
||||
|
||||
@@ -769,7 +769,7 @@ inline constexpr auto d = day;
|
||||
|
||||
namespace si::unit_symbols {
|
||||
|
||||
using namespace non_si::unit_symbols;
|
||||
using namespace non_si::unit_symbols; // NOLINT(google-build-using-namespace)
|
||||
|
||||
} // namespace si::unit_symbols
|
||||
|
||||
|
||||
Reference in new issue
Block a user