Skip to content

Commit

Permalink
Merge pull request #390 from chronoxor/master
Browse files Browse the repository at this point in the history
Introduced NamedArgWithType<Char, T> : NamedArg<Char>
  • Loading branch information
vitaut authored Sep 29, 2016
2 parents 17c17d1 + 1546b9e commit f66d37f
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ struct Arg : Value {

template <typename Char>
struct NamedArg;
template <typename Char, typename T>
struct NamedArgWithType;

template <typename T = void>
struct Null {};
Expand Down Expand Up @@ -1333,9 +1335,13 @@ class MakeValue : public Arg {
// uses char.
template <typename Char_>
MakeValue(const NamedArg<Char_> &value) { pointer = &value; }
template <typename Char_, typename T>
MakeValue(const NamedArgWithType<Char_, T> &value) { pointer = &value; }

template <typename Char_>
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>
Expand All @@ -1361,6 +1367,12 @@ struct NamedArg : Arg {
: 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 {
protected:
RuntimeError() : std::runtime_error("") {}
Expand Down Expand Up @@ -3342,13 +3354,13 @@ inline void format_decimal(char *&buffer, T value) {
\endrst
*/
template <typename T>
inline internal::NamedArg<char> arg(StringRef name, const T &arg) {
return internal::NamedArg<char>(name, arg);
inline internal::NamedArgWithType<char, T> arg(StringRef name, const T &arg) {
return internal::NamedArgWithType<char, T>(name, arg);
}

template <typename T>
inline internal::NamedArg<wchar_t> arg(WStringRef name, const T &arg) {
return internal::NamedArg<wchar_t>(name, arg);
inline internal::NamedArgWithType<wchar_t, T> arg(WStringRef name, const T &arg) {
return internal::NamedArgWithType<wchar_t, T>(name, arg);
}

// The following two functions are deleted intentionally to disable
Expand Down Expand Up @@ -3793,7 +3805,7 @@ struct UdlArg {
const Char *str;

template <typename T>
NamedArg<Char> operator=(T &&value) const {
NamedArgWithType<Char, T> operator=(T &&value) const {
return {str, std::forward<T>(value)};
}
};
Expand Down

0 comments on commit f66d37f

Please sign in to comment.