forked from fmtlib/fmt
Detemplatize basic_printf_context
This commit is contained in:
@@ -1698,7 +1698,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using iterator = OutputIt;
|
using iterator = OutputIt;
|
||||||
using format_arg = basic_format_arg<basic_format_context>; // DEPRECATED!
|
using format_arg = basic_format_arg<basic_format_context>;
|
||||||
using format_args = basic_format_args<basic_format_context>;
|
using format_args = basic_format_args<basic_format_context>;
|
||||||
using parse_context_type = basic_format_parse_context<Char>;
|
using parse_context_type = basic_format_parse_context<Char>;
|
||||||
template <typename T> using formatter_type = formatter<T, Char>;
|
template <typename T> using formatter_type = formatter<T, Char>;
|
||||||
|
@@ -18,9 +18,9 @@ FMT_BEGIN_EXPORT
|
|||||||
|
|
||||||
template <typename T> struct printf_formatter { printf_formatter() = delete; };
|
template <typename T> struct printf_formatter { printf_formatter() = delete; };
|
||||||
|
|
||||||
template <typename OutputIt, typename Char> class basic_printf_context {
|
template <typename Char> class basic_printf_context {
|
||||||
private:
|
private:
|
||||||
OutputIt out_;
|
detail::buffer_appender<Char> out_;
|
||||||
basic_format_args<basic_printf_context> args_;
|
basic_format_args<basic_printf_context> args_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -34,12 +34,12 @@ template <typename OutputIt, typename Char> class basic_printf_context {
|
|||||||
stored in the context object so make sure they have appropriate lifetimes.
|
stored in the context object so make sure they have appropriate lifetimes.
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
basic_printf_context(OutputIt out,
|
basic_printf_context(detail::buffer_appender<Char> out,
|
||||||
basic_format_args<basic_printf_context> args)
|
basic_format_args<basic_printf_context> args)
|
||||||
: out_(out), args_(args) {}
|
: out_(out), args_(args) {}
|
||||||
|
|
||||||
auto out() -> OutputIt { return out_; }
|
auto out() -> detail::buffer_appender<Char> { return out_; }
|
||||||
void advance_to(OutputIt it) { out_ = it; }
|
void advance_to(detail::buffer_appender<Char>) {}
|
||||||
|
|
||||||
auto locale() -> detail::locale_ref { return {}; }
|
auto locale() -> detail::locale_ref { return {}; }
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ template <typename OutputIt, typename Char>
|
|||||||
class printf_arg_formatter : public arg_formatter<Char> {
|
class printf_arg_formatter : public arg_formatter<Char> {
|
||||||
private:
|
private:
|
||||||
using base = arg_formatter<Char>;
|
using base = arg_formatter<Char>;
|
||||||
using context_type = basic_printf_context<OutputIt, Char>;
|
using context_type = basic_printf_context<Char>;
|
||||||
|
|
||||||
context_type& context_;
|
context_type& context_;
|
||||||
|
|
||||||
@@ -412,7 +412,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
|||||||
basic_format_args<Context> args) {
|
basic_format_args<Context> args) {
|
||||||
using iterator = buffer_appender<Char>;
|
using iterator = buffer_appender<Char>;
|
||||||
auto out = iterator(buf);
|
auto out = iterator(buf);
|
||||||
auto context = basic_printf_context<iterator, Char>(out, args);
|
auto context = basic_printf_context<Char>(out, args);
|
||||||
auto parse_ctx = basic_format_parse_context<Char>(format);
|
auto parse_ctx = basic_format_parse_context<Char>(format);
|
||||||
|
|
||||||
// Returns the argument with specified index or, if arg_index is -1, the next
|
// Returns the argument with specified index or, if arg_index is -1, the next
|
||||||
@@ -476,7 +476,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
|||||||
auto nul = std::find(str, str_end, Char());
|
auto nul = std::find(str, str_end, Char());
|
||||||
auto sv = basic_string_view<Char>(
|
auto sv = basic_string_view<Char>(
|
||||||
str, to_unsigned(nul != str_end ? nul - str : specs.precision));
|
str, to_unsigned(nul != str_end ? nul - str : specs.precision));
|
||||||
arg = make_arg<basic_printf_context<iterator, Char>>(sv);
|
arg = make_arg<basic_printf_context<Char>>(sv);
|
||||||
}
|
}
|
||||||
if (specs.alt && visit_format_arg(is_zero_int(), arg)) specs.alt = false;
|
if (specs.alt && visit_format_arg(is_zero_int(), arg)) specs.alt = false;
|
||||||
if (specs.fill[0] == '0') {
|
if (specs.fill[0] == '0') {
|
||||||
@@ -538,8 +538,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
|||||||
type = 'd';
|
type = 'd';
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
visit_format_arg(
|
visit_format_arg(char_converter<basic_printf_context<Char>>(arg), arg);
|
||||||
char_converter<basic_printf_context<iterator, Char>>(arg), arg);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,12 +556,8 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
|
|||||||
}
|
}
|
||||||
FMT_END_DETAIL_NAMESPACE
|
FMT_END_DETAIL_NAMESPACE
|
||||||
|
|
||||||
template <typename Char>
|
using printf_context = basic_printf_context<char>;
|
||||||
using basic_printf_context_t =
|
using wprintf_context = basic_printf_context<wchar_t>;
|
||||||
basic_printf_context<detail::buffer_appender<Char>, Char>;
|
|
||||||
|
|
||||||
using printf_context = basic_printf_context_t<char>;
|
|
||||||
using wprintf_context = basic_printf_context_t<wchar_t>;
|
|
||||||
|
|
||||||
using printf_args = basic_format_args<printf_context>;
|
using printf_args = basic_format_args<printf_context>;
|
||||||
using wprintf_args = basic_format_args<wprintf_context>;
|
using wprintf_args = basic_format_args<wprintf_context>;
|
||||||
@@ -595,7 +590,7 @@ inline auto make_wprintf_args(const T&... args)
|
|||||||
template <typename S, typename Char = char_t<S>>
|
template <typename S, typename Char = char_t<S>>
|
||||||
inline auto vsprintf(
|
inline auto vsprintf(
|
||||||
const S& fmt,
|
const S& fmt,
|
||||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||||
-> std::basic_string<Char> {
|
-> std::basic_string<Char> {
|
||||||
auto buf = basic_memory_buffer<Char>();
|
auto buf = basic_memory_buffer<Char>();
|
||||||
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
||||||
@@ -614,15 +609,14 @@ inline auto vsprintf(
|
|||||||
template <typename S, typename... T,
|
template <typename S, typename... T,
|
||||||
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
typename Char = enable_if_t<detail::is_string<S>::value, char_t<S>>>
|
||||||
inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string<Char> {
|
inline auto sprintf(const S& fmt, const T&... args) -> std::basic_string<Char> {
|
||||||
using context = basic_printf_context_t<Char>;
|
|
||||||
return vsprintf(detail::to_string_view(fmt),
|
return vsprintf(detail::to_string_view(fmt),
|
||||||
fmt::make_format_args<context>(args...));
|
fmt::make_format_args<basic_printf_context<Char>>(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename S, typename Char = char_t<S>>
|
template <typename S, typename Char = char_t<S>>
|
||||||
inline auto vfprintf(
|
inline auto vfprintf(
|
||||||
std::FILE* f, const S& fmt,
|
std::FILE* f, const S& fmt,
|
||||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||||
-> int {
|
-> int {
|
||||||
auto buf = basic_memory_buffer<Char>();
|
auto buf = basic_memory_buffer<Char>();
|
||||||
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
detail::vprintf(buf, detail::to_string_view(fmt), args);
|
||||||
@@ -643,7 +637,7 @@ inline auto vfprintf(
|
|||||||
*/
|
*/
|
||||||
template <typename S, typename... T, typename Char = char_t<S>>
|
template <typename S, typename... T, typename Char = char_t<S>>
|
||||||
inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
|
inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
|
||||||
using context = basic_printf_context_t<Char>;
|
using context = basic_printf_context<Char>;
|
||||||
return vfprintf(f, detail::to_string_view(fmt),
|
return vfprintf(f, detail::to_string_view(fmt),
|
||||||
fmt::make_format_args<context>(args...));
|
fmt::make_format_args<context>(args...));
|
||||||
}
|
}
|
||||||
@@ -651,7 +645,7 @@ inline auto fprintf(std::FILE* f, const S& fmt, const T&... args) -> int {
|
|||||||
template <typename Char>
|
template <typename Char>
|
||||||
FMT_DEPRECATED inline auto vprintf(
|
FMT_DEPRECATED inline auto vprintf(
|
||||||
basic_string_view<Char> fmt,
|
basic_string_view<Char> fmt,
|
||||||
basic_format_args<basic_printf_context_t<type_identity_t<Char>>> args)
|
basic_format_args<basic_printf_context<type_identity_t<Char>>> args)
|
||||||
-> int {
|
-> int {
|
||||||
return vfprintf(stdout, fmt, args);
|
return vfprintf(stdout, fmt, args);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user