Cleanup base API

This commit is contained in:
Victor Zverovich 2024-09-02 07:41:20 -07:00
parent 4eed488c66
commit d980dd7171
4 changed files with 22 additions and 35 deletions

View File

@ -2240,9 +2240,9 @@ template <typename Char> struct named_arg_value {
}; };
template <typename Context> struct custom_value { template <typename Context> struct custom_value {
using parse_context = typename Context::parse_context_type; using char_type = typename Context::char_type;
void* value; void* value;
void (*format)(void* arg, parse_context& parse_ctx, Context& ctx); void (*format)(void* arg, parse_context<char_type>& parse_ctx, Context& ctx);
}; };
enum class custom_tag {}; enum class custom_tag {};
@ -2600,9 +2600,6 @@ template <typename Context> class basic_format_arg {
auto type() const -> detail::type { return type_; } auto type() const -> detail::type { return type_; }
auto is_integral() const -> bool { return detail::is_integral_type(type_); } auto is_integral() const -> bool { return detail::is_integral_type(type_); }
auto is_arithmetic() const -> bool {
return detail::is_arithmetic_type(type_);
}
/** /**
* Visits an argument dispatching to the appropriate visit method based on * Visits an argument dispatching to the appropriate visit method based on
@ -2650,8 +2647,8 @@ template <typename Context> class basic_format_arg {
} }
auto format_custom(const char_type* parse_begin, auto format_custom(const char_type* parse_begin,
typename Context::parse_context_type& parse_ctx, parse_context<char_type>& parse_ctx, Context& ctx)
Context& ctx) -> bool { -> bool {
if (type_ != detail::type::custom_type) return false; if (type_ != detail::type::custom_type) return false;
parse_ctx.advance_to(parse_begin); parse_ctx.advance_to(parse_begin);
value_.custom.format(value_.custom.value, parse_ctx, ctx); value_.custom.format(value_.custom.value, parse_ctx, ctx);
@ -2659,12 +2656,6 @@ template <typename Context> class basic_format_arg {
} }
}; };
template <typename Visitor, typename Context>
FMT_DEPRECATED FMT_CONSTEXPR auto visit_format_arg(
Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
return arg.visit(static_cast<Visitor&&>(vis));
}
/** /**
* A view of a collection of formatting arguments. To avoid lifetime issues it * A view of a collection of formatting arguments. To avoid lifetime issues it
* should only be used as a parameter type in type-erased functions such as * should only be used as a parameter type in type-erased functions such as
@ -2674,10 +2665,6 @@ FMT_DEPRECATED FMT_CONSTEXPR auto visit_format_arg(
* fmt::format_args args = fmt::make_format_args(); // Dangling reference * fmt::format_args args = fmt::make_format_args(); // Dangling reference
*/ */
template <typename Context> class basic_format_args { template <typename Context> class basic_format_args {
public:
using size_type = int;
using format_arg = basic_format_arg<Context>;
private: private:
// A descriptor that contains information about formatting arguments. // A descriptor that contains information about formatting arguments.
// If the number of arguments is less or equal to max_packed_args then // If the number of arguments is less or equal to max_packed_args then
@ -2691,7 +2678,7 @@ template <typename Context> class basic_format_args {
// may require more code (at least on x86-64) even if the same amount of // may require more code (at least on x86-64) even if the same amount of
// data is actually copied to stack. It saves ~10% on the bloat test. // data is actually copied to stack. It saves ~10% on the bloat test.
const detail::value<Context>* values_; const detail::value<Context>* values_;
const format_arg* args_; const basic_format_arg<Context>* args_;
}; };
constexpr auto is_packed() const -> bool { constexpr auto is_packed() const -> bool {
@ -2708,6 +2695,8 @@ template <typename Context> class basic_format_args {
} }
public: public:
using format_arg = basic_format_arg<Context>;
constexpr basic_format_args() : desc_(0), args_(nullptr) {} constexpr basic_format_args() : desc_(0), args_(nullptr) {}
/// Constructs a `basic_format_args` object from `format_arg_store`. /// Constructs a `basic_format_args` object from `format_arg_store`.
@ -2775,7 +2764,7 @@ template <typename Context> class basic_format_args {
class context { class context {
private: private:
appender out_; appender out_;
basic_format_args<context> args_; format_args args_;
FMT_NO_UNIQUE_ADDRESS detail::locale_ref loc_; FMT_NO_UNIQUE_ADDRESS detail::locale_ref loc_;
public: public:
@ -2784,15 +2773,14 @@ class context {
using iterator = appender; using iterator = appender;
using format_arg = basic_format_arg<context>; using format_arg = basic_format_arg<context>;
using parse_context_type = parse_context<char>; using parse_context_type FMT_DEPRECATED = parse_context<>;
template <typename T> using formatter_type FMT_DEPRECATED = formatter<T>; template <typename T> using formatter_type FMT_DEPRECATED = formatter<T>;
enum { builtin_types = FMT_BUILTIN_TYPES }; enum { builtin_types = FMT_BUILTIN_TYPES };
/// Constructs a `context` object. References to the arguments are stored /// Constructs a `context` object. References to the arguments are stored
/// in the object so make sure they have appropriate lifetimes. /// in the object so make sure they have appropriate lifetimes.
FMT_CONSTEXPR context(iterator out, basic_format_args<context> ctx_args, FMT_CONSTEXPR context(iterator out, format_args a, detail::locale_ref l = {})
detail::locale_ref loc = {}) : out_(out), args_(a), loc_(l) {}
: out_(out), args_(ctx_args), loc_(loc) {}
context(context&&) = default; context(context&&) = default;
context(const context&) = delete; context(const context&) = delete;
void operator=(const context&) = delete; void operator=(const context&) = delete;
@ -2802,7 +2790,6 @@ class context {
FMT_CONSTEXPR auto arg_id(string_view name) -> int { FMT_CONSTEXPR auto arg_id(string_view name) -> int {
return args_.get_id(name); return args_.get_id(name);
} }
auto args() const -> const basic_format_args<context>& { return args_; }
// Returns an iterator to the beginning of the output range. // Returns an iterator to the beginning of the output range.
FMT_CONSTEXPR auto out() -> iterator { return out_; } FMT_CONSTEXPR auto out() -> iterator { return out_; }
@ -2887,6 +2874,9 @@ template <typename T, typename Char = char>
concept formattable = is_formattable<remove_reference_t<T>, Char>::value; concept formattable = is_formattable<remove_reference_t<T>, Char>::value;
#endif #endif
template <typename T, typename Char>
using has_formatter FMT_DEPRECATED = std::is_constructible<formatter<T, Char>>;
// A formatter specialization for natively supported types. // A formatter specialization for natively supported types.
template <typename T, typename Char> template <typename T, typename Char>
struct formatter<T, Char, struct formatter<T, Char,

View File

@ -1043,8 +1043,9 @@ template <typename OutputIt, typename Char> class generic_context {
public: public:
using char_type = Char; using char_type = Char;
using iterator = OutputIt; using iterator = OutputIt;
using parse_context_type = parse_context<Char>; using parse_context_type FMT_DEPRECATED = parse_context<Char>;
template <typename T> using formatter_type = formatter<T, Char>; template <typename T>
using formatter_type FMT_DEPRECATED = formatter<T, Char>;
enum { builtin_types = FMT_BUILTIN_TYPES }; enum { builtin_types = FMT_BUILTIN_TYPES };
constexpr generic_context(OutputIt out, constexpr generic_context(OutputIt out,
@ -1064,9 +1065,6 @@ template <typename OutputIt, typename Char> class generic_context {
FMT_CONSTEXPR auto arg_id(basic_string_view<Char> name) -> int { FMT_CONSTEXPR auto arg_id(basic_string_view<Char> name) -> int {
return args_.get_id(name); return args_.get_id(name);
} }
auto args() const -> const basic_format_args<generic_context>& {
return args_;
}
FMT_CONSTEXPR auto out() -> iterator { return out_; } FMT_CONSTEXPR auto out() -> iterator { return out_; }

View File

@ -505,7 +505,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
} }
if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt(); if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt();
if (specs.fill_unit<Char>() == '0') { if (specs.fill_unit<Char>() == '0') {
if (arg.is_arithmetic() && specs.align() != align::left) { if (is_arithmetic_type(arg.type()) && specs.align() != align::left) {
specs.set_align(align::numeric); specs.set_align(align::numeric);
} else { } else {
// Ignore '0' flag for non-numeric types or if '-' flag is also present. // Ignore '0' flag for non-numeric types or if '-' flag is also present.

View File

@ -359,20 +359,19 @@ template <typename T, typename Char> struct is_range {
namespace detail { namespace detail {
template <typename T, typename Char>
using has_formatter = std::is_constructible<formatter<T, Char>>;
template <typename Context> struct range_mapper { template <typename Context> struct range_mapper {
using mapper = arg_mapper<typename Context::char_type>; using mapper = arg_mapper<typename Context::char_type>;
using char_type = typename Context::char_type; using char_type = typename Context::char_type;
template <typename T, template <typename T,
FMT_ENABLE_IF(has_formatter<remove_cvref_t<T>, char_type>::value)> FMT_ENABLE_IF(std::is_constructible<
formatter<remove_cvref_t<T>, char_type>>::value)>
static auto map(T&& value) -> T&& { static auto map(T&& value) -> T&& {
return static_cast<T&&>(value); return static_cast<T&&>(value);
} }
template <typename T, template <typename T,
FMT_ENABLE_IF(!has_formatter<remove_cvref_t<T>, char_type>::value)> FMT_ENABLE_IF(!std::is_constructible<
formatter<remove_cvref_t<T>, char_type>>::value)>
static auto map(T&& value) -> decltype(mapper::map(static_cast<T&&>(value))) { static auto map(T&& value) -> decltype(mapper::map(static_cast<T&&>(value))) {
return mapper::map(static_cast<T&&>(value)); return mapper::map(static_cast<T&&>(value));
} }