diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index 133a7713a..df2ca9093 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -163,7 +163,8 @@ void print(const aircraft_tow& tow) void example() { - using namespace mp_units::si::unit_symbols; + using mp_units::si::unit_symbols::m; + using mp_units::si::unit_symbols::s; const safety sfty = {300 * m}; const auto gliders = get_gliders(); diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 06114cb03..f49d6f6c3 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -210,8 +210,8 @@ class MP_UNITS_STD_FMT::formatter, Char> { std::array, sizeof...(QPs)> format_str_; std::tuple...> formatters_{}; - template - constexpr const Char* parse_default_spec(const Char* begin, const Char* end, Formatter& f, std::string& format_str) + template + constexpr It parse_default_spec(It begin, It end, Formatter& f, std::string& format_str) { if (begin == end || *begin++ != '[') throw MP_UNITS_STD_FMT::format_error("`default-spec` should contain a `[` character"); @@ -231,9 +231,8 @@ class MP_UNITS_STD_FMT::formatter, Char> { return ++it; // skip `]` } - template - [[nodiscard]] constexpr const Char* parse_default_spec(const Char* begin, const Char* end, size_t idx, - std::index_sequence) + template + [[nodiscard]] constexpr It parse_default_spec(It begin, It end, size_t idx, std::index_sequence) { auto parse = [&](bool flag, auto& f, std::basic_string& str) { return flag ? parse_default_spec(begin, end, f, str) : begin; @@ -241,7 +240,8 @@ class MP_UNITS_STD_FMT::formatter, Char> { return std::max({parse(idx == Is, std::get(formatters_), format_str_[Is])...}); } - [[nodiscard]] constexpr const Char* parse_defaults_specs(const Char* begin, const Char* end) + template + [[nodiscard]] constexpr It parse_defaults_specs(It begin, It end) { if (begin == end || *begin == '}') return begin; if (*begin++ != ':') throw MP_UNITS_STD_FMT::format_error("`defaults-specs` should start with a `:`"); diff --git a/example/total_energy.cpp b/example/total_energy.cpp index d65450873..82419760d 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -48,7 +48,10 @@ QuantityOf auto total_energy(QuantityOf a void si_example() { - using namespace mp_units::si::unit_symbols; + using mp_units::si::unit_symbols::kg; + using mp_units::si::unit_symbols::m; + using mp_units::si::unit_symbols::s; + using mp_units::si::unit_symbols::J; constexpr Unit auto GeV = si::giga; constexpr quantity c = 1. * si::si2019::speed_of_light_in_vacuum; const quantity c2 = pow<2>(c); diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 064e80553..4c5d2276e 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -70,6 +70,7 @@ constexpr const char* to_text(earth_gravity_model m) return "EGM2008-1"; } assert(false && "unsupported enum value"); + return nullptr; } template diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index 92312bb1b..c01fb09f5 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -214,18 +214,18 @@ template { MP_UNITS_EXPECTS(begin != end && '0' <= *begin && *begin <= '9'); unsigned value = 0, prev = 0; - auto p = begin; + auto pos = begin; do { prev = value; - value = value * 10 + unsigned(*p - '0'); - ++p; - } while (p != end && '0' <= *p && *p <= '9'); - auto num_digits = p - begin; - begin = p; + value = value * 10 + unsigned(*pos - '0'); + ++pos; + } while (pos != end && '0' <= *pos && *pos <= '9'); + auto num_digits = pos - begin; + begin = pos; if (num_digits <= std::numeric_limits::digits10) return static_cast(value); // Check for overflow. const unsigned max = ::mp_units::detail::to_unsigned((std::numeric_limits::max)()); - return num_digits == std::numeric_limits::digits10 + 1 && prev * 10ull + unsigned(p[-1] - '0') <= max + return num_digits == std::numeric_limits::digits10 + 1 && prev * 10ull + unsigned(pos[-1] - '0') <= max ? static_cast(value) : error_value; } @@ -239,11 +239,11 @@ template template [[nodiscard]] constexpr const It do_parse_arg_id(It begin, It end, Handler& handler) { - auto c = *begin; - if (c >= '0' && c <= '9') { + auto ch = *begin; + if (ch >= '0' && ch <= '9') { int index = 0; constexpr int max = (std::numeric_limits::max)(); - if (c != '0') + if (ch != '0') index = ::mp_units::detail::parse_nonnegative_int(begin, end, max); else ++begin; @@ -252,8 +252,8 @@ template handler.on_index(index); return begin; } - if (c == '%') return begin; // mp-units extension - if (!::mp_units::detail::is_name_start(c)) { + if (ch == '%') return begin; // mp-units extension + if (!::mp_units::detail::is_name_start(ch)) { MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string")); } auto it = begin; @@ -273,8 +273,8 @@ template [[nodiscard]] constexpr It parse_arg_id(It begin, It end, Handler& handler) { MP_UNITS_EXPECTS(begin != end); - auto c = *begin; - if (c != '}' && c != ':') return ::mp_units::detail::do_parse_arg_id(begin, end, handler); + auto ch = *begin; + if (ch != '}' && ch != ':') return ::mp_units::detail::do_parse_arg_id(begin, end, handler); handler.on_auto(); return begin; } @@ -351,10 +351,10 @@ template { MP_UNITS_EXPECTS(begin != end); auto align = fmt_align::none; - auto p = begin + code_point_length(begin); - if (end - p <= 0) p = begin; + auto pos = begin + code_point_length(begin); + if (end - pos <= 0) pos = begin; for (;;) { - switch (to_ascii(*p)) { + switch (to_ascii(*pos)) { case '<': align = fmt_align::left; break; @@ -366,19 +366,19 @@ template break; } if (align != fmt_align::none) { - if (p != begin) { - auto c = *begin; - if (c == '}') return begin; - if (c == '{') MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill character '{'")); - specs.fill = {begin, p}; - begin = p + 1; + if (pos != begin) { + auto ch = *begin; + if (ch == '}') return begin; + if (ch == '{') MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill character '{'")); + specs.fill = {begin, pos}; + begin = pos + 1; } else { ++begin; } break; } - if (p == begin) break; - p = begin; + if (pos == begin) break; + pos = begin; } if (align == fmt_align::none) align = default_align; // mp-units extension specs.align = align; diff --git a/src/core/include/mp-units/ext/fixed_string.h b/src/core/include/mp-units/ext/fixed_string.h index f2155a060..050a2bacf 100644 --- a/src/core/include/mp-units/ext/fixed_string.h +++ b/src/core/include/mp-units/ext/fixed_string.h @@ -173,8 +173,8 @@ public: { CharT txt[N + N2]; CharT* it = txt; - for (CharT c : lhs) *it++ = c; - for (CharT c : rhs) *it++ = c; + for (CharT ch : lhs) *it++ = ch; + for (CharT ch : rhs) *it++ = ch; return basic_fixed_string(txt, it); } @@ -183,7 +183,7 @@ public: { CharT txt[N + 1]; CharT* it = txt; - for (CharT c : lhs) *it++ = c; + for (CharT ch : lhs) *it++ = ch; *it++ = rhs; return basic_fixed_string(txt, it); } @@ -194,7 +194,7 @@ public: CharT txt[1 + N]; CharT* it = txt; *it++ = lhs; - for (CharT c : rhs) *it++ = c; + for (CharT ch : rhs) *it++ = ch; return basic_fixed_string(txt, it); } @@ -205,8 +205,8 @@ public: MP_UNITS_EXPECTS(rhs[N2 - 1] == CharT{}); CharT txt[N + N2]; CharT* it = txt; - for (CharT c : lhs) *it++ = c; - for (CharT c : rhs) *it++ = c; + for (CharT ch : lhs) *it++ = ch; + for (CharT ch : rhs) *it++ = ch; return txt; } @@ -218,7 +218,7 @@ public: CharT txt[N1 + N]; CharT* it = txt; for (std::size_t i = 0; i != N1 - 1; ++i) *it++ = lhs[i]; - for (CharT c : rhs) *it++ = c; + for (CharT ch : rhs) *it++ = ch; *it++ = CharT(); return txt; } diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 379a0cdef..fec9e0a31 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -870,9 +870,9 @@ class MP_UNITS_STD_FMT::formatter, Char> { "`quantity-specs` should start with a `conversion-spec` ('%' characters expected)"); auto ptr = begin; while (ptr != end) { - auto c = *ptr; - if (c == '}') break; - if (c == ':') { + auto ch = *ptr; + if (ch == '}') break; + if (ch == ':') { if (ptr + 1 != end && *(ptr + 1) == ':') { handler.on_text(begin, ++ptr); // account for ':' ++ptr; // consume the second ':' @@ -881,7 +881,7 @@ class MP_UNITS_STD_FMT::formatter, Char> { // default specs started break; } - if (c != '%') { + if (ch != '%') { ++ptr; continue; } @@ -889,8 +889,8 @@ class MP_UNITS_STD_FMT::formatter, Char> { ++ptr; // consume '%' if (ptr == end) throw MP_UNITS_STD_FMT::format_error("invalid `conversion-spec` format"); - c = *ptr++; - switch (c) { + ch = *ptr++; + switch (ch) { case 'N': handler.on_number(); break; @@ -907,7 +907,7 @@ class MP_UNITS_STD_FMT::formatter, Char> { handler.on_text(ptr - 1, ptr); break; default: - throw MP_UNITS_STD_FMT::format_error(std::string("unknown `placement-type` token '") + c + "'"); + throw MP_UNITS_STD_FMT::format_error(std::string("unknown `placement-type` token '") + ch + "'"); } begin = ptr; } @@ -942,9 +942,9 @@ class MP_UNITS_STD_FMT::formatter, Char> { if (begin == end || *begin == '}') return begin; if (*begin++ != ':') throw MP_UNITS_STD_FMT::format_error("`defaults-specs` should start with a `:`"); do { - auto c = *begin++; + auto ch = *begin++; // TODO check if not repeated - switch (c) { + switch (ch) { case 'N': begin = parse_default_spec(begin, end, rep_formatter_, rep_format_str_); break; @@ -955,7 +955,7 @@ class MP_UNITS_STD_FMT::formatter, Char> { begin = parse_default_spec(begin, end, dimension_formatter_, dimension_format_str_); break; default: - throw MP_UNITS_STD_FMT::format_error(std::string("unknown `subentity-id` token '") + c + "'"); + throw MP_UNITS_STD_FMT::format_error(std::string("unknown `subentity-id` token '") + ch + "'"); } } while (begin != end && *begin != '}'); return begin; diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 81b433770..166385e5f 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1224,7 +1224,7 @@ template // if quantities can't be converted in any direction check if they have a common base in the tree else if constexpr (detail::have_common_base(Q1{}, Q2{})) { constexpr auto base = detail::get_common_base(Q1{}, Q2{}); - if constexpr (mp_units::implicitly_convertible(q1, base) && mp_units::implicitly_convertible(q2, base)) + if constexpr (mp_units::implicitly_convertible(Q1{}, base) && mp_units::implicitly_convertible(Q2{}, base)) return base; else return no_common_quantity_spec{}; diff --git a/src/core/include/mp-units/framework/value_cast.h b/src/core/include/mp-units/framework/value_cast.h index 6a975cdfc..f342d664b 100644 --- a/src/core/include/mp-units/framework/value_cast.h +++ b/src/core/include/mp-units/framework/value_cast.h @@ -46,7 +46,7 @@ template else if constexpr (std::totally_ordered_with && requires(Rep v) { representation_values::max(); }) { constexpr auto factor = - get_value(numerator(get_canonical_unit(from).mag / get_canonical_unit(to).mag)); + get_value(numerator(get_canonical_unit(UFrom{}).mag / get_canonical_unit(UTo{}).mag)); if constexpr (std::is_integral_v) return !std::in_range(factor); else