Skip to content

Commit

Permalink
Bump fmt version to 6.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed May 26, 2020
1 parent 0317731 commit bc61f69
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
25 changes: 16 additions & 9 deletions include/spdlog/fmt/bundled/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <vector>

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 60200
#define FMT_VERSION 60201

#ifdef __has_feature
# define FMT_HAS_FEATURE(x) __has_feature(x)
Expand Down Expand Up @@ -830,7 +830,8 @@ template <typename Char> struct string_value {
template <typename Context> struct custom_value {
using parse_context = basic_format_parse_context<typename Context::char_type>;
const void* value;
void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx);
void (*format)(const void* arg,
typename Context::parse_context_type& parse_ctx, Context& ctx);
};

// A formatting argument value.
Expand Down Expand Up @@ -890,9 +891,9 @@ template <typename Context> class value {
private:
// Formats an argument of a custom type, such as a user-defined class.
template <typename T, typename Formatter>
static void format_custom_arg(
const void* arg, basic_format_parse_context<char_type>& parse_ctx,
Context& ctx) {
static void format_custom_arg(const void* arg,
typename Context::parse_context_type& parse_ctx,
Context& ctx) {
Formatter f;
parse_ctx.advance_to(f.parse(parse_ctx));
ctx.advance_to(f.format(*static_cast<const T*>(arg), ctx));
Expand Down Expand Up @@ -1061,7 +1062,7 @@ template <typename Context> class basic_format_arg {
public:
explicit handle(internal::custom_value<Context> custom) : custom_(custom) {}

void format(basic_format_parse_context<char_type>& parse_ctx,
void format(typename Context::parse_context_type& parse_ctx,
Context& ctx) const {
custom_.format(custom_.value, parse_ctx, ctx);
}
Expand Down Expand Up @@ -1207,13 +1208,16 @@ FMT_CONSTEXPR basic_format_arg<Context> make_arg(const T& value) {
return arg;
}

template <bool IS_PACKED, typename Context, typename T,
// The type template parameter is there to avoid an ODR violation when using
// a fallback formatter in one translation unit and an implicit conversion in
// another (not recommended).
template <bool IS_PACKED, typename Context, type, typename T,
FMT_ENABLE_IF(IS_PACKED)>
inline value<Context> make_arg(const T& val) {
return arg_mapper<Context>().map(val);
}

template <bool IS_PACKED, typename Context, typename T,
template <bool IS_PACKED, typename Context, type, typename T,
FMT_ENABLE_IF(!IS_PACKED)>
inline basic_format_arg<Context> make_arg(const T& value) {
return make_arg<Context>(value);
Expand Down Expand Up @@ -1272,6 +1276,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
public:
using iterator = OutputIt;
using format_arg = basic_format_arg<basic_format_context>;
using parse_context_type = basic_format_parse_context<Char>;
template <typename T> using formatter_type = formatter<T, char_type>;

basic_format_context(const basic_format_context&) = delete;
Expand Down Expand Up @@ -1346,7 +1351,9 @@ class format_arg_store
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
basic_format_args<Context>(*this),
#endif
data_{internal::make_arg<is_packed, Context>(args)...} {
data_{internal::make_arg<
is_packed, Context,
internal::mapped_type_constant<Args, Context>::value>(args)...} {
}
};

Expand Down
33 changes: 28 additions & 5 deletions include/spdlog/fmt/bundled/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
#define FMT_OSTREAM_H_

#include <ostream>

#include "format.h"

FMT_BEGIN_NAMESPACE

template <typename CHar> class basic_printf_parse_context;
template <typename OutputIt, typename Char> class basic_printf_context;

namespace internal {

template <class Char> class formatbuf : public std::basic_streambuf<Char> {
Expand Down Expand Up @@ -93,9 +98,9 @@ void format_value(buffer<Char>& buf, const T& value,
locale_ref loc = locale_ref()) {
formatbuf<Char> format_buf(buf);
std::basic_ostream<Char> output(&format_buf);
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
if (loc) output.imbue(loc.get<std::locale>());
#endif
#endif
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
output << value;
buf.resize(buf.size());
Expand All @@ -104,14 +109,32 @@ void format_value(buffer<Char>& buf, const T& value,
// Formats an object of type T that has an overloaded ostream operator<<.
template <typename T, typename Char>
struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
: formatter<basic_string_view<Char>, Char> {
template <typename Context>
auto format(const T& value, Context& ctx) -> decltype(ctx.out()) {
: private formatter<basic_string_view<Char>, Char> {
auto parse(basic_format_parse_context<Char>& ctx) -> decltype(ctx.begin()) {
return formatter<basic_string_view<Char>, Char>::parse(ctx);
}
template <typename ParseCtx,
FMT_ENABLE_IF(std::is_same<
ParseCtx, basic_printf_parse_context<Char>>::value)>
auto parse(ParseCtx& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}

template <typename OutputIt>
auto format(const T& value, basic_format_context<OutputIt, Char>& ctx)
-> OutputIt {
basic_memory_buffer<Char> buffer;
format_value(buffer, value, ctx.locale());
basic_string_view<Char> str(buffer.data(), buffer.size());
return formatter<basic_string_view<Char>, Char>::format(str, ctx);
}
template <typename OutputIt>
auto format(const T& value, basic_printf_context<OutputIt, Char>& ctx)
-> OutputIt {
basic_memory_buffer<Char> buffer;
format_value(buffer, value, ctx.locale());
return std::copy(buffer.begin(), buffer.end(), ctx.out());
}
};
} // namespace internal

Expand Down
9 changes: 7 additions & 2 deletions include/spdlog/fmt/bundled/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ using internal::printf; // For printing into memory_buffer.

template <typename Range> class printf_arg_formatter;

template <typename Char>
class basic_printf_parse_context : public basic_format_parse_context<Char> {
using basic_format_parse_context<Char>::basic_format_parse_context;
};
template <typename OutputIt, typename Char> class basic_printf_context;

/**
Expand Down Expand Up @@ -324,14 +328,15 @@ template <typename OutputIt, typename Char> class basic_printf_context {
using char_type = Char;
using iterator = OutputIt;
using format_arg = basic_format_arg<basic_printf_context>;
using parse_context_type = basic_printf_parse_context<Char>;
template <typename T> using formatter_type = printf_formatter<T>;

private:
using format_specs = basic_format_specs<char_type>;

OutputIt out_;
basic_format_args<basic_printf_context> args_;
basic_format_parse_context<Char> parse_ctx_;
parse_context_type parse_ctx_;

static void parse_flags(format_specs& specs, const Char*& it,
const Char* end);
Expand Down Expand Up @@ -362,7 +367,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {

format_arg arg(int id) const { return args_.get(id); }

basic_format_parse_context<Char>& parse_context() { return parse_ctx_; }
parse_context_type& parse_context() { return parse_ctx_; }

FMT_CONSTEXPR void on_error(const char* message) {
parse_ctx_.on_error(message);
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

#define SPDLOG_VER_MAJOR 1
#define SPDLOG_VER_MINOR 6
#define SPDLOG_VER_PATCH 0
#define SPDLOG_VER_PATCH 1

#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)

0 comments on commit bc61f69

Please sign in to comment.