🎉 Array overload safety for base.h only

This commit is contained in:
ThePhD 2024-01-14 11:45:04 -05:00
parent 123e058eb3
commit acc60e68b8
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA

View File

@ -259,6 +259,8 @@
# define FMT_UNICODE !FMT_MSC_VERSION
#endif
#define FMT_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
// Enable minimal optimizations for more compact code in debug mode.
FMT_GCC_PRAGMA("GCC push_options")
#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
@ -2809,15 +2811,43 @@ using format_string = basic_format_string<char, type_identity_t<Args>...>;
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
#endif
template <typename... Args>
using format_string = basic_format_string<char, type_identity_t<Args>...>;
/** Formats a string and writes the output to ``out``. */
template <typename OutputIt,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
char>::value)>
auto vformat_to(OutputIt&& out, string_view fmt, format_args args)
-> remove_cvref_t<OutputIt> {
auto&& buf = detail::get_buffer<char>(out);
detail::vformat_to(buf, fmt, args, {});
return detail::get_iterator(buf, out);
}
template <typename OutputIt, typename OutputSen = OutputIt>
struct format_to_result {
/** Iterator past the end of the last write. */
OutputIt out;
/** Iterator to the end of the output range. */
OutputSen out_last;
FMT_CONSTEXPR operator OutputIt&() & noexcept { return out; }
FMT_CONSTEXPR operator const OutputIt&() const& noexcept { return out; }
FMT_CONSTEXPR operator OutputIt&&() && noexcept {
return static_cast<OutputIt&&>(out);
}
};
/** Formats a string and writes the output to ``out``. */
template <size_t Size>
auto vformat_to(char (&out)[Size], string_view fmt, format_args args)
-> format_to_result<char*> {
using traits = detail::fixed_buffer_traits;
auto buf = detail::iterator_buffer<char*, char, traits>(out, Size);
detail::vformat_to(buf, fmt, args, {});
return {out + buf.count(), out + Size};
}
/**
\rst
Formats ``args`` according to specifications in ``fmt``, writes the result to
@ -2831,9 +2861,28 @@ auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
\endrst
*/
template <typename OutputIt, typename... T,
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
FMT_INLINE auto format_to(OutputIt out, format_string<T...> fmt, T&&... args)
-> OutputIt {
FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
char>::value)>
FMT_INLINE auto format_to(OutputIt&& out, format_string<T...> fmt, T&&... args)
-> remove_cvref_t<OutputIt> {
return vformat_to(FMT_FWD(out), fmt, fmt::make_format_args(args...));
}
/**
\rst
Formats ``args`` according to specifications in ``fmt``, writes the result to
the output iterator ``out`` and returns the iterator past the end of the output
range. `format_to` does not append a terminating null character.
**Example**::
auto out = std::vector<char>();
fmt::format_to(std::back_inserter(out), "{}", 42);
\endrst
*/
template <size_t Size, typename... T>
FMT_INLINE auto format_to(char (&out)[Size], format_string<T...> fmt,
T&&... args) -> format_to_result<char*> {
return vformat_to(out, fmt, fmt::make_format_args(args...));
}