Skip to content

Commit

Permalink
libs: update fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Nov 2, 2024
1 parent 14ae95d commit 1e19aef
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 119 deletions.
58 changes: 41 additions & 17 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@
// Use the provided definition.
#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
# define FMT_USE_EXCEPTIONS 0
#elif defined(__clang__) && !defined(__cpp_exceptions)
# define FMT_USE_EXCEPTIONS 0
#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
# define FMT_USE_EXCEPTIONS 0
#else
Expand Down Expand Up @@ -851,7 +853,7 @@ template <typename Char = char> class parse_context {
using char_type = Char;
using iterator = const Char*;

explicit constexpr parse_context(basic_string_view<Char> fmt,
constexpr explicit parse_context(basic_string_view<Char> fmt,
int next_arg_id = 0)
: fmt_(fmt), next_arg_id_(next_arg_id) {}

Expand Down Expand Up @@ -1021,15 +1023,15 @@ template <typename Char, typename T> struct named_arg : view {
static_assert(!is_named_arg<T>::value, "nested named arguments");
};

template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }
template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
template <bool B = false> constexpr auto count() -> int { return B ? 1 : 0; }
template <bool B1, bool B2, bool... Tail> constexpr auto count() -> int {
return (B1 ? 1 : 0) + count<B2, Tail...>();
}

template <typename... Args> constexpr auto count_named_args() -> size_t {
template <typename... Args> constexpr auto count_named_args() -> int {
return count<is_named_arg<Args>::value...>();
}
template <typename... Args> constexpr auto count_static_named_args() -> size_t {
template <typename... Args> constexpr auto count_static_named_args() -> int {
return count<is_static_named_arg<Args>::value...>();
}

Expand Down Expand Up @@ -1189,7 +1191,7 @@ class compile_parse_context : public parse_context<Char> {
using base = parse_context<Char>;

public:
explicit FMT_CONSTEXPR compile_parse_context(basic_string_view<Char> fmt,
FMT_CONSTEXPR explicit compile_parse_context(basic_string_view<Char> fmt,
int num_args, const type* types,
int next_arg_id = 0)
: base(fmt, next_arg_id), num_args_(num_args), types_(types) {}
Expand Down Expand Up @@ -1645,7 +1647,7 @@ class format_string_checker {

public:
template <typename... T>
explicit FMT_CONSTEXPR format_string_checker(basic_string_view<Char> fmt,
FMT_CONSTEXPR explicit format_string_checker(basic_string_view<Char> fmt,
arg_pack<T...>)
: types_{mapped_type_constant<T, Char>::value...},
named_args_{},
Expand Down Expand Up @@ -1971,15 +1973,37 @@ template <typename T = char> class counting_buffer : public buffer<T> {
template <typename T>
struct is_back_insert_iterator<basic_appender<T>> : std::true_type {};

template <typename OutputIt, typename InputIt, typename = void>
struct has_back_insert_iterator_container_append : std::false_type {};
template <typename OutputIt, typename InputIt>
struct has_back_insert_iterator_container_append<
OutputIt, InputIt,
void_t<decltype(get_container(std::declval<OutputIt>())
.append(std::declval<InputIt>(),
std::declval<InputIt>()))>> : std::true_type {};

// An optimized version of std::copy with the output value type (T).
template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value&&
has_back_insert_iterator_container_append<
OutputIt, InputIt>::value)>
FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out)
-> OutputIt {
get_container(out).append(begin, end);
return out;
}

template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value &&
!has_back_insert_iterator_container_append<
OutputIt, InputIt>::value)>
FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out)
-> OutputIt {
auto& c = get_container(out);
c.insert(c.end(), begin, end);
return out;
}

template <typename T, typename InputIt, typename OutputIt,
FMT_ENABLE_IF(!is_back_insert_iterator<OutputIt>::value)>
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
Expand Down Expand Up @@ -2256,11 +2280,11 @@ constexpr auto make_descriptor() -> unsigned long long {
: is_unpacked_bit | NUM_ARGS;
}

template <typename Context, size_t NUM_ARGS>
template <typename Context, int NUM_ARGS>
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
basic_format_arg<Context>>;

template <typename Context, size_t NUM_ARGS, size_t NUM_NAMED_ARGS,
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS,
unsigned long long DESC>
struct named_arg_store {
// args_[0].named_args points to named_args to avoid bloating format_args.
Expand Down Expand Up @@ -2292,13 +2316,13 @@ struct named_arg_store {
// An array of references to arguments. It can be implicitly converted to
// `basic_format_args` for passing into type-erased formatting functions
// such as `vformat`. It is a plain struct to reduce binary size in debug mode.
template <typename Context, size_t NUM_ARGS, size_t NUM_NAMED_ARGS,
template <typename Context, int NUM_ARGS, int NUM_NAMED_ARGS,
unsigned long long DESC>
struct format_arg_store {
// +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
using type =
conditional_t<NUM_NAMED_ARGS == 0,
arg_t<Context, NUM_ARGS>[max_of<size_t>(1, NUM_ARGS)],
arg_t<Context, NUM_ARGS>[max_of(1, NUM_ARGS)],
named_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC>>;
type args;
};
Expand Down Expand Up @@ -2510,7 +2534,7 @@ template <typename Context> class basic_format_args {
return static_cast<detail::type>((desc_ >> shift) & mask);
}

template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC>
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC>
using store =
detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC>;

Expand All @@ -2520,14 +2544,14 @@ template <typename Context> class basic_format_args {
constexpr basic_format_args() : desc_(0), args_(nullptr) {}

/// Constructs a `basic_format_args` object from `format_arg_store`.
template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC,
FMT_ENABLE_IF(NUM_ARGS <= detail::max_packed_args)>
constexpr FMT_ALWAYS_INLINE basic_format_args(
const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
values_(s.args) {}

template <size_t NUM_ARGS, size_t NUM_NAMED_ARGS, unsigned long long DESC,
template <int NUM_ARGS, int NUM_NAMED_ARGS, unsigned long long DESC,
FMT_ENABLE_IF(NUM_ARGS > detail::max_packed_args)>
constexpr basic_format_args(const store<NUM_ARGS, NUM_NAMED_ARGS, DESC>& s)
: desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)),
Expand Down Expand Up @@ -2719,8 +2743,8 @@ struct formatter<T, Char,
// Take arguments by lvalue references to avoid some lifetime issues, e.g.
// auto args = make_format_args(std::string());
template <typename Context = context, typename... T,
size_t NUM_ARGS = sizeof...(T),
size_t NUM_NAMED_ARGS = detail::count_named_args<T...>(),
int NUM_ARGS = sizeof...(T),
int NUM_NAMED_ARGS = detail::count_named_args<T...>(),
unsigned long long DESC = detail::make_descriptor<Context, T...>()>
constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args)
-> detail::format_arg_store<Context, NUM_ARGS, NUM_NAMED_ARGS, DESC> {
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
template <typename Char, size_t N, fmt::detail::fixed_string<Char, N> Str>
struct udl_compiled_string : compiled_string {
using char_type = Char;
explicit constexpr operator basic_string_view<char_type>() const {
constexpr explicit operator basic_string_view<char_type>() const {
return {Str.data, N - 1};
}
};
Expand Down
Loading

0 comments on commit 1e19aef

Please sign in to comment.