refactor: All the macros refactored to have MP_UNITS_ prefix
This commit is contained in:
1 parent
d9d9d9d3b7
commit
ba1f58af76
41 files changed
+609
-558
No files matched your search
+1
-1
@@ -23,7 +23,7 @@
|
||||
cmake_minimum_required(VERSION 3.19)
|
||||
project(mp-units VERSION 2.0.0 LANGUAGES CXX)
|
||||
|
||||
set(projectPrefix UNITS_)
|
||||
set(projectPrefix MP_UNITS_)
|
||||
|
||||
option(${projectPrefix}AS_SYSTEM_HEADERS "Exports library as system headers" OFF)
|
||||
message(STATUS "${projectPrefix}AS_SYSTEM_HEADERS: ${${projectPrefix}AS_SYSTEM_HEADERS}")
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
constexpr fill_t& operator=(std::basic_string_view<Char> str)
|
||||
{
|
||||
auto size = str.size();
|
||||
if (size > max_size) UNITS_THROW(UNITS_STD_FMT::format_error("invalid fill"));
|
||||
if (size > max_size) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill"));
|
||||
for (size_t i = 0; i < size; ++i) data_[i] = str[i];
|
||||
size_ = static_cast<unsigned char>(size);
|
||||
return *this;
|
||||
@@ -98,11 +98,11 @@ struct width_checker {
|
||||
{
|
||||
if constexpr (is_integer<T>) {
|
||||
if constexpr (std::numeric_limits<T>::is_signed) {
|
||||
if (value < 0) UNITS_THROW(UNITS_STD_FMT::format_error("negative width"));
|
||||
if (value < 0) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("negative width"));
|
||||
}
|
||||
return static_cast<unsigned long long>(value);
|
||||
} else {
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("width is not integer"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer"));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -113,11 +113,11 @@ struct precision_checker {
|
||||
{
|
||||
if constexpr (is_integer<T>) {
|
||||
if constexpr (std::numeric_limits<T>::is_signed) {
|
||||
if (value < 0) UNITS_THROW(UNITS_STD_FMT::format_error("negative precision"));
|
||||
if (value < 0) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("negative precision"));
|
||||
}
|
||||
return static_cast<unsigned long long>(value);
|
||||
} else {
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("precision is not integer"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("precision is not integer"));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -147,31 +147,31 @@ struct dynamic_format_specs : basic_format_specs<Char> {
|
||||
[[nodiscard]] constexpr int verify_dynamic_arg_index_in_range(size_t idx)
|
||||
{
|
||||
if (idx > static_cast<size_t>(std::numeric_limits<int>::max())) {
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("Dynamic width or precision index too large."));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("Dynamic width or precision index too large."));
|
||||
}
|
||||
return static_cast<int>(idx);
|
||||
}
|
||||
|
||||
template<typename CharT>
|
||||
[[nodiscard]] constexpr int on_dynamic_arg(size_t arg_id, UNITS_STD_FMT::basic_format_parse_context<CharT>& context)
|
||||
[[nodiscard]] constexpr int on_dynamic_arg(size_t arg_id, MP_UNITS_STD_FMT::basic_format_parse_context<CharT>& context)
|
||||
{
|
||||
context.check_arg_id(UNITS_FMT_TO_ARG_ID(arg_id));
|
||||
context.check_arg_id(MP_UNITS_FMT_TO_ARG_ID(arg_id));
|
||||
return verify_dynamic_arg_index_in_range(arg_id);
|
||||
}
|
||||
|
||||
template<typename CharT>
|
||||
[[nodiscard]] constexpr int on_dynamic_arg(auto_id, UNITS_STD_FMT::basic_format_parse_context<CharT>& context)
|
||||
[[nodiscard]] constexpr int on_dynamic_arg(auto_id, MP_UNITS_STD_FMT::basic_format_parse_context<CharT>& context)
|
||||
{
|
||||
return verify_dynamic_arg_index_in_range(UNITS_FMT_FROM_ARG_ID(context.next_arg_id()));
|
||||
return verify_dynamic_arg_index_in_range(MP_UNITS_FMT_FROM_ARG_ID(context.next_arg_id()));
|
||||
}
|
||||
|
||||
template<class Handler, typename FormatContext>
|
||||
[[nodiscard]] constexpr int get_dynamic_spec(int index, FormatContext& ctx)
|
||||
{
|
||||
const unsigned long long value =
|
||||
UNITS_STD_FMT::visit_format_arg(Handler{}, ctx.arg(UNITS_FMT_TO_ARG_ID(static_cast<size_t>(index))));
|
||||
MP_UNITS_STD_FMT::visit_format_arg(Handler{}, ctx.arg(MP_UNITS_FMT_TO_ARG_ID(static_cast<size_t>(index))));
|
||||
if (value > static_cast<unsigned long long>(std::numeric_limits<int>::max())) {
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("number is too big"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("number is too big"));
|
||||
}
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
@@ -195,7 +195,7 @@ template<std::input_iterator It, std::sentinel_for<It> S>
|
||||
++begin;
|
||||
} while (begin != end && '0' <= *begin && *begin <= '9');
|
||||
|
||||
if (value > max_int) UNITS_THROW(UNITS_STD_FMT::format_error("Number is too big"));
|
||||
if (value > max_int) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("Number is too big"));
|
||||
|
||||
return begin;
|
||||
}
|
||||
@@ -222,12 +222,12 @@ template<std::input_iterator It, std::sentinel_for<It> S, typename IDHandler>
|
||||
else
|
||||
++begin;
|
||||
if (begin == end || (*begin != '}' && *begin != ':'))
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("invalid format string"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
|
||||
else
|
||||
handler(index);
|
||||
return begin;
|
||||
}
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("invalid format string"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
|
||||
}
|
||||
|
||||
template<std::input_iterator It, std::sentinel_for<It> S, typename IDHandler>
|
||||
@@ -278,11 +278,11 @@ template<std::input_iterator It, std::sentinel_for<It> S, typename Handler>
|
||||
if (width != -1)
|
||||
handler.on_width(width);
|
||||
else
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("number is too big"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("number is too big"));
|
||||
} else if (*begin == '{') {
|
||||
++begin;
|
||||
if (begin != end) begin = parse_arg_id(begin, end, width_adapter{handler});
|
||||
if (begin == end || *begin != '}') UNITS_THROW(UNITS_STD_FMT::format_error("invalid format string"));
|
||||
if (begin == end || *begin != '}') MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
|
||||
++begin;
|
||||
}
|
||||
return begin;
|
||||
@@ -305,13 +305,13 @@ template<std::input_iterator It, std::sentinel_for<It> S, typename Handler>
|
||||
if (precision != -1)
|
||||
handler.on_precision(precision);
|
||||
else
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("number is too big"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("number is too big"));
|
||||
} else if (c == '{') {
|
||||
++begin;
|
||||
if (begin != end) begin = parse_arg_id(begin, end, precision_adapter{handler});
|
||||
if (begin == end || *begin++ != '}') UNITS_THROW(UNITS_STD_FMT::format_error("invalid format string"));
|
||||
if (begin == end || *begin++ != '}') MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string"));
|
||||
} else {
|
||||
UNITS_THROW(UNITS_STD_FMT::format_error("missing precision specifier"));
|
||||
MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("missing precision specifier"));
|
||||
}
|
||||
return begin;
|
||||
}
|
||||
@@ -355,7 +355,7 @@ template<std::input_iterator It, std::sentinel_for<It> S, typename Handler>
|
||||
if (align != fmt_align::none) {
|
||||
if (p != begin) {
|
||||
auto c = *begin;
|
||||
if (c == '{') UNITS_THROW(UNITS_STD_FMT::format_error("invalid fill character '{'"));
|
||||
if (c == '{') MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill character '{'"));
|
||||
handler.on_fill(std::basic_string_view<std::iter_value_t<It>>(&*begin, static_cast<size_t>(p - begin)));
|
||||
begin = p + 1;
|
||||
} else
|
||||
|
||||
@@ -29,32 +29,32 @@
|
||||
|
||||
#include <mp-units/bits/external/hacks.h>
|
||||
|
||||
#ifndef UNITS_USE_LIBFMT
|
||||
#define UNITS_USE_LIBFMT 1
|
||||
#ifndef MP_UNITS_USE_LIBFMT
|
||||
#define MP_UNITS_USE_LIBFMT 1
|
||||
#endif
|
||||
|
||||
#if UNITS_USE_LIBFMT
|
||||
#if MP_UNITS_USE_LIBFMT
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
MP_UNITS_DIAGNOSTIC_PUSH
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
#include <fmt/format.h>
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
|
||||
#define UNITS_STD_FMT fmt
|
||||
#define UNITS_FMT_LOCALE(loc) (loc).template get<std::locale>()
|
||||
#define UNITS_FMT_TO_ARG_ID(arg) static_cast<int>(arg)
|
||||
#define UNITS_FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
|
||||
#define MP_UNITS_STD_FMT fmt
|
||||
#define MP_UNITS_FMT_LOCALE(loc) (loc).template get<std::locale>()
|
||||
#define MP_UNITS_FMT_TO_ARG_ID(arg) static_cast<int>(arg)
|
||||
#define MP_UNITS_FMT_FROM_ARG_ID(arg) static_cast<size_t>(arg)
|
||||
|
||||
// This re-uses code from fmt;
|
||||
#if FMT_EXCEPTIONS
|
||||
#if FMT_MSC_VERSION || defined(__NVCC__)
|
||||
#define UNITS_THROW(x) ::fmt::detail::do_throw(x)
|
||||
#define MP_UNITS_THROW(x) ::fmt::detail::do_throw(x)
|
||||
#else
|
||||
#define UNITS_THROW(x) throw x
|
||||
#define MP_UNITS_THROW(x) throw x
|
||||
#endif
|
||||
#else
|
||||
#define UNITS_THROW(x) \
|
||||
#define MP_UNITS_THROW(x) \
|
||||
do { \
|
||||
FMT_ASSERT(false, (x).what()); \
|
||||
} while (false)
|
||||
@@ -68,10 +68,10 @@ UNITS_DIAGNOSTIC_POP
|
||||
|
||||
#include <format>
|
||||
|
||||
#define UNITS_STD_FMT std
|
||||
#define UNITS_FMT_LOCALE(loc) loc
|
||||
#define UNITS_FMT_TO_ARG_ID(arg) arg
|
||||
#define UNITS_FMT_FROM_ARG_ID(arg) arg
|
||||
#define UNITS_THROW(arg) throw arg
|
||||
#define MP_UNITS_STD_FMT std
|
||||
#define MP_UNITS_FMT_LOCALE(loc) loc
|
||||
#define MP_UNITS_FMT_TO_ARG_ID(arg) arg
|
||||
#define MP_UNITS_FMT_FROM_ARG_ID(arg) arg
|
||||
#define MP_UNITS_THROW(arg) throw arg
|
||||
|
||||
#endif
|
||||
@@ -96,7 +96,7 @@ constexpr It parse_units_rep(It begin, S end, Handler&& handler, bool treat_as_f
|
||||
if (treat_as_floating_point) {
|
||||
begin = parse_precision(begin, end, handler);
|
||||
} else
|
||||
throw UNITS_STD_FMT::format_error("precision not allowed for integral quantity representation");
|
||||
throw MP_UNITS_STD_FMT::format_error("precision not allowed for integral quantity representation");
|
||||
if (begin == end) return begin;
|
||||
}
|
||||
|
||||
@@ -126,12 +126,12 @@ constexpr It parse_units_format(It begin, S end, Handler&& handler)
|
||||
}
|
||||
if (begin != ptr) handler.on_text(begin, ptr);
|
||||
begin = ++ptr; // consume '%'
|
||||
if (ptr == end) throw UNITS_STD_FMT::format_error("invalid format");
|
||||
if (ptr == end) throw MP_UNITS_STD_FMT::format_error("invalid format");
|
||||
c = *ptr++;
|
||||
|
||||
constexpr auto units_types = std::string_view{"Qq"};
|
||||
const auto new_end = find_first_of(begin, end, units_types.begin(), units_types.end());
|
||||
if (new_end == end) throw UNITS_STD_FMT::format_error("invalid format");
|
||||
if (new_end == end) throw MP_UNITS_STD_FMT::format_error("invalid format");
|
||||
if (*new_end == 'Q') {
|
||||
handler.on_quantity_value(begin, new_end); // Edit `on_quantity_value` to add rep modifiers
|
||||
} else {
|
||||
@@ -152,43 +152,43 @@ template<typename CharT, typename Rep, typename OutputIt, typename Locale>
|
||||
std::basic_string<CharT> buffer;
|
||||
auto to_buffer = std::back_inserter(buffer);
|
||||
|
||||
UNITS_STD_FMT::format_to(to_buffer, "{{:");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "{{:");
|
||||
switch (rep_specs.sign) {
|
||||
case fmt_sign::none:
|
||||
break;
|
||||
case fmt_sign::plus:
|
||||
UNITS_STD_FMT::format_to(to_buffer, "+");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "+");
|
||||
break;
|
||||
case fmt_sign::minus:
|
||||
UNITS_STD_FMT::format_to(to_buffer, "-");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "-");
|
||||
break;
|
||||
case fmt_sign::space:
|
||||
UNITS_STD_FMT::format_to(to_buffer, " ");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, " ");
|
||||
break;
|
||||
}
|
||||
|
||||
if (rep_specs.alt) {
|
||||
UNITS_STD_FMT::format_to(to_buffer, "#");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "#");
|
||||
}
|
||||
auto type = rep_specs.type;
|
||||
if (auto precision = rep_specs.precision; precision >= 0) {
|
||||
UNITS_STD_FMT::format_to(to_buffer, ".{}{}", precision, type == '\0' ? 'f' : type);
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, ".{}{}", precision, type == '\0' ? 'f' : type);
|
||||
} else if constexpr (treat_as_floating_point<Rep>) {
|
||||
UNITS_STD_FMT::format_to(to_buffer, "{}", type == '\0' ? 'g' : type);
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "{}", type == '\0' ? 'g' : type);
|
||||
} else {
|
||||
if (type != '\0') {
|
||||
UNITS_STD_FMT::format_to(to_buffer, "{}", type);
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "{}", type);
|
||||
}
|
||||
}
|
||||
if (rep_specs.localized) {
|
||||
UNITS_STD_FMT::format_to(to_buffer, "L");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "L");
|
||||
}
|
||||
|
||||
UNITS_STD_FMT::format_to(to_buffer, "}}");
|
||||
MP_UNITS_STD_FMT::format_to(to_buffer, "}}");
|
||||
if (rep_specs.localized) {
|
||||
return UNITS_STD_FMT::vformat_to(out, UNITS_FMT_LOCALE(loc), buffer, UNITS_STD_FMT::make_format_args(val));
|
||||
return MP_UNITS_STD_FMT::vformat_to(out, MP_UNITS_FMT_LOCALE(loc), buffer, MP_UNITS_STD_FMT::make_format_args(val));
|
||||
}
|
||||
return UNITS_STD_FMT::vformat_to(out, buffer, UNITS_STD_FMT::make_format_args(val));
|
||||
return MP_UNITS_STD_FMT::vformat_to(out, buffer, MP_UNITS_STD_FMT::make_format_args(val));
|
||||
}
|
||||
|
||||
// Creates a global format string
|
||||
@@ -196,25 +196,25 @@ template<typename CharT, typename Rep, typename OutputIt, typename Locale>
|
||||
template<typename CharT, typename OutputIt>
|
||||
OutputIt format_global_buffer(OutputIt out, const quantity_global_format_specs<CharT>& specs)
|
||||
{
|
||||
UNITS_STD_FMT::format_to(out, "{{:");
|
||||
MP_UNITS_STD_FMT::format_to(out, "{{:");
|
||||
if (specs.fill.size() != 1 || specs.fill[0] != ' ') {
|
||||
UNITS_STD_FMT::format_to(out, "{}", specs.fill.data());
|
||||
MP_UNITS_STD_FMT::format_to(out, "{}", specs.fill.data());
|
||||
}
|
||||
switch (specs.align) {
|
||||
case fmt_align::left:
|
||||
UNITS_STD_FMT::format_to(out, "<");
|
||||
MP_UNITS_STD_FMT::format_to(out, "<");
|
||||
break;
|
||||
case fmt_align::right:
|
||||
UNITS_STD_FMT::format_to(out, ">");
|
||||
MP_UNITS_STD_FMT::format_to(out, ">");
|
||||
break;
|
||||
case fmt_align::center:
|
||||
UNITS_STD_FMT::format_to(out, "^");
|
||||
MP_UNITS_STD_FMT::format_to(out, "^");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (specs.width >= 1) UNITS_STD_FMT::format_to(out, "{}", specs.width);
|
||||
return UNITS_STD_FMT::format_to(out, "}}");
|
||||
if (specs.width >= 1) MP_UNITS_STD_FMT::format_to(out, "{}", specs.width);
|
||||
return MP_UNITS_STD_FMT::format_to(out, "}}");
|
||||
}
|
||||
|
||||
template<auto Reference, typename Rep, typename Locale, typename CharT, typename OutputIt>
|
||||
@@ -254,18 +254,18 @@ template<std::input_iterator It, std::sentinel_for<It> S>
|
||||
{
|
||||
auto 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 UNITS_STD_FMT::format_error("only one of '" + std::string(modifiers) +
|
||||
"' unit modifiers may be used in the format spec");
|
||||
throw MP_UNITS_STD_FMT::format_error("only one of '" + std::string(modifiers) +
|
||||
"' unit modifiers may be used in the format spec");
|
||||
return it;
|
||||
}
|
||||
|
||||
} // namespace mp_units::detail
|
||||
|
||||
template<auto Reference, typename Rep, typename CharT>
|
||||
struct UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, CharT> {
|
||||
struct MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, CharT> {
|
||||
private:
|
||||
using quantity = mp_units::quantity<Reference, Rep>;
|
||||
using iterator = TYPENAME UNITS_STD_FMT::basic_format_parse_context<CharT>::iterator;
|
||||
using iterator = TYPENAME MP_UNITS_STD_FMT::basic_format_parse_context<CharT>::iterator;
|
||||
|
||||
bool quantity_value = false;
|
||||
bool quantity_unit = false;
|
||||
@@ -274,7 +274,7 @@ private:
|
||||
|
||||
struct spec_handler {
|
||||
formatter& f;
|
||||
UNITS_STD_FMT::basic_format_parse_context<CharT>& context;
|
||||
MP_UNITS_STD_FMT::basic_format_parse_context<CharT>& context;
|
||||
|
||||
constexpr void on_fill(std::basic_string_view<CharT> fill) { f.specs.global.fill = fill; }
|
||||
constexpr void on_align(mp_units::detail::fmt_align align) { f.specs.global.align = align; }
|
||||
@@ -290,7 +290,7 @@ private:
|
||||
if (valid_rep_types.find(type) != std::string_view::npos) {
|
||||
f.specs.rep.type = type;
|
||||
} else {
|
||||
throw UNITS_STD_FMT::format_error("invalid quantity type specifier");
|
||||
throw MP_UNITS_STD_FMT::format_error("invalid quantity type specifier");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ private:
|
||||
constexpr auto valid_modifiers = std::string_view{"UAoansd"};
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
if (valid_modifiers.find(*it) == std::string_view::npos)
|
||||
throw UNITS_STD_FMT::format_error("invalid unit modifier specified");
|
||||
throw MP_UNITS_STD_FMT::format_error("invalid unit modifier specified");
|
||||
}
|
||||
|
||||
if (auto it = mp_units::detail::at_most_one_of(begin, end, "UA"); it != end) {
|
||||
@@ -350,7 +350,7 @@ private:
|
||||
f.specs.unit.separator = mp_units::unit_symbol_separator::space;
|
||||
else {
|
||||
if (f.specs.unit.encoding == mp_units::text_encoding::ascii)
|
||||
throw UNITS_STD_FMT::format_error("half_high_dot unit separator allowed only for Unicode encoding");
|
||||
throw MP_UNITS_STD_FMT::format_error("half_high_dot unit separator allowed only for Unicode encoding");
|
||||
f.specs.unit.separator = mp_units::unit_symbol_separator::half_high_dot;
|
||||
}
|
||||
}
|
||||
@@ -359,7 +359,8 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] constexpr std::pair<iterator, iterator> do_parse(UNITS_STD_FMT::basic_format_parse_context<CharT>& ctx)
|
||||
[[nodiscard]] constexpr std::pair<iterator, iterator> do_parse(
|
||||
MP_UNITS_STD_FMT::basic_format_parse_context<CharT>& ctx)
|
||||
{
|
||||
auto begin = ctx.begin();
|
||||
auto end = ctx.end();
|
||||
@@ -409,7 +410,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] constexpr auto parse(UNITS_STD_FMT::basic_format_parse_context<CharT>& ctx)
|
||||
[[nodiscard]] constexpr auto parse(MP_UNITS_STD_FMT::basic_format_parse_context<CharT>& ctx)
|
||||
{
|
||||
auto range = do_parse(ctx);
|
||||
if (range.first != range.second)
|
||||
@@ -446,9 +447,9 @@ public:
|
||||
mp_units::detail::format_global_buffer<CharT>(std::back_inserter(global_format_buffer), specs.global);
|
||||
|
||||
// Format the `quantity buffer` using specs from `global_format_buffer`
|
||||
// In the example, equivalent to UNITS_STD_FMT::format("{:*^10}", "1.2_m")
|
||||
return UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
UNITS_STD_FMT::make_format_args(quantity_buffer));
|
||||
// In the example, equivalent to MP_UNITS_STD_FMT::format("{:*^10}", "1.2_m")
|
||||
return MP_UNITS_STD_FMT::vformat_to(ctx.out(), global_format_buffer,
|
||||
MP_UNITS_STD_FMT::make_format_args(quantity_buffer));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -95,11 +95,11 @@ constexpr auto lexicographical_compare_three_way(I1 f1, I1 l1, I2 f2, I2 l2, Cmp
|
||||
|
||||
bool exhaust1 = (f1 == l1);
|
||||
bool exhaust2 = (f2 == l2);
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
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;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
|
||||
return !exhaust1 ? std::strong_ordering::greater
|
||||
: !exhaust2 ? std::strong_ordering::less
|
||||
|
||||
+53
-52
@@ -25,57 +25,58 @@
|
||||
#include <version>
|
||||
|
||||
#if __clang__
|
||||
#define UNITS_COMP_CLANG __clang_major__
|
||||
#define MP_UNITS_COMP_CLANG __clang_major__
|
||||
#elif __GNUC__
|
||||
#define UNITS_COMP_GCC __GNUC__
|
||||
#define UNITS_COMP_GCC_MINOR __GNUC_MINOR__
|
||||
#define MP_UNITS_COMP_GCC __GNUC__
|
||||
#define MP_UNITS_COMP_GCC_MINOR __GNUC_MINOR__
|
||||
#elif _MSC_VER
|
||||
#define UNITS_COMP_MSVC _MSC_VER
|
||||
#define MP_UNITS_COMP_MSVC _MSC_VER
|
||||
#endif
|
||||
|
||||
// Adapted from https://github.com/ericniebler/range-v3/blob/master/include/range/v3/detail/config.hpp#L185.
|
||||
#define UNITS_PRAGMA(X) _Pragma(#X)
|
||||
#if !UNITS_COMP_MSVC
|
||||
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(GCC diagnostic push)
|
||||
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(GCC diagnostic pop)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE(X) \
|
||||
UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \
|
||||
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \
|
||||
UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
|
||||
UNITS_PRAGMA(GCC diagnostic ignored X)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL UNITS_DIAGNOSTIC_IGNORE("-Wfloat-equal")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT UNITS_DIAGNOSTIC_IGNORE("-Wzero-as-nullpointer-constant")
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_DEPRECATED UNITS_DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
|
||||
#define MP_UNITS_PRAGMA(X) _Pragma(#X)
|
||||
#if !MP_UNITS_COMP_MSVC
|
||||
#define MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_PRAGMA(GCC diagnostic push)
|
||||
#define MP_UNITS_DIAGNOSTIC_POP MP_UNITS_PRAGMA(GCC diagnostic pop)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wpragmas")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE(X) \
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored "-Wunknown-warning-option") \
|
||||
MP_UNITS_PRAGMA(GCC diagnostic ignored X)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL MP_UNITS_DIAGNOSTIC_IGNORE("-Wfloat-equal")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES MP_UNITS_DIAGNOSTIC_IGNORE("-Wmissing-braces")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND MP_UNITS_DIAGNOSTIC_IGNORE("-Wnon-template-friend")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW MP_UNITS_DIAGNOSTIC_IGNORE("-Wshadow")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT \
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE("-Wzero-as-nullpointer-constant")
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED MP_UNITS_DIAGNOSTIC_IGNORE("-Wdeprecated-declarations")
|
||||
#else
|
||||
#define UNITS_DIAGNOSTIC_PUSH UNITS_PRAGMA(warning(push))
|
||||
#define UNITS_DIAGNOSTIC_POP UNITS_PRAGMA(warning(pop))
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : 4068))
|
||||
#define UNITS_DIAGNOSTIC_IGNORE(X) UNITS_DIAGNOSTIC_IGNORE_PRAGMAS UNITS_PRAGMA(warning(disable : X))
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF UNITS_DIAGNOSTIC_IGNORE(4296)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA UNITS_DIAGNOSTIC_IGNORE(4244)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_SHADOW UNITS_DIAGNOSTIC_IGNORE(4459)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE(4702)
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
#define UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
|
||||
#define MP_UNITS_DIAGNOSTIC_PUSH MP_UNITS_PRAGMA(warning(push))
|
||||
#define MP_UNITS_DIAGNOSTIC_POP MP_UNITS_PRAGMA(warning(pop))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(warning(disable : 4068))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE(X) MP_UNITS_DIAGNOSTIC_IGNORE_PRAGMAS MP_UNITS_PRAGMA(warning(disable : X))
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF MP_UNITS_DIAGNOSTIC_IGNORE(4296)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_LOSS_OF_DATA MP_UNITS_DIAGNOSTIC_IGNORE(4244)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_NON_TEMPLATE_FRIEND
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_SHADOW MP_UNITS_DIAGNOSTIC_IGNORE(4459)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE MP_UNITS_DIAGNOSTIC_IGNORE(4702)
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
#define MP_UNITS_DIAGNOSTIC_IGNORE_DEPRECATED
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_VERSION
|
||||
#define UNITS_LIBCXX _LIBCPP_VERSION
|
||||
#define MP_UNITS_LIBCXX _LIBCPP_VERSION
|
||||
#endif
|
||||
|
||||
#if UNITS_LIBCXX
|
||||
#if MP_UNITS_LIBCXX
|
||||
|
||||
#if UNITS_LIBCXX < 13000
|
||||
#if MP_UNITS_LIBCXX < 13000
|
||||
|
||||
#include <concepts/concepts.hpp>
|
||||
#include <range/v3/algorithm/lower_bound.hpp>
|
||||
@@ -85,7 +86,7 @@
|
||||
#include <range/v3/iterator/concepts.hpp>
|
||||
#include <range/v3/range/concepts.hpp>
|
||||
|
||||
#elif UNITS_LIBCXX < 14000
|
||||
#elif MP_UNITS_LIBCXX < 14000
|
||||
|
||||
#include <range/v3/functional/comparisons.hpp>
|
||||
|
||||
@@ -96,7 +97,7 @@
|
||||
#include <compare>
|
||||
#include <concepts>
|
||||
|
||||
#if UNITS_COMP_MSVC || (UNITS_COMP_CLANG && UNITS_COMP_CLANG < 16)
|
||||
#if MP_UNITS_COMP_MSVC || (MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 16)
|
||||
|
||||
#define TYPENAME typename
|
||||
|
||||
@@ -106,7 +107,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
#define CONSTEVAL constexpr
|
||||
|
||||
@@ -116,37 +117,37 @@
|
||||
|
||||
#endif
|
||||
|
||||
#if UNITS_COMP_MSVC
|
||||
#if MP_UNITS_COMP_MSVC
|
||||
|
||||
#define UNITS_CONSTRAINED_AUTO_WORKAROUND(X)
|
||||
#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X)
|
||||
|
||||
#else
|
||||
|
||||
#define UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X
|
||||
#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X
|
||||
|
||||
#endif
|
||||
|
||||
#if UNITS_COMP_MSVC || (UNITS_COMP_GCC && UNITS_COMP_GCC < 11)
|
||||
#if MP_UNITS_COMP_MSVC || (MP_UNITS_COMP_GCC && MP_UNITS_COMP_GCC < 11)
|
||||
|
||||
#define UNITS_CONSTRAINED_NTTP_WORKAROUND(X)
|
||||
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X)
|
||||
|
||||
#else
|
||||
|
||||
#define UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
|
||||
#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
namespace std {
|
||||
|
||||
#if UNITS_COMP_GCC
|
||||
#if MP_UNITS_COMP_GCC
|
||||
|
||||
template<class T>
|
||||
concept default_constructible = constructible_from<T>;
|
||||
|
||||
#elif UNITS_LIBCXX
|
||||
#elif MP_UNITS_LIBCXX
|
||||
|
||||
#if UNITS_LIBCXX < 13000
|
||||
#if MP_UNITS_LIBCXX < 13000
|
||||
|
||||
// concepts
|
||||
using concepts::common_with;
|
||||
@@ -254,7 +255,7 @@ constexpr bool in_range(T t) noexcept
|
||||
std::cmp_less_equal(t, std::numeric_limits<R>::max());
|
||||
}
|
||||
|
||||
#elif UNITS_LIBCXX < 14000
|
||||
#elif MP_UNITS_LIBCXX < 14000
|
||||
|
||||
using concepts::three_way_comparable;
|
||||
using concepts::three_way_comparable_with;
|
||||
|
||||
+3
-3
@@ -26,8 +26,8 @@
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
||||
MP_UNITS_DIAGNOSTIC_PUSH
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_EXPR_ALWAYS_TF
|
||||
|
||||
namespace mp_units {
|
||||
|
||||
@@ -296,4 +296,4 @@ using type_list_sort = TYPENAME detail::type_list_sort_impl<List, Pred>::type;
|
||||
|
||||
} // namespace mp_units
|
||||
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
@@ -136,7 +136,7 @@ inline constexpr bool is_named_magnitude = Magnitude<T> && !detail::is_specializ
|
||||
|
||||
}
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
template<typename T>
|
||||
struct mag_value {
|
||||
@@ -185,7 +185,7 @@ template<MagnitudeSpec Element>
|
||||
[[nodiscard]] consteval auto get_base(Element element)
|
||||
{
|
||||
if constexpr (detail::is_specialization_of_power_v<Element>) return Element::base;
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
else if constexpr (is_specialization_of<Element, mag_value>)
|
||||
return element.value;
|
||||
#endif
|
||||
@@ -271,12 +271,12 @@ template<typename T>
|
||||
|
||||
constexpr auto checked_multiply = [](auto a, auto b) {
|
||||
const auto result = a * b;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
MP_UNITS_DIAGNOSTIC_PUSH
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_FLOAT_EQUAL
|
||||
if (result / a != b) {
|
||||
std::terminate(); // Wraparound detected
|
||||
}
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -521,7 +521,7 @@ constexpr T get_value(const magnitude<Ms...>&)
|
||||
/**
|
||||
* @brief A convenient Magnitude constant for pi, which we can manipulate like a regular number.
|
||||
*/
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
inline constexpr struct mag_pi : magnitude<mag_value{std::numbers::pi_v<long double>}> {
|
||||
} mag_pi;
|
||||
|
||||
@@ -152,10 +152,10 @@ struct basic_symbol_text {
|
||||
[[nodiscard]] friend constexpr auto operator<=>(const basic_symbol_text& lhs,
|
||||
const basic_symbol_text<UnicodeCharT2, N2, M2>& rhs) noexcept
|
||||
{
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
MP_UNITS_DIAGNOSTIC_PUSH
|
||||
MP_UNITS_DIAGNOSTIC_IGNORE_ZERO_AS_NULLPOINTER_CONSTANT
|
||||
if (const auto cmp = lhs.unicode() <=> rhs.unicode(); cmp != 0) return cmp;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
MP_UNITS_DIAGNOSTIC_POP
|
||||
return lhs.ascii() <=> rhs.ascii();
|
||||
}
|
||||
|
||||
|
||||
@@ -453,7 +453,7 @@ struct kind_of_<Q> : Q {
|
||||
};
|
||||
#else
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
template<auto Q>
|
||||
requires detail::QuantitySpecWithNoSpecifiers<std::remove_cvref_t<decltype(Q)>> && (get_kind(Q) == Q)
|
||||
#else
|
||||
@@ -663,7 +663,7 @@ struct explode_to_equation_result {
|
||||
specs_convertible_result result;
|
||||
};
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
template<QuantitySpec Q>
|
||||
explode_to_equation_result(Q, specs_convertible_result) -> explode_to_equation_result<Q>;
|
||||
@@ -700,7 +700,7 @@ struct explode_result {
|
||||
}
|
||||
};
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
template<QuantitySpec Q>
|
||||
explode_result(Q) -> explode_result<Q>;
|
||||
@@ -870,7 +870,7 @@ struct extract_results {
|
||||
Elem elem{};
|
||||
};
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
template<QuantitySpec From = struct dimensionless, QuantitySpec To = struct dimensionless, typename Elem = int>
|
||||
extract_results(bool, From = {}, To = {}, prepend_rest = {}, Elem = {}) -> extract_results<From, To, Elem>;
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace mp_units {
|
||||
*/
|
||||
template<Magnitude auto M, Unit U>
|
||||
struct scaled_unit {
|
||||
static constexpr UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M;
|
||||
static constexpr MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M;
|
||||
static constexpr U reference_unit{};
|
||||
};
|
||||
|
||||
@@ -282,7 +282,7 @@ struct canonical_unit {
|
||||
U reference_unit;
|
||||
};
|
||||
|
||||
#if UNITS_COMP_CLANG
|
||||
#if MP_UNITS_COMP_CLANG
|
||||
|
||||
template<Magnitude M, Unit U>
|
||||
canonical_unit(M, U) -> canonical_unit<M, U>;
|
||||
|
||||
@@ -41,7 +41,7 @@ endfunction()
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
if(UNITS_USE_LIBFMT)
|
||||
if(MP_UNITS_USE_LIBFMT)
|
||||
find_dependency(fmt)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -51,12 +51,12 @@ inline constexpr struct newton : named_unit<"N", kilogram * metre / square(secon
|
||||
#ifdef pascal
|
||||
#pragma push_macro("pascal")
|
||||
#undef pascal
|
||||
#define UNITS_REDEFINE_PASCAL
|
||||
#define MP_UNITS_REDEFINE_PASCAL
|
||||
#endif
|
||||
inline constexpr struct pascal : named_unit<"Pa", newton / square(metre)> {} pascal;
|
||||
#ifdef UNITS_REDEFINE_PASCAL
|
||||
#ifdef MP_UNITS_REDEFINE_PASCAL
|
||||
#pragma pop_macro("pascal")
|
||||
#undef UNITS_REDEFINE_PASCAL
|
||||
#undef MP_UNITS_REDEFINE_PASCAL
|
||||
#endif
|
||||
inline constexpr struct joule : named_unit<"J", newton * metre> {} joule;
|
||||
inline constexpr struct watt : named_unit<"W", joule / second> {} watt;
|
||||
|
||||
Reference in new issue
Block a user