mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 12:24:26 +02:00
refactor: remove dependency on <ranges>
header and switch to use an iterator-based copy
algorithm
This commit is contained in:
@@ -39,7 +39,6 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <ranges>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
@@ -95,7 +95,7 @@ constexpr Out copy(const symbol_text<N, M>& txt, text_encoding encoding, Out out
|
|||||||
{
|
{
|
||||||
if (encoding == text_encoding::unicode) {
|
if (encoding == text_encoding::unicode) {
|
||||||
if constexpr (is_same_v<CharT, char8_t>)
|
if constexpr (is_same_v<CharT, char8_t>)
|
||||||
return copy(txt.unicode(), out).out;
|
return ::mp_units::detail::copy(txt.unicode().begin(), txt.unicode().end(), out);
|
||||||
else if constexpr (is_same_v<CharT, char>) {
|
else if constexpr (is_same_v<CharT, char>) {
|
||||||
for (const char8_t ch : txt.unicode()) *out++ = static_cast<char>(ch);
|
for (const char8_t ch : txt.unicode()) *out++ = static_cast<char>(ch);
|
||||||
return out;
|
return out;
|
||||||
@@ -103,7 +103,7 @@ constexpr Out copy(const symbol_text<N, M>& txt, text_encoding encoding, Out out
|
|||||||
throw std::invalid_argument("Unicode text can't be copied to CharT output");
|
throw std::invalid_argument("Unicode text can't be copied to CharT output");
|
||||||
} else {
|
} else {
|
||||||
if constexpr (is_same_v<CharT, char>)
|
if constexpr (is_same_v<CharT, char>)
|
||||||
return copy(txt.ascii(), out).out;
|
return ::mp_units::detail::copy(txt.ascii().begin(), txt.ascii().end(), out);
|
||||||
else
|
else
|
||||||
throw std::invalid_argument("ASCII text can't be copied to CharT output");
|
throw std::invalid_argument("ASCII text can't be copied to CharT output");
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@
|
|||||||
#include <compare>
|
#include <compare>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <ranges>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace mp_units::detail {
|
namespace mp_units::detail {
|
||||||
@@ -164,44 +163,11 @@ constexpr const T& min(const T& a, const T& b)
|
|||||||
return (b < a) ? b : a;
|
return (b < a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class I, class O>
|
template<class InputIt, class OutputIt>
|
||||||
struct in_out_result {
|
constexpr OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
|
||||||
[[no_unique_address]] I in;
|
|
||||||
[[no_unique_address]] O out;
|
|
||||||
|
|
||||||
template<class I2, class O2>
|
|
||||||
requires std::convertible_to<const I&, I2> && std::convertible_to<const O&, O2>
|
|
||||||
constexpr operator in_out_result<I2, O2>() const&
|
|
||||||
{
|
|
||||||
return {in, out};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class I2, class O2>
|
|
||||||
requires std::convertible_to<I, I2> && std::convertible_to<O, O2>
|
|
||||||
constexpr operator in_out_result<I2, O2>() &&
|
|
||||||
{
|
|
||||||
return {std::move(in), std::move(out)};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class I, class O>
|
|
||||||
using copy_result = in_out_result<I, O>;
|
|
||||||
|
|
||||||
template<std::input_iterator I, std::sentinel_for<I> S, std::weakly_incrementable O>
|
|
||||||
requires std::indirectly_copyable<I, O>
|
|
||||||
constexpr copy_result<I, O> copy(I first, S last, O result)
|
|
||||||
{
|
{
|
||||||
for (; first != last; ++first, (void)++result) {
|
for (; first != last; (void)++first, (void)++d_first) *d_first = *first;
|
||||||
*result = *first;
|
return d_first;
|
||||||
}
|
|
||||||
return {std::move(first), std::move(result)};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<std::ranges::input_range R, std::weakly_incrementable O>
|
|
||||||
requires std::indirectly_copyable<std::ranges::iterator_t<R>, O>
|
|
||||||
constexpr copy_result<std::ranges::borrowed_iterator_t<R>, O> copy(R&& r, O result)
|
|
||||||
{
|
|
||||||
return ::mp_units::detail::copy(std::ranges::begin(r), std::ranges::end(r), std::move(result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mp_units::detail
|
} // namespace mp_units::detail
|
||||||
|
@@ -319,7 +319,7 @@ class MP_UNITS_STD_FMT::formatter<mp_units::quantity<Reference, Rep>, Char> {
|
|||||||
out = MP_UNITS_STD_FMT::vformat_to(out, locale, f.dimension_format_str_,
|
out = MP_UNITS_STD_FMT::vformat_to(out, locale, f.dimension_format_str_,
|
||||||
MP_UNITS_STD_FMT::make_format_args(q.dimension));
|
MP_UNITS_STD_FMT::make_format_args(q.dimension));
|
||||||
}
|
}
|
||||||
void on_text(const Char* begin, const Char* end) const { std::copy(begin, end, out); }
|
void on_text(const Char* begin, const Char* end) const { mp_units::detail::copy(begin, end, out); }
|
||||||
};
|
};
|
||||||
template<typename OutputIt, typename... Args>
|
template<typename OutputIt, typename... Args>
|
||||||
quantity_formatter(const formatter&, OutputIt, Args...) -> quantity_formatter<OutputIt>;
|
quantity_formatter(const formatter&, OutputIt, Args...) -> quantity_formatter<OutputIt>;
|
||||||
|
@@ -720,7 +720,8 @@ constexpr Out print_separator(Out out, const unit_symbol_formatting& fmt)
|
|||||||
if (fmt.encoding != text_encoding::unicode)
|
if (fmt.encoding != text_encoding::unicode)
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
"'unit_symbol_separator::half_high_dot' can be only used with 'text_encoding::unicode'");
|
"'unit_symbol_separator::half_high_dot' can be only used with 'text_encoding::unicode'");
|
||||||
out = copy(std::string_view("⋅"), out).out;
|
const std::string_view dot = "⋅";
|
||||||
|
out = detail::copy(dot.begin(), dot.end(), out);
|
||||||
} else {
|
} else {
|
||||||
*out++ = ' ';
|
*out++ = ' ';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user