🎉 Array overload safety for base.h only
This commit is contained in:
parent
123e058eb3
commit
acc60e68b8
@ -259,6 +259,8 @@
|
|||||||
# define FMT_UNICODE !FMT_MSC_VERSION
|
# define FMT_UNICODE !FMT_MSC_VERSION
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FMT_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
|
||||||
|
|
||||||
// Enable minimal optimizations for more compact code in debug mode.
|
// Enable minimal optimizations for more compact code in debug mode.
|
||||||
FMT_GCC_PRAGMA("GCC push_options")
|
FMT_GCC_PRAGMA("GCC push_options")
|
||||||
#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
|
#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}}; }
|
inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
using format_string = basic_format_string<char, type_identity_t<Args>...>;
|
||||||
/** Formats a string and writes the output to ``out``. */
|
/** Formats a string and writes the output to ``out``. */
|
||||||
template <typename OutputIt,
|
template <typename OutputIt,
|
||||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
|
||||||
auto vformat_to(OutputIt out, string_view fmt, format_args args) -> 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);
|
auto&& buf = detail::get_buffer<char>(out);
|
||||||
detail::vformat_to(buf, fmt, args, {});
|
detail::vformat_to(buf, fmt, args, {});
|
||||||
return detail::get_iterator(buf, out);
|
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
|
\rst
|
||||||
Formats ``args`` according to specifications in ``fmt``, writes the result to
|
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
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename OutputIt, typename... T,
|
template <typename OutputIt, typename... T,
|
||||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
|
FMT_ENABLE_IF(detail::is_output_iterator<remove_cvref_t<OutputIt>,
|
||||||
FMT_INLINE auto format_to(OutputIt out, format_string<T...> fmt, T&&... args)
|
char>::value)>
|
||||||
-> OutputIt {
|
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...));
|
return vformat_to(out, fmt, fmt::make_format_args(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user