mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-08 11:33:46 +00:00
Introduced NamedArgWithType<Char, T> : NamedArg<Char>
This commit is contained in:
parent
d09dd1a81a
commit
1546b9e336
22
fmt/format.h
22
fmt/format.h
@ -1041,6 +1041,8 @@ struct Arg : Value {
|
|||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct NamedArg;
|
struct NamedArg;
|
||||||
|
template <typename Char, typename T>
|
||||||
|
struct NamedArgWithType;
|
||||||
|
|
||||||
template <typename T = void>
|
template <typename T = void>
|
||||||
struct Null {};
|
struct Null {};
|
||||||
@ -1322,9 +1324,13 @@ class MakeValue : public Arg {
|
|||||||
// uses char.
|
// uses char.
|
||||||
template <typename Char_>
|
template <typename Char_>
|
||||||
MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
|
MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
|
||||||
|
template <typename Char_, typename T>
|
||||||
|
MakeValue(const NamedArgWithType<Char_, T> &value) { pointer = &value; }
|
||||||
|
|
||||||
template <typename Char_>
|
template <typename Char_>
|
||||||
static uint64_t type(const NamedArg<Char_> &) { return Arg::NAMED_ARG; }
|
static uint64_t type(const NamedArg<Char_> &) { return Arg::NAMED_ARG; }
|
||||||
|
template <typename Char_, typename T>
|
||||||
|
static uint64_t type(const NamedArgWithType<Char_, T> &) { return Arg::NAMED_ARG; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Formatter>
|
template <typename Formatter>
|
||||||
@ -1350,6 +1356,12 @@ struct NamedArg : Arg {
|
|||||||
: Arg(MakeArg< BasicFormatter<Char> >(value)), name(argname) {}
|
: Arg(MakeArg< BasicFormatter<Char> >(value)), name(argname) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Char, typename T>
|
||||||
|
struct NamedArgWithType : NamedArg<Char> {
|
||||||
|
NamedArgWithType(BasicStringRef<Char> argname, const T &value)
|
||||||
|
: NamedArg<Char>(argname, value) {}
|
||||||
|
};
|
||||||
|
|
||||||
class RuntimeError : public std::runtime_error {
|
class RuntimeError : public std::runtime_error {
|
||||||
protected:
|
protected:
|
||||||
RuntimeError() : std::runtime_error("") {}
|
RuntimeError() : std::runtime_error("") {}
|
||||||
@ -3331,13 +3343,13 @@ inline void format_decimal(char *&buffer, T value) {
|
|||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline internal::NamedArg<char> arg(StringRef name, const T &arg) {
|
inline internal::NamedArgWithType<char, T> arg(StringRef name, const T &arg) {
|
||||||
return internal::NamedArg<char>(name, arg);
|
return internal::NamedArgWithType<char, T>(name, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline internal::NamedArg<wchar_t> arg(WStringRef name, const T &arg) {
|
inline internal::NamedArgWithType<wchar_t, T> arg(WStringRef name, const T &arg) {
|
||||||
return internal::NamedArg<wchar_t>(name, arg);
|
return internal::NamedArgWithType<wchar_t, T>(name, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following two functions are deleted intentionally to disable
|
// The following two functions are deleted intentionally to disable
|
||||||
@ -3782,7 +3794,7 @@ struct UdlArg {
|
|||||||
const Char *str;
|
const Char *str;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
NamedArg<Char> operator=(T &&value) const {
|
NamedArgWithType<Char, T> operator=(T &&value) const {
|
||||||
return {str, std::forward<T>(value)};
|
return {str, std::forward<T>(value)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user