mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
MakeArg -> make_arg
This commit is contained in:
parent
ee1651ce07
commit
abb6996f36
36
fmt/format.h
36
fmt/format.h
@ -371,6 +371,9 @@ class BasicWriter;
|
||||
typedef BasicWriter<char> Writer;
|
||||
typedef BasicWriter<wchar_t> WWriter;
|
||||
|
||||
template <typename Char>
|
||||
class basic_format_arg;
|
||||
|
||||
template <typename Char>
|
||||
class ArgFormatter;
|
||||
|
||||
@ -1329,6 +1332,9 @@ class MakeValue : public Value<typename Context::char_type> {
|
||||
|
||||
template <typename Char>
|
||||
class ArgMap;
|
||||
|
||||
template <typename Context, typename T>
|
||||
basic_format_arg<typename Context::char_type> make_arg(const T &value);
|
||||
} // namespace internal
|
||||
|
||||
struct monostate {};
|
||||
@ -1340,10 +1346,14 @@ class basic_format_args;
|
||||
// allow storage in internal::MemoryBuffer.
|
||||
template <typename Char>
|
||||
class basic_format_arg {
|
||||
protected:
|
||||
private:
|
||||
internal::Value<Char> value_;
|
||||
internal::Type type_;
|
||||
|
||||
template <typename Context, typename T>
|
||||
friend basic_format_arg<typename Context::char_type>
|
||||
internal::make_arg(const T &value);
|
||||
|
||||
template <typename Visitor, typename CharType>
|
||||
friend typename std::result_of<Visitor(int)>::type
|
||||
visit(Visitor &&vis, basic_format_arg<CharType> arg);
|
||||
@ -1426,19 +1436,13 @@ typename std::result_of<Visitor(int)>::type
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename Context>
|
||||
class MakeArg : public basic_format_arg<typename Context::char_type> {
|
||||
public:
|
||||
MakeArg() {
|
||||
this->type_ = internal::NONE;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MakeArg(const T &value) {
|
||||
this->value_ = internal::MakeValue<Context>(value);
|
||||
this->type_ = internal::type<T>();
|
||||
}
|
||||
};
|
||||
template <typename Context, typename T>
|
||||
basic_format_arg<typename Context::char_type> make_arg(const T &value) {
|
||||
basic_format_arg<typename Context::char_type> arg;
|
||||
arg.type_ = internal::type<T>();
|
||||
arg.value_ = internal::MakeValue<Context>(value);
|
||||
return arg;
|
||||
}
|
||||
|
||||
template <typename T, T> struct LConvCheck {
|
||||
LConvCheck(int) {}
|
||||
@ -1490,7 +1494,7 @@ struct NamedArg : basic_format_arg<Char> {
|
||||
|
||||
template <typename T>
|
||||
NamedArg(BasicStringRef<Char> argname, const T &value)
|
||||
: basic_format_arg<Char>(MakeArg< basic_format_context<Char> >(value)),
|
||||
: basic_format_arg<Char>(make_arg< basic_format_context<Char> >(value)),
|
||||
name(argname) {}
|
||||
};
|
||||
|
||||
@ -1522,7 +1526,7 @@ template <bool IS_PACKED, typename Context, typename T>
|
||||
inline typename std::enable_if<
|
||||
!IS_PACKED, basic_format_arg<typename Context::char_type>>::type
|
||||
make_arg(const T& value) {
|
||||
return MakeArg<Context>(value);
|
||||
return make_arg<Context>(value);
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
|
@ -87,8 +87,8 @@ void format_value(BasicWriter<Char> &w, const T &value,
|
||||
basic_format_context<Char> &ctx) {
|
||||
internal::MemoryBuffer<Char, internal::INLINE_BUFFER_SIZE> buffer;
|
||||
auto str = internal::format_value(buffer, value);
|
||||
typedef internal::MakeArg< basic_format_context<Char> > MakeArg;
|
||||
do_format_arg< ArgFormatter<Char> >(w, MakeArg(str), ctx);
|
||||
do_format_arg< ArgFormatter<Char> >(
|
||||
w, internal::make_arg< basic_format_context<Char> >(str), ctx);
|
||||
}
|
||||
|
||||
FMT_API void vprint(std::ostream &os, CStringRef format_str, format_args args);
|
||||
|
10
fmt/printf.h
10
fmt/printf.h
@ -105,11 +105,11 @@ class ArgConverter {
|
||||
if (sizeof(TargetType) <= sizeof(int)) {
|
||||
// Extra casts are used to silence warnings.
|
||||
if (is_signed) {
|
||||
arg_ = internal::MakeArg<format_context>(
|
||||
arg_ = internal::make_arg<format_context>(
|
||||
static_cast<int>(static_cast<TargetType>(value)));
|
||||
} else {
|
||||
typedef typename internal::MakeUnsigned<TargetType>::Type Unsigned;
|
||||
arg_ = internal::MakeArg<format_context>(
|
||||
arg_ = internal::make_arg<format_context>(
|
||||
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
||||
}
|
||||
} else {
|
||||
@ -117,10 +117,10 @@ class ArgConverter {
|
||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||
// std::printf("%lld", -42); // prints "4294967254"
|
||||
// but we don't have to do the same because it's a UB.
|
||||
arg_ = internal::MakeArg<format_context>(
|
||||
arg_ = internal::make_arg<format_context>(
|
||||
static_cast<LongLong>(value));
|
||||
} else {
|
||||
arg_ = internal::MakeArg<format_context>(
|
||||
arg_ = internal::make_arg<format_context>(
|
||||
static_cast<typename internal::MakeUnsigned<U>::Type>(value));
|
||||
}
|
||||
}
|
||||
@ -157,7 +157,7 @@ class CharConverter {
|
||||
typename std::enable_if<std::is_integral<T>::value>::type
|
||||
operator()(T value) {
|
||||
arg_ =
|
||||
internal::MakeArg<basic_format_context<Char>>(static_cast<char>(value));
|
||||
internal::make_arg<basic_format_context<Char>>(static_cast<char>(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -57,7 +57,7 @@ struct ValueExtractor {
|
||||
TEST(FormatTest, ArgConverter) {
|
||||
using fmt::format_arg;
|
||||
fmt::LongLong value = std::numeric_limits<fmt::LongLong>::max();
|
||||
format_arg arg = fmt::internal::MakeArg<fmt::format_context>(value);
|
||||
format_arg arg = fmt::internal::make_arg<fmt::format_context>(value);
|
||||
visit(fmt::internal::ArgConverter<fmt::LongLong, char>(arg, 'd'), arg);
|
||||
EXPECT_EQ(value, visit(ValueExtractor<fmt::LongLong>(), arg));
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ TEST(OStreamTest, CustomArg) {
|
||||
fmt::format_context ctx("}", fmt::format_args());
|
||||
fmt::FormatSpec spec;
|
||||
TestArgFormatter af(writer, ctx, spec);
|
||||
visit(af, fmt::internal::MakeArg<fmt::format_context>(TestEnum()));
|
||||
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
|
||||
EXPECT_EQ("TestEnum", writer.str());
|
||||
}
|
||||
|
||||
|
@ -75,8 +75,7 @@ void format_value(fmt::BasicWriter<Char> &w, Test,
|
||||
|
||||
template <typename Char, typename T>
|
||||
basic_format_arg<Char> make_arg(const T &value) {
|
||||
typedef fmt::internal::MakeArg< fmt::basic_format_context<Char> > MakeArg;
|
||||
return MakeArg(value);
|
||||
return fmt::internal::make_arg< fmt::basic_format_context<Char> >(value);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user