Remove <utility> dependency and replace typedefs with using
This commit is contained in:
parent
94edb1a71c
commit
faaafc7e12
@ -31,10 +31,10 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#ifdef __has_feature
|
#ifdef __has_feature
|
||||||
# define FMT_HAS_FEATURE(x) __has_feature(x)
|
# define FMT_HAS_FEATURE(x) __has_feature(x)
|
||||||
@ -223,8 +223,8 @@ class basic_string_view {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef basic_string_view<char> string_view;
|
using string_view = basic_string_view<char>;
|
||||||
typedef basic_string_view<wchar_t> wstring_view;
|
using wstring_view = basic_string_view<wchar_t>;
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
@ -255,8 +255,8 @@ inline void require_wchar() {
|
|||||||
"formatting of wide characters into a narrow output is disallowed");
|
"formatting of wide characters into a narrow output is disallowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef char yes[1];
|
using yes = char[1];
|
||||||
typedef char no[2];
|
using no = char[2];
|
||||||
|
|
||||||
yes &convert(unsigned long long);
|
yes &convert(unsigned long long);
|
||||||
no &convert(...);
|
no &convert(...);
|
||||||
@ -389,7 +389,7 @@ struct string_value {
|
|||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
struct custom_value {
|
struct custom_value {
|
||||||
typedef void (*format_func)(
|
using format_func = void (*)(
|
||||||
basic_buffer<typename Context::char_type> &buffer,
|
basic_buffer<typename Context::char_type> &buffer,
|
||||||
const void *arg, Context &ctx);
|
const void *arg, Context &ctx);
|
||||||
|
|
||||||
@ -672,15 +672,28 @@ inline typename std::enable_if<!IS_PACKED, basic_arg<Context>>::type
|
|||||||
return make_arg<Context>(value);
|
return make_arg<Context>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Context>
|
||||||
|
struct named_arg : basic_arg<Context> {
|
||||||
|
typedef typename Context::char_type Char;
|
||||||
|
|
||||||
|
basic_string_view<Char> name;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
named_arg(basic_string_view<Char> argname, const T &value)
|
||||||
|
: basic_arg<Context>(make_arg<Context>(value)), name(argname) {}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
class arg_map {
|
class arg_map {
|
||||||
private:
|
private:
|
||||||
typedef typename Context::char_type Char;
|
using Char = typename Context::char_type;
|
||||||
typedef std::vector<
|
|
||||||
std::pair<fmt::basic_string_view<Char>, basic_arg<Context> > > MapType;
|
|
||||||
typedef typename MapType::value_type Pair;
|
|
||||||
|
|
||||||
MapType map_;
|
struct arg {
|
||||||
|
fmt::basic_string_view<Char> name;
|
||||||
|
basic_arg<Context> value;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<arg> map_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void init(const basic_format_args<Context> &args);
|
void init(const basic_format_args<Context> &args);
|
||||||
@ -688,10 +701,9 @@ class arg_map {
|
|||||||
const basic_arg<Context>
|
const basic_arg<Context>
|
||||||
*find(const fmt::basic_string_view<Char> &name) const {
|
*find(const fmt::basic_string_view<Char> &name) const {
|
||||||
// The list is unsorted, so just return the first matching name.
|
// The list is unsorted, so just return the first matching name.
|
||||||
for (typename MapType::const_iterator it = map_.begin(), end = map_.end();
|
for (auto it = map_.begin(), end = map_.end(); it != end; ++it) {
|
||||||
it != end; ++it) {
|
if (it->name == name)
|
||||||
if (it->first == name)
|
return &it->value;
|
||||||
return &it->second;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -703,7 +715,7 @@ class context_base : public basic_parse_context<Char>{
|
|||||||
basic_format_args<Context> args_;
|
basic_format_args<Context> args_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef basic_arg<Context> format_arg;
|
using format_arg = basic_arg<Context>;
|
||||||
|
|
||||||
context_base(basic_string_view<Char> format_str,
|
context_base(basic_string_view<Char> format_str,
|
||||||
basic_format_args<Context> args)
|
basic_format_args<Context> args)
|
||||||
@ -747,9 +759,9 @@ class basic_context :
|
|||||||
|
|
||||||
FMT_DISALLOW_COPY_AND_ASSIGN(basic_context);
|
FMT_DISALLOW_COPY_AND_ASSIGN(basic_context);
|
||||||
|
|
||||||
typedef internal::context_base<Char, basic_context<Char>> Base;
|
using Base = internal::context_base<Char, basic_context<Char>>;
|
||||||
|
|
||||||
typedef typename Base::format_arg format_arg;
|
using format_arg = typename Base::format_arg;
|
||||||
using Base::get_arg;
|
using Base::get_arg;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -779,13 +791,11 @@ class arg_store {
|
|||||||
// Packed is a macro on MinGW so use IS_PACKED instead.
|
// Packed is a macro on MinGW so use IS_PACKED instead.
|
||||||
static const bool IS_PACKED = NUM_ARGS < internal::MAX_PACKED_ARGS;
|
static const bool IS_PACKED = NUM_ARGS < internal::MAX_PACKED_ARGS;
|
||||||
|
|
||||||
typedef typename Context::char_type char_type;
|
using value_type = typename std::conditional<IS_PACKED,
|
||||||
|
internal::value<Context>, basic_arg<Context>>::type;
|
||||||
typedef typename std::conditional<IS_PACKED,
|
|
||||||
internal::value<Context>, basic_arg<Context>>::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.
|
||||||
typedef std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)> Array;
|
using Array = std::array<value_type, NUM_ARGS + (IS_PACKED ? 0 : 1)>;
|
||||||
Array data_;
|
Array data_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -812,8 +822,8 @@ inline arg_store<context, Args...> make_args(const Args & ... args) {
|
|||||||
template <typename Context>
|
template <typename Context>
|
||||||
class basic_format_args {
|
class basic_format_args {
|
||||||
public:
|
public:
|
||||||
typedef unsigned size_type;
|
using size_type = unsigned;
|
||||||
typedef basic_arg<Context> format_arg;
|
using format_arg = basic_arg<Context> ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// To reduce compiled code size per formatting function call, types of first
|
// To reduce compiled code size per formatting function call, types of first
|
||||||
@ -875,8 +885,37 @@ class basic_format_args {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef basic_format_args<context> format_args;
|
using format_args = basic_format_args<context>;
|
||||||
typedef basic_format_args<wcontext> wformat_args;
|
using wformat_args = basic_format_args<wcontext>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
\rst
|
||||||
|
Returns a named argument for formatting functions.
|
||||||
|
|
||||||
|
**Example**::
|
||||||
|
|
||||||
|
print("Elapsed time: {s:.2f} seconds", arg("s", 1.23));
|
||||||
|
|
||||||
|
\endrst
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
inline internal::named_arg<context> arg(string_view name, const T &arg) {
|
||||||
|
return internal::named_arg<context>(name, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline internal::named_arg<wcontext> arg(wstring_view name, const T &arg) {
|
||||||
|
return internal::named_arg<wcontext>(name, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The following two functions are deleted intentionally to disable
|
||||||
|
// nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``.
|
||||||
|
template <typename Context>
|
||||||
|
void arg(string_view, const internal::named_arg<Context>&)
|
||||||
|
FMT_DELETED_OR_UNDEFINED;
|
||||||
|
template <typename Context>
|
||||||
|
void arg(wstring_view, const internal::named_arg<Context>&)
|
||||||
|
FMT_DELETED_OR_UNDEFINED;
|
||||||
|
|
||||||
enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
enum Color { BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE };
|
||||||
|
|
||||||
@ -942,8 +981,7 @@ FMT_API void vprint(std::FILE *f, string_view format_str, format_args args);
|
|||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline void print(std::FILE *f, string_view format_str,
|
inline void print(std::FILE *f, string_view format_str, const Args & ... args) {
|
||||||
const Args & ... args) {
|
|
||||||
vprint(f, format_str, make_args(args...));
|
vprint(f, format_str, make_args(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,20 +919,6 @@ constexpr typename std::result_of<Visitor(int)>::type
|
|||||||
return typename std::result_of<Visitor(int)>::type();
|
return typename std::result_of<Visitor(int)>::type();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
template <typename Context>
|
|
||||||
struct named_arg : basic_arg<Context> {
|
|
||||||
typedef typename Context::char_type Char;
|
|
||||||
|
|
||||||
basic_string_view<Char> name;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
named_arg(basic_string_view<Char> argname, const T &value)
|
|
||||||
: basic_arg<Context>(make_arg<Context>(value)), name(argname) {}
|
|
||||||
};
|
|
||||||
} // namespace internal
|
|
||||||
|
|
||||||
enum alignment {
|
enum alignment {
|
||||||
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_NUMERIC
|
||||||
};
|
};
|
||||||
@ -1195,7 +1181,7 @@ void arg_map<Context>::init(const basic_format_args<Context> &args) {
|
|||||||
return;
|
return;
|
||||||
case internal::NAMED_ARG:
|
case internal::NAMED_ARG:
|
||||||
named_arg = static_cast<const NamedArg*>(args.values_[i].pointer);
|
named_arg = static_cast<const NamedArg*>(args.values_[i].pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(arg{named_arg->name, *named_arg});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break; // Do nothing.
|
break; // Do nothing.
|
||||||
@ -1207,7 +1193,7 @@ void arg_map<Context>::init(const basic_format_args<Context> &args) {
|
|||||||
internal::type arg_type = args.type(i);
|
internal::type arg_type = args.type(i);
|
||||||
if (arg_type == internal::NAMED_ARG) {
|
if (arg_type == internal::NAMED_ARG) {
|
||||||
named_arg = static_cast<const NamedArg*>(args.args_[i].value_.pointer);
|
named_arg = static_cast<const NamedArg*>(args.args_[i].value_.pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(arg{named_arg->name, *named_arg});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned i = MAX_PACKED_ARGS; ; ++i) {
|
for (unsigned i = MAX_PACKED_ARGS; ; ++i) {
|
||||||
@ -1216,7 +1202,7 @@ void arg_map<Context>::init(const basic_format_args<Context> &args) {
|
|||||||
return;
|
return;
|
||||||
case internal::NAMED_ARG:
|
case internal::NAMED_ARG:
|
||||||
named_arg = static_cast<const NamedArg*>(args.args_[i].value_.pointer);
|
named_arg = static_cast<const NamedArg*>(args.args_[i].value_.pointer);
|
||||||
map_.push_back(Pair(named_arg->name, *named_arg));
|
map_.push_back(arg{named_arg->name, *named_arg});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break; // Do nothing.
|
break; // Do nothing.
|
||||||
@ -2869,35 +2855,6 @@ inline void format_decimal(char *&buffer, T value) {
|
|||||||
buffer += num_digits;
|
buffer += num_digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
\rst
|
|
||||||
Returns a named argument for formatting functions.
|
|
||||||
|
|
||||||
**Example**::
|
|
||||||
|
|
||||||
print("Elapsed time: {s:.2f} seconds", arg("s", 1.23));
|
|
||||||
|
|
||||||
\endrst
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
inline internal::named_arg<context> arg(string_view name, const T &arg) {
|
|
||||||
return internal::named_arg<context>(name, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline internal::named_arg<wcontext> arg(wstring_view name, const T &arg) {
|
|
||||||
return internal::named_arg<wcontext>(name, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following two functions are deleted intentionally to disable
|
|
||||||
// nested named arguments as in ``format("{}", arg("a", arg("b", 42)))``.
|
|
||||||
template <typename Context>
|
|
||||||
void arg(string_view, const internal::named_arg<Context>&)
|
|
||||||
FMT_DELETED_OR_UNDEFINED;
|
|
||||||
template <typename Context>
|
|
||||||
void arg(wstring_view, const internal::named_arg<Context>&)
|
|
||||||
FMT_DELETED_OR_UNDEFINED;
|
|
||||||
|
|
||||||
// Formatter of objects of type T.
|
// Formatter of objects of type T.
|
||||||
template <typename T, typename Char>
|
template <typename T, typename Char>
|
||||||
struct formatter<
|
struct formatter<
|
||||||
|
Loading…
Reference in New Issue
Block a user