Commit f6f0415b authored by Victor Zverovich's avatar Victor Zverovich

typedef -> using

parent c92dc374
......@@ -506,12 +506,12 @@ struct chrono_formatter {
conditional_t<std::is_integral<Rep>::value && sizeof(Rep) < sizeof(int),
unsigned, typename make_unsigned_or_unchanged<Rep>::type>;
rep val;
typedef std::chrono::duration<rep> seconds;
using seconds = std::chrono::duration<rep>;
seconds s;
typedef std::chrono::duration<rep, std::milli> milliseconds;
using milliseconds = std::chrono::duration<rep, std::milli>;
bool negative;
typedef typename FormatContext::char_type char_type;
using char_type = typename FormatContext::char_type;
explicit chrono_formatter(FormatContext& ctx, OutputIt o,
std::chrono::duration<Rep, Period> d)
......@@ -717,11 +717,11 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
private:
basic_format_specs<Char> specs;
int precision;
typedef internal::arg_ref<Char> arg_ref_type;
using arg_ref_type = internal::arg_ref<Char>;
arg_ref_type width_ref;
arg_ref_type precision_ref;
mutable basic_string_view<Char> format_str;
typedef std::chrono::duration<Rep, Period> duration;
using duration = std::chrono::duration<Rep, Period>;
struct spec_handler {
formatter& f;
......@@ -759,7 +759,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
}
};
typedef typename basic_parse_context<Char>::iterator iterator;
using iterator = typename basic_parse_context<Char>::iterator;
struct parse_range {
iterator begin;
iterator end;
......
......@@ -78,7 +78,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) {
# define FMT_SNPRINTF fmt_snprintf
#endif // _MSC_VER
typedef void (*FormatFunc)(internal::buffer<char>&, int, string_view);
using format_func = void (*)(internal::buffer<char>&, int, string_view);
// Portable thread-safe version of strerror.
// Sets buffer to point to a string describing the error code.
......@@ -182,7 +182,7 @@ FMT_FUNC void fwrite_fully(const void* ptr, size_t size, size_t count,
}
}
FMT_FUNC void report_error(FormatFunc func, int error_code,
FMT_FUNC void report_error(format_func func, int error_code,
string_view message) FMT_NOEXCEPT {
memory_buffer full_message;
func(full_message, error_code, message);
......@@ -355,7 +355,7 @@ template <typename T> struct bits {
// A handmade floating-point number f * pow(2, e).
class fp {
private:
typedef uint64_t significand_type;
using significand_type = uint64_t;
// All sizes are in bits.
// Subtract 1 to account for an implicit most significant bit in the
......@@ -379,7 +379,7 @@ class fp {
// errors on platforms where double is not IEEE754.
template <typename Double> explicit fp(Double d) {
// Assume double is in the format [sign][exponent][significand].
typedef std::numeric_limits<Double> limits;
using limits = std::numeric_limits<Double>;
const int exponent_size =
bits<Double>::value - double_significand_size - 1; // -1 for sign
const uint64_t significand_mask = implicit_bit - 1;
......
......@@ -69,7 +69,7 @@ FMT_BEGIN_NAMESPACE
A reference to a null-terminated string. It can be constructed from a C
string or ``std::string``.
You can use one of the following typedefs for common character types:
You can use one of the following type aliases for common character types:
+---------------+-----------------------------+
| Type | Definition |
......@@ -108,8 +108,8 @@ template <typename Char> class basic_cstring_view {
const Char* c_str() const { return data_; }
};
typedef basic_cstring_view<char> cstring_view;
typedef basic_cstring_view<wchar_t> wcstring_view;
using cstring_view = basic_cstring_view<char>;
using wcstring_view = basic_cstring_view<wchar_t>;
// An error code.
class error_code {
......@@ -266,7 +266,7 @@ long getpagesize();
class Locale {
private:
# ifdef _MSC_VER
typedef _locale_t locale_t;
using locale_t = _locale_t;
enum { LC_NUMERIC_MASK = LC_NUMERIC };
......@@ -287,14 +287,14 @@ class Locale {
void operator=(const Locale&) = delete;
public:
typedef locale_t Type;
using type = locale_t;
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", nullptr)) {
if (!locale_) FMT_THROW(system_error(errno, "cannot create locale"));
}
~Locale() { freelocale(locale_); }
Type get() const { return locale_; }
type get() const { return locale_; }
// Converts string to floating-point number and advances str past the end
// of the parsed input.
......
......@@ -70,17 +70,17 @@ class is_zero_int {
template <typename T> struct make_unsigned_or_bool : std::make_unsigned<T> {};
template <> struct make_unsigned_or_bool<bool> { typedef bool type; };
template <> struct make_unsigned_or_bool<bool> { using type = bool; };
template <typename T, typename Context> class arg_converter {
private:
typedef typename Context::char_type Char;
using char_type = typename Context::char_type;
basic_format_arg<Context>& arg_;
typename Context::char_type type_;
char_type type_;
public:
arg_converter(basic_format_arg<Context>& arg, Char type)
arg_converter(basic_format_arg<Context>& arg, char_type type)
: arg_(arg), type_(type) {}
void operator()(bool value) {
......@@ -97,9 +97,9 @@ template <typename T, typename Context> class arg_converter {
arg_ = internal::make_arg<Context>(
static_cast<int>(static_cast<target_type>(value)));
} else {
typedef typename make_unsigned_or_bool<target_type>::type Unsigned;
using unsigned_type = typename make_unsigned_or_bool<target_type>::type;
arg_ = internal::make_arg<Context>(
static_cast<unsigned>(static_cast<Unsigned>(value)));
static_cast<unsigned>(static_cast<unsigned_type>(value)));
}
} else {
if (is_signed) {
......@@ -137,8 +137,8 @@ template <typename Context> class char_converter {
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
void operator()(T value) {
typedef typename Context::char_type Char;
arg_ = internal::make_arg<Context>(static_cast<Char>(value));
arg_ = internal::make_arg<Context>(
static_cast<typename Context::char_type>(value));
}
template <typename T, FMT_ENABLE_IF(!std::is_integral<T>::value)>
......@@ -149,7 +149,7 @@ template <typename Context> class char_converter {
// left alignment if it is negative.
template <typename Char> class printf_width_handler {
private:
typedef basic_format_specs<Char> format_specs;
using format_specs = basic_format_specs<Char>;
format_specs& specs_;
......@@ -203,12 +203,12 @@ template <typename OutputIt, typename Char> class basic_printf_context;
template <typename Range>
class printf_arg_formatter : public internal::arg_formatter_base<Range> {
public:
typedef decltype(std::declval<Range>().begin()) iterator;
using iterator = typename Range::iterator;
private:
typedef typename Range::value_type char_type;
typedef internal::arg_formatter_base<Range> base;
typedef basic_printf_context<iterator, char_type> context_type;
using char_type = typename Range::value_type;
using base = internal::arg_formatter_base<Range>;
using context_type = basic_printf_context<iterator, char_type>;
context_type& context_;
......@@ -223,7 +223,7 @@ class printf_arg_formatter : public internal::arg_formatter_base<Range> {
}
public:
typedef typename base::format_specs format_specs;
using format_specs = typename base::format_specs;
/**
\rst
......@@ -328,7 +328,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
template <typename T> using formatter_type = printf_formatter<T>;
private:
typedef basic_format_specs<char_type> format_specs;
using format_specs = basic_format_specs<char_type>;
OutputIt out_;
basic_format_args<basic_printf_context> args_;
......@@ -563,17 +563,15 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
return std::copy(start, it, out);
}
template <typename Buffer> struct basic_printf_context_t {
typedef basic_printf_context<std::back_insert_iterator<Buffer>,
typename Buffer::value_type>
type;
};
template <typename Char> using basic_printf_context_t =
basic_printf_context<std::back_insert_iterator<internal::buffer<Char>>,
Char>;
typedef basic_printf_context_t<internal::buffer<char>>::type printf_context;
typedef basic_printf_context_t<internal::buffer<wchar_t>>::type wprintf_context;
using printf_context = basic_printf_context_t<char>;
using wprintf_context = basic_printf_context_t<wchar_t>;
typedef basic_format_args<printf_context> printf_args;
typedef basic_format_args<wprintf_context> wprintf_args;
using printf_args = basic_format_args<printf_context>;
using wprintf_args = basic_format_args<wprintf_context>;
/**
\rst
......@@ -602,9 +600,7 @@ inline format_arg_store<wprintf_context, Args...> make_wprintf_args(
template <typename S, typename Char = char_t<S>>
inline std::basic_string<Char> vsprintf(
const S& format,
basic_format_args<
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_format_args<basic_printf_context_t<Char>> args) {
basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args);
return to_string(buffer);
......@@ -622,17 +618,14 @@ inline std::basic_string<Char> vsprintf(
template <typename S, typename... Args,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline std::basic_string<Char> sprintf(const S& format, const Args&... args) {
using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
return vsprintf(to_string_view(format), basic_format_args<context>(as));
using context = basic_printf_context_t<Char>;
return vsprintf(to_string_view(format), {make_format_args<context>(args...)});
}
template <typename S, typename Char = char_t<S>>
inline int vfprintf(
std::FILE* f, const S& format,
basic_format_args<
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_format_args<basic_printf_context_t<Char>> args) {
basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args);
std::size_t size = buffer.size();
......@@ -653,17 +646,15 @@ inline int vfprintf(
template <typename S, typename... Args,
typename Char = enable_if_t<internal::is_string<S>::value, char_t<S>>>
inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
return vfprintf(f, to_string_view(format), basic_format_args<context>(as));
using context = basic_printf_context_t<Char>;
return vfprintf(f, to_string_view(format),
{make_format_args<context>(args...)});
}
template <typename S, typename Char = char_t<S>>
inline int vprintf(
const S& format,
basic_format_args<
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_format_args<basic_printf_context_t<Char>> args) {
return vfprintf(stdout, to_string_view(format), args);
}
......@@ -679,18 +670,15 @@ inline int vprintf(
template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)>
inline int printf(const S& format_str, const Args&... args) {
using buffer = internal::buffer<char_t<S>>;
using context = typename basic_printf_context_t<buffer>::type;
format_arg_store<context, Args...> as{args...};
return vprintf(to_string_view(format_str), basic_format_args<context>(as));
using context = basic_printf_context_t<char_t<S>>;
return vprintf(to_string_view(format_str),
{make_format_args<context>(args...)});
}
template <typename S, typename Char = char_t<S>>
inline int vfprintf(
std::basic_ostream<Char>& os, const S& format,
basic_format_args<
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_format_args<basic_printf_context_t<Char>> args) {
basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args);
internal::write(os, buffer);
......@@ -721,10 +709,9 @@ typename ArgFormatter::iterator vprintf(internal::buffer<Char>& out,
template <typename S, typename... Args, typename Char = char_t<S>>
inline int fprintf(std::basic_ostream<Char>& os, const S& format_str,
const Args&... args) {
using context = typename basic_printf_context_t<internal::buffer<Char>>::type;
format_arg_store<context, Args...> as{args...};
using context = basic_printf_context_t<Char>;
return vfprintf(os, to_string_view(format_str),
basic_format_args<context>(as));
{make_format_args<context>(args...)});
}
FMT_END_NAMESPACE
......
......@@ -124,7 +124,7 @@ template <std::size_t N>
using make_index_sequence = std::make_index_sequence<N>;
#else
template <typename T, T... N> struct integer_sequence {
typedef T value_type;
using value_type = T;
static FMT_CONSTEXPR std::size_t size() { return sizeof...(N); }
};
......
......@@ -446,7 +446,7 @@ TEST(ScopedMock, Scope) {
#ifdef FMT_LOCALE
typedef fmt::Locale::Type LocaleType;
typedef fmt::Locale::type LocaleType;
struct LocaleMock {
static LocaleMock* instance;
......
......@@ -535,11 +535,11 @@ TEST(PrintfTest, VSPrintfMakeArgsExample) {
fmt::basic_format_args<fmt::printf_context> args2(as2);
EXPECT_EQ("[42] something happened",
fmt::vsprintf("[%d] %s happened", args2));
// the older gcc versions can't cast the return value
// The older gcc versions can't cast the return value.
#if !defined(__GNUC__) || (__GNUC__ > 4)
EXPECT_EQ("[42] something happened",
fmt::vsprintf("[%d] %s happened",
fmt::make_printf_args(42, "something")));
{fmt::make_printf_args(42, "something")}));
#endif
}
......@@ -557,7 +557,7 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
#if !defined(__GNUC__) || (__GNUC__ > 4)
EXPECT_EQ(L"[42] something happened",
fmt::vsprintf(L"[%d] %s happened",
fmt::make_wprintf_args(42, L"something")));
{fmt::make_wprintf_args(42, L"something")}));
#endif
}
......@@ -601,7 +601,7 @@ std::string custom_vformat(fmt::string_view format_str, format_args_t args) {
template <typename... Args>
std::string custom_format(const char* format_str, const Args&... args) {
auto va = fmt::make_printf_args(args...);
return custom_vformat(format_str, va);
return custom_vformat(format_str, {va});
}
TEST(PrintfTest, CustomFormat) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment