mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-26 00:21:13 +00:00
Parameterize Value on character type
This commit is contained in:
parent
6cba8fe9ba
commit
763ca9780f
15
fmt/format.h
15
fmt/format.h
@ -1012,6 +1012,7 @@ struct CustomValue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// A formatting argument value.
|
// A formatting argument value.
|
||||||
|
template <typename Char>
|
||||||
struct Value {
|
struct Value {
|
||||||
union {
|
union {
|
||||||
int int_value;
|
int int_value;
|
||||||
@ -1039,7 +1040,7 @@ class basic_format_args;
|
|||||||
// A formatting argument. It is a trivially copyable/constructible type to
|
// A formatting argument. It is a trivially copyable/constructible type to
|
||||||
// allow storage in internal::MemoryBuffer.
|
// allow storage in internal::MemoryBuffer.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class basic_format_arg : public internal::Value {
|
class basic_format_arg : public internal::Value<Char> {
|
||||||
protected:
|
protected:
|
||||||
internal::Type type_;
|
internal::Type type_;
|
||||||
|
|
||||||
@ -1539,8 +1540,10 @@ class format_arg_store {
|
|||||||
static const size_t NUM_ARGS = sizeof...(Args);
|
static const size_t NUM_ARGS = sizeof...(Args);
|
||||||
static const bool IS_PACKED = NUM_ARGS <= internal::MAX_PACKED_ARGS;
|
static const bool IS_PACKED = NUM_ARGS <= internal::MAX_PACKED_ARGS;
|
||||||
|
|
||||||
typedef typename std::conditional<
|
typedef typename Context::char_type char_type;
|
||||||
IS_PACKED, internal::Value, format_arg>::type value_type;
|
|
||||||
|
typedef typename std::conditional<IS_PACKED,
|
||||||
|
internal::Value<char_type>, basic_format_arg<char_type>>::type value_type;
|
||||||
|
|
||||||
// If the arguments are not packed, add one more element to mark the end.
|
// If the arguments are not packed, add one more element to mark the end.
|
||||||
std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> data_;
|
std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> data_;
|
||||||
@ -1583,7 +1586,7 @@ class basic_format_args {
|
|||||||
// This is done to reduce compiled code size as storing larger objects
|
// This is done to reduce compiled code size as storing larger objects
|
||||||
// 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 internal::Value *values_;
|
const internal::Value<Char> *values_;
|
||||||
const format_arg *args_;
|
const format_arg *args_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1596,7 +1599,7 @@ class basic_format_args {
|
|||||||
|
|
||||||
friend class internal::ArgMap<Char>;
|
friend class internal::ArgMap<Char>;
|
||||||
|
|
||||||
void set_data(const internal::Value *values) { values_ = values; }
|
void set_data(const internal::Value<Char> *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 get(size_type index) const {
|
||||||
@ -1604,7 +1607,7 @@ class basic_format_args {
|
|||||||
bool use_values = type(internal::MAX_PACKED_ARGS - 1) == internal::NONE;
|
bool use_values = type(internal::MAX_PACKED_ARGS - 1) == internal::NONE;
|
||||||
if (index < internal::MAX_PACKED_ARGS) {
|
if (index < internal::MAX_PACKED_ARGS) {
|
||||||
typename internal::Type arg_type = type(index);
|
typename internal::Type arg_type = type(index);
|
||||||
internal::Value &val = arg;
|
internal::Value<Char> &val = arg;
|
||||||
if (arg_type != internal::NONE)
|
if (arg_type != internal::NONE)
|
||||||
val = use_values ? values_[index] : args_[index];
|
val = use_values ? values_[index] : args_[index];
|
||||||
arg.type_ = arg_type;
|
arg.type_ = arg_type;
|
||||||
|
Loading…
Reference in New Issue
Block a user