mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-12 15:39:09 +00:00
Sync API with standards proposal
This commit is contained in:
parent
a1579b0ff8
commit
822eccc3b8
@ -686,7 +686,7 @@ class basic_format_arg {
|
|||||||
public:
|
public:
|
||||||
explicit handle(internal::custom_value<Context> custom): custom_(custom) {}
|
explicit handle(internal::custom_value<Context> custom): custom_(custom) {}
|
||||||
|
|
||||||
void format(Context &ctx) { custom_.format(custom_.value, ctx); }
|
void format(Context &ctx) const { custom_.format(custom_.value, ctx); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
internal::custom_value<Context> custom_;
|
internal::custom_value<Context> custom_;
|
||||||
@ -702,7 +702,6 @@ class basic_format_arg {
|
|||||||
|
|
||||||
bool is_integral() const { return internal::is_integral(type_); }
|
bool is_integral() const { return internal::is_integral(type_); }
|
||||||
bool is_arithmetic() const { return internal::is_arithmetic(type_); }
|
bool is_arithmetic() const { return internal::is_arithmetic(type_); }
|
||||||
bool is_pointer() const { return type_ == internal::pointer_type; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parsing context consisting of a format string range being parsed and an
|
// Parsing context consisting of a format string range being parsed and an
|
||||||
@ -816,7 +815,7 @@ class context_base {
|
|||||||
|
|
||||||
// Returns the argument with specified index.
|
// Returns the argument with specified index.
|
||||||
format_arg do_get_arg(unsigned arg_id) {
|
format_arg do_get_arg(unsigned arg_id) {
|
||||||
format_arg arg = args_[arg_id];
|
format_arg arg = args_.get(arg_id);
|
||||||
if (!arg)
|
if (!arg)
|
||||||
parse_context_.on_error("argument index out of range");
|
parse_context_.on_error("argument index out of range");
|
||||||
return arg;
|
return arg;
|
||||||
@ -986,8 +985,6 @@ class format_arg_store {
|
|||||||
format_arg_store(const Args &... args)
|
format_arg_store(const Args &... args)
|
||||||
: data_{internal::make_arg<IS_PACKED, Context>(args)...} {}
|
: data_{internal::make_arg<IS_PACKED, Context>(args)...} {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
basic_format_args<Context> operator*() const { return *this; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ...Args>
|
template <typename Context, typename ...Args>
|
||||||
@ -1047,7 +1044,7 @@ class basic_format_args {
|
|||||||
void set_data(const internal::value<Context> *values) { values_ = values; }
|
void set_data(const internal::value<Context> *values) { values_ = values; }
|
||||||
void set_data(const format_arg *args) { args_ = args; }
|
void set_data(const format_arg *args) { args_ = args; }
|
||||||
|
|
||||||
format_arg get(size_type index) const {
|
format_arg do_get(size_type index) const {
|
||||||
int64_t signed_types = static_cast<int64_t>(types_);
|
int64_t signed_types = static_cast<int64_t>(types_);
|
||||||
if (signed_types < 0) {
|
if (signed_types < 0) {
|
||||||
uint64_t num_args = -signed_types;
|
uint64_t num_args = -signed_types;
|
||||||
@ -1079,8 +1076,8 @@ class basic_format_args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the argument at specified index. */
|
/** Returns the argument at specified index. */
|
||||||
format_arg operator[](size_type index) const {
|
format_arg get(size_type index) const {
|
||||||
format_arg arg = get(index);
|
format_arg arg = do_get(index);
|
||||||
return arg.type_ == internal::name_arg_type ?
|
return arg.type_ == internal::name_arg_type ?
|
||||||
arg.value_.as_named_arg().template deserialize<Context>() : arg;
|
arg.value_.as_named_arg().template deserialize<Context>() : arg;
|
||||||
}
|
}
|
||||||
|
@ -3384,7 +3384,7 @@ template <typename OutputIt, typename... Args>
|
|||||||
inline OutputIt format_to(OutputIt out, string_view format_str,
|
inline OutputIt format_to(OutputIt out, string_view format_str,
|
||||||
const Args & ... args) {
|
const Args & ... args) {
|
||||||
return vformat_to(out, format_str,
|
return vformat_to(out, format_str,
|
||||||
*make_format_args<typename format_context_t<OutputIt>::type>(args...));
|
make_format_args<typename format_context_t<OutputIt>::type>(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Container, typename... Args>
|
template <typename Container, typename... Args>
|
||||||
@ -3415,7 +3415,7 @@ inline format_to_n_result<OutputIt> format_to_n(
|
|||||||
OutputIt out, std::size_t n, string_view format_str, const Args & ... args) {
|
OutputIt out, std::size_t n, string_view format_str, const Args & ... args) {
|
||||||
typedef internal::truncating_iterator<OutputIt> It;
|
typedef internal::truncating_iterator<OutputIt> It;
|
||||||
auto it = vformat_to(It(out, n), format_str,
|
auto it = vformat_to(It(out, n), format_str,
|
||||||
*make_format_args<typename format_context_t<It>::type>(args...));
|
make_format_args<typename format_context_t<It>::type>(args...));
|
||||||
return {it.base(), it.count()};
|
return {it.base(), it.count()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ TEST(UtilTest, Increment) {
|
|||||||
|
|
||||||
TEST(UtilTest, FormatArgs) {
|
TEST(UtilTest, FormatArgs) {
|
||||||
fmt::format_args args;
|
fmt::format_args args;
|
||||||
EXPECT_FALSE(args[1]);
|
EXPECT_FALSE(args.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct custom_context {
|
struct custom_context {
|
||||||
|
Loading…
Reference in New Issue
Block a user