|
|
|
@ -22,27 +22,25 @@ FMT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
|
|
template <typename RangeT, typename OutputIterator>
|
|
|
|
|
OutputIterator copy(const RangeT& range, OutputIterator out) {
|
|
|
|
|
template <typename Range, typename OutputIt>
|
|
|
|
|
auto copy(const Range& range, OutputIt out) -> OutputIt {
|
|
|
|
|
for (auto it = range.begin(), end = range.end(); it != end; ++it)
|
|
|
|
|
*out++ = *it;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OutputIterator>
|
|
|
|
|
OutputIterator copy(const char* str, OutputIterator out) {
|
|
|
|
|
template <typename OutputIt>
|
|
|
|
|
auto copy(const char* str, OutputIt out) -> OutputIt {
|
|
|
|
|
while (*str) *out++ = *str++;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OutputIterator>
|
|
|
|
|
OutputIterator copy(char ch, OutputIterator out) {
|
|
|
|
|
template <typename OutputIt> auto copy(char ch, OutputIt out) -> OutputIt {
|
|
|
|
|
*out++ = ch;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OutputIterator>
|
|
|
|
|
OutputIterator copy(wchar_t ch, OutputIterator out) {
|
|
|
|
|
template <typename OutputIt> auto copy(wchar_t ch, OutputIt out) -> OutputIt {
|
|
|
|
|
*out++ = ch;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
@ -69,7 +67,7 @@ template <typename T> class is_map {
|
|
|
|
|
template <typename> static void check(...);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
#ifdef FMT_FORMAT_MAP_AS_LIST
|
|
|
|
|
#ifdef FMT_FORMAT_MAP_AS_LIST // DEPRECATED!
|
|
|
|
|
static constexpr const bool value = false;
|
|
|
|
|
#else
|
|
|
|
|
static constexpr const bool value =
|
|
|
|
@ -82,7 +80,7 @@ template <typename T> class is_set {
|
|
|
|
|
template <typename> static void check(...);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
#ifdef FMT_FORMAT_SET_AS_LIST
|
|
|
|
|
#ifdef FMT_FORMAT_SET_AS_LIST // DEPRECATED!
|
|
|
|
|
static constexpr const bool value = false;
|
|
|
|
|
#else
|
|
|
|
|
static constexpr const bool value =
|
|
|
|
@ -157,8 +155,9 @@ template <typename T>
|
|
|
|
|
struct has_mutable_begin_end<
|
|
|
|
|
T, void_t<decltype(detail::range_begin(std::declval<T>())),
|
|
|
|
|
decltype(detail::range_end(std::declval<T>())),
|
|
|
|
|
enable_if_t<std::is_copy_constructible<T>::value>>>
|
|
|
|
|
: std::true_type {};
|
|
|
|
|
// the extra int here is because older versions of MSVC don't
|
|
|
|
|
// SFINAE properly unless there are distinct types
|
|
|
|
|
int>> : std::true_type {};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct is_range_<T, void>
|
|
|
|
@ -211,41 +210,61 @@ class is_tuple_formattable_ {
|
|
|
|
|
static constexpr const bool value = false;
|
|
|
|
|
};
|
|
|
|
|
template <typename T, typename C> class is_tuple_formattable_<T, C, true> {
|
|
|
|
|
template <std::size_t... I>
|
|
|
|
|
static std::true_type check2(index_sequence<I...>,
|
|
|
|
|
integer_sequence<bool, (I == I)...>);
|
|
|
|
|
template <std::size_t... Is>
|
|
|
|
|
static std::true_type check2(index_sequence<Is...>,
|
|
|
|
|
integer_sequence<bool, (Is == Is)...>);
|
|
|
|
|
static std::false_type check2(...);
|
|
|
|
|
template <std::size_t... I>
|
|
|
|
|
template <std::size_t... Is>
|
|
|
|
|
static decltype(check2(
|
|
|
|
|
index_sequence<I...>{},
|
|
|
|
|
index_sequence<Is...>{},
|
|
|
|
|
integer_sequence<
|
|
|
|
|
bool, (is_formattable<typename std::tuple_element<I, T>::type,
|
|
|
|
|
C>::value)...>{})) check(index_sequence<I...>);
|
|
|
|
|
bool, (is_formattable<typename std::tuple_element<Is, T>::type,
|
|
|
|
|
C>::value)...>{})) check(index_sequence<Is...>);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static constexpr const bool value =
|
|
|
|
|
decltype(check(tuple_index_sequence<T>{}))::value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class Tuple, class F, size_t... Is>
|
|
|
|
|
void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) noexcept {
|
|
|
|
|
template <typename Tuple, typename F, size_t... Is>
|
|
|
|
|
FMT_CONSTEXPR void for_each(index_sequence<Is...>, Tuple&& t, F&& f) {
|
|
|
|
|
using std::get;
|
|
|
|
|
// using free function get<I>(T) now.
|
|
|
|
|
const int _[] = {0, ((void)f(get<Is>(tup)), 0)...};
|
|
|
|
|
(void)_; // blocks warnings
|
|
|
|
|
// Using a free function get<Is>(Tuple) now.
|
|
|
|
|
const int unused[] = {0, ((void)f(get<Is>(t)), 0)...};
|
|
|
|
|
ignore_unused(unused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Tuple, typename F>
|
|
|
|
|
FMT_CONSTEXPR void for_each(Tuple&& t, F&& f) {
|
|
|
|
|
for_each(tuple_index_sequence<remove_cvref_t<Tuple>>(),
|
|
|
|
|
std::forward<Tuple>(t), std::forward<F>(f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
FMT_CONSTEXPR make_index_sequence<std::tuple_size<T>::value> get_indexes(
|
|
|
|
|
T const&) {
|
|
|
|
|
return {};
|
|
|
|
|
template <typename Tuple1, typename Tuple2, typename F, size_t... Is>
|
|
|
|
|
void for_each2(index_sequence<Is...>, Tuple1&& t1, Tuple2&& t2, F&& f) {
|
|
|
|
|
using std::get;
|
|
|
|
|
const int unused[] = {0, ((void)f(get<Is>(t1), get<Is>(t2)), 0)...};
|
|
|
|
|
ignore_unused(unused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class Tuple, class F> void for_each(Tuple&& tup, F&& f) {
|
|
|
|
|
const auto indexes = get_indexes(tup);
|
|
|
|
|
for_each(indexes, std::forward<Tuple>(tup), std::forward<F>(f));
|
|
|
|
|
template <typename Tuple1, typename Tuple2, typename F>
|
|
|
|
|
void for_each2(Tuple1&& t1, Tuple2&& t2, F&& f) {
|
|
|
|
|
for_each2(tuple_index_sequence<remove_cvref_t<Tuple1>>(),
|
|
|
|
|
std::forward<Tuple1>(t1), std::forward<Tuple2>(t2),
|
|
|
|
|
std::forward<F>(f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace tuple {
|
|
|
|
|
// Workaround a bug in MSVC 2019 (v140).
|
|
|
|
|
template <typename Char, typename... T>
|
|
|
|
|
using result_t = std::tuple<formatter<remove_cvref_t<T>, Char>...>;
|
|
|
|
|
|
|
|
|
|
using std::get;
|
|
|
|
|
template <typename Tuple, typename Char, std::size_t... Is>
|
|
|
|
|
auto get_formatters(index_sequence<Is...>)
|
|
|
|
|
-> result_t<Char, decltype(get<Is>(std::declval<Tuple>()))...>;
|
|
|
|
|
} // namespace tuple
|
|
|
|
|
|
|
|
|
|
#if FMT_MSC_VERSION && FMT_MSC_VERSION < 1920
|
|
|
|
|
// Older MSVC doesn't get the reference type correctly for arrays.
|
|
|
|
|
template <typename R> struct range_reference_type_impl {
|
|
|
|
@ -269,45 +288,37 @@ using range_reference_type =
|
|
|
|
|
template <typename Range>
|
|
|
|
|
using uncvref_type = remove_cvref_t<range_reference_type<Range>>;
|
|
|
|
|
|
|
|
|
|
template <typename Range>
|
|
|
|
|
using uncvref_first_type = remove_cvref_t<
|
|
|
|
|
decltype(std::declval<range_reference_type<Range>>().first)>;
|
|
|
|
|
|
|
|
|
|
template <typename Range>
|
|
|
|
|
using uncvref_second_type = remove_cvref_t<
|
|
|
|
|
decltype(std::declval<range_reference_type<Range>>().second)>;
|
|
|
|
|
|
|
|
|
|
template <typename OutputIt> OutputIt write_delimiter(OutputIt out) {
|
|
|
|
|
*out++ = ',';
|
|
|
|
|
*out++ = ' ';
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename OutputIt>
|
|
|
|
|
auto write_range_entry(OutputIt out, basic_string_view<Char> str) -> OutputIt {
|
|
|
|
|
return write_escaped_string(out, str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename OutputIt, typename T,
|
|
|
|
|
FMT_ENABLE_IF(std::is_convertible<T, std_string_view<char>>::value)>
|
|
|
|
|
inline auto write_range_entry(OutputIt out, const T& str) -> OutputIt {
|
|
|
|
|
auto sv = std_string_view<Char>(str);
|
|
|
|
|
return write_range_entry<Char>(out, basic_string_view<Char>(sv));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename OutputIt, typename Arg,
|
|
|
|
|
FMT_ENABLE_IF(std::is_same<Arg, Char>::value)>
|
|
|
|
|
OutputIt write_range_entry(OutputIt out, const Arg v) {
|
|
|
|
|
return write_escaped_char(out, v);
|
|
|
|
|
template <typename Formatter>
|
|
|
|
|
FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set)
|
|
|
|
|
-> decltype(f.set_debug_format(set)) {
|
|
|
|
|
f.set_debug_format(set);
|
|
|
|
|
}
|
|
|
|
|
template <typename Formatter>
|
|
|
|
|
FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {}
|
|
|
|
|
|
|
|
|
|
// These are not generic lambdas for compatibility with C++11.
|
|
|
|
|
template <typename ParseContext> struct parse_empty_specs {
|
|
|
|
|
template <typename Formatter> FMT_CONSTEXPR void operator()(Formatter& f) {
|
|
|
|
|
f.parse(ctx);
|
|
|
|
|
detail::maybe_set_debug_format(f, true);
|
|
|
|
|
}
|
|
|
|
|
ParseContext& ctx;
|
|
|
|
|
};
|
|
|
|
|
template <typename FormatContext> struct format_tuple_element {
|
|
|
|
|
using char_type = typename FormatContext::char_type;
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
void operator()(const formatter<T, char_type>& f, const T& v) {
|
|
|
|
|
if (i > 0)
|
|
|
|
|
ctx.advance_to(detail::copy_str<char_type>(separator, ctx.out()));
|
|
|
|
|
ctx.advance_to(f.format(v, ctx));
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename Char, typename OutputIt, typename Arg,
|
|
|
|
|
FMT_ENABLE_IF(!is_std_string_like<typename std::decay<Arg>::type>::value &&
|
|
|
|
|
!std::is_same<Arg, Char>::value)>
|
|
|
|
|
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
|
|
|
|
return write<Char>(out, v);
|
|
|
|
|
}
|
|
|
|
|
int i;
|
|
|
|
|
FormatContext& ctx;
|
|
|
|
|
basic_string_view<char_type> separator;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
@ -321,45 +332,58 @@ template <typename T, typename C> struct is_tuple_formattable {
|
|
|
|
|
detail::is_tuple_formattable_<T, C>::value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename TupleT, typename Char>
|
|
|
|
|
struct formatter<TupleT, Char,
|
|
|
|
|
enable_if_t<fmt::is_tuple_like<TupleT>::value &&
|
|
|
|
|
fmt::is_tuple_formattable<TupleT, Char>::value>> {
|
|
|
|
|
template <typename Tuple, typename Char>
|
|
|
|
|
struct formatter<Tuple, Char,
|
|
|
|
|
enable_if_t<fmt::is_tuple_like<Tuple>::value &&
|
|
|
|
|
fmt::is_tuple_formattable<Tuple, Char>::value>> {
|
|
|
|
|
private:
|
|
|
|
|
// C++11 generic lambda for format().
|
|
|
|
|
template <typename FormatContext> struct format_each {
|
|
|
|
|
template <typename T> void operator()(const T& v) {
|
|
|
|
|
if (i > 0) out = detail::write_delimiter(out);
|
|
|
|
|
out = detail::write_range_entry<Char>(out, v);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
int i;
|
|
|
|
|
typename FormatContext::iterator& out;
|
|
|
|
|
};
|
|
|
|
|
decltype(detail::tuple::get_formatters<Tuple, Char>(
|
|
|
|
|
detail::tuple_index_sequence<Tuple>())) formatters_;
|
|
|
|
|
|
|
|
|
|
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{};
|
|
|
|
|
basic_string_view<Char> opening_bracket_ =
|
|
|
|
|
detail::string_literal<Char, '('>{};
|
|
|
|
|
basic_string_view<Char> closing_bracket_ =
|
|
|
|
|
detail::string_literal<Char, ')'>{};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FMT_CONSTEXPR formatter() {}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) {
|
|
|
|
|
separator_ = sep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open,
|
|
|
|
|
basic_string_view<Char> close) {
|
|
|
|
|
opening_bracket_ = open;
|
|
|
|
|
closing_bracket_ = close;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename ParseContext>
|
|
|
|
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
|
|
|
|
return ctx.begin();
|
|
|
|
|
auto it = ctx.begin();
|
|
|
|
|
if (it != ctx.end() && *it != '}')
|
|
|
|
|
FMT_THROW(format_error("invalid format specifier"));
|
|
|
|
|
detail::for_each(formatters_, detail::parse_empty_specs<ParseContext>{ctx});
|
|
|
|
|
return it;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename FormatContext = format_context>
|
|
|
|
|
auto format(const TupleT& values, FormatContext& ctx) const
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
auto format(const Tuple& value, FormatContext& ctx) const
|
|
|
|
|
-> decltype(ctx.out()) {
|
|
|
|
|
auto out = ctx.out();
|
|
|
|
|
*out++ = '(';
|
|
|
|
|
detail::for_each(values, format_each<FormatContext>{0, out});
|
|
|
|
|
*out++ = ')';
|
|
|
|
|
return out;
|
|
|
|
|
ctx.advance_to(detail::copy_str<Char>(opening_bracket_, ctx.out()));
|
|
|
|
|
detail::for_each2(
|
|
|
|
|
formatters_, value,
|
|
|
|
|
detail::format_tuple_element<FormatContext>{0, ctx, separator_});
|
|
|
|
|
return detail::copy_str<Char>(closing_bracket_, ctx.out());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char> struct is_range {
|
|
|
|
|
static constexpr const bool value =
|
|
|
|
|
detail::is_range_<T>::value && !detail::is_std_string_like<T>::value &&
|
|
|
|
|
!detail::is_map<T>::value &&
|
|
|
|
|
!std::is_convertible<T, std::basic_string<Char>>::value &&
|
|
|
|
|
!std::is_constructible<detail::std_string_view<Char>, T>::value;
|
|
|
|
|
!std::is_convertible<T, detail::std_string_view<Char>>::value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
@ -380,127 +404,172 @@ template <typename Context> struct range_mapper {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename Element>
|
|
|
|
|
using range_formatter_type = conditional_t<
|
|
|
|
|
is_formattable<Element, Char>::value,
|
|
|
|
|
using range_formatter_type =
|
|
|
|
|
formatter<remove_cvref_t<decltype(range_mapper<buffer_context<Char>>{}.map(
|
|
|
|
|
std::declval<Element>()))>,
|
|
|
|
|
Char>,
|
|
|
|
|
fallback_formatter<Element, Char>>;
|
|
|
|
|
Char>;
|
|
|
|
|
|
|
|
|
|
template <typename R>
|
|
|
|
|
using maybe_const_range =
|
|
|
|
|
conditional_t<has_const_begin_end<R>::value, const R, R>;
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
// Workaround a bug in MSVC 2015 and earlier.
|
|
|
|
|
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910
|
|
|
|
|
template <typename R, typename Char>
|
|
|
|
|
struct formatter<
|
|
|
|
|
R, Char,
|
|
|
|
|
enable_if_t<
|
|
|
|
|
conjunction<fmt::is_range<R, Char>
|
|
|
|
|
// Workaround a bug in MSVC 2017 and earlier.
|
|
|
|
|
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920
|
|
|
|
|
,
|
|
|
|
|
disjunction<
|
|
|
|
|
is_formattable<detail::uncvref_type<detail::maybe_const_range<R>>,
|
|
|
|
|
Char>,
|
|
|
|
|
detail::has_fallback_formatter<
|
|
|
|
|
detail::uncvref_type<detail::maybe_const_range<R>>, Char>
|
|
|
|
|
>
|
|
|
|
|
struct is_formattable_delayed
|
|
|
|
|
: is_formattable<uncvref_type<maybe_const_range<R>>, Char> {};
|
|
|
|
|
#endif
|
|
|
|
|
>::value
|
|
|
|
|
>> {
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
using range_type = detail::maybe_const_range<R>;
|
|
|
|
|
using formatter_type =
|
|
|
|
|
detail::range_formatter_type<Char, detail::uncvref_type<range_type>>;
|
|
|
|
|
formatter_type underlying_;
|
|
|
|
|
bool custom_specs_ = false;
|
|
|
|
|
template <typename T, typename Char, typename Enable = void>
|
|
|
|
|
struct range_formatter;
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char>
|
|
|
|
|
struct range_formatter<
|
|
|
|
|
T, Char,
|
|
|
|
|
enable_if_t<conjunction<std::is_same<T, remove_cvref_t<T>>,
|
|
|
|
|
is_formattable<T, Char>>::value>> {
|
|
|
|
|
private:
|
|
|
|
|
detail::range_formatter_type<Char, T> underlying_;
|
|
|
|
|
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{};
|
|
|
|
|
basic_string_view<Char> opening_bracket_ =
|
|
|
|
|
detail::string_literal<Char, '['>{};
|
|
|
|
|
basic_string_view<Char> closing_bracket_ =
|
|
|
|
|
detail::string_literal<Char, ']'>{};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FMT_CONSTEXPR range_formatter() {}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type<Char, T>& {
|
|
|
|
|
return underlying_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void set_separator(basic_string_view<Char> sep) {
|
|
|
|
|
separator_ = sep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void set_brackets(basic_string_view<Char> open,
|
|
|
|
|
basic_string_view<Char> close) {
|
|
|
|
|
opening_bracket_ = open;
|
|
|
|
|
closing_bracket_ = close;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename ParseContext>
|
|
|
|
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
|
|
|
|
auto it = ctx.begin();
|
|
|
|
|
auto end = ctx.end();
|
|
|
|
|
if (it == end || *it == '}') return it;
|
|
|
|
|
|
|
|
|
|
if (*it != ':')
|
|
|
|
|
FMT_THROW(format_error("no top-level range formatters supported"));
|
|
|
|
|
if (it != end && *it == 'n') {
|
|
|
|
|
set_brackets({}, {});
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (it != end && *it != '}') {
|
|
|
|
|
if (*it != ':') FMT_THROW(format_error("invalid format specifier"));
|
|
|
|
|
++it;
|
|
|
|
|
} else {
|
|
|
|
|
detail::maybe_set_debug_format(underlying_, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
custom_specs_ = true;
|
|
|
|
|
++it;
|
|
|
|
|
ctx.advance_to(it);
|
|
|
|
|
return underlying_.parse(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
auto format(range_type& range, FormatContext& ctx) const
|
|
|
|
|
-> decltype(ctx.out()) {
|
|
|
|
|
Char prefix = detail::is_set<R>::value ? '{' : '[';
|
|
|
|
|
Char postfix = detail::is_set<R>::value ? '}' : ']';
|
|
|
|
|
template <typename R, typename FormatContext>
|
|
|
|
|
auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
|
|
|
|
|
detail::range_mapper<buffer_context<Char>> mapper;
|
|
|
|
|
auto out = ctx.out();
|
|
|
|
|
*out++ = prefix;
|
|
|
|
|
out = detail::copy_str<Char>(opening_bracket_, out);
|
|
|
|
|
int i = 0;
|
|
|
|
|
auto it = detail::range_begin(range);
|
|
|
|
|
auto end = detail::range_end(range);
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (i > 0) out = detail::write_delimiter(out);
|
|
|
|
|
if (custom_specs_) {
|
|
|
|
|
ctx.advance_to(out);
|
|
|
|
|
out = underlying_.format(mapper.map(*it), ctx);
|
|
|
|
|
} else {
|
|
|
|
|
out = detail::write_range_entry<Char>(out, *it);
|
|
|
|
|
}
|
|
|
|
|
if (i > 0) out = detail::copy_str<Char>(separator_, out);
|
|
|
|
|
ctx.advance_to(out);
|
|
|
|
|
out = underlying_.format(mapper.map(*it), ctx);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
*out++ = postfix;
|
|
|
|
|
out = detail::copy_str<Char>(closing_bracket_, out);
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char>
|
|
|
|
|
struct formatter<
|
|
|
|
|
T, Char,
|
|
|
|
|
enable_if_t<conjunction<detail::is_map<T>
|
|
|
|
|
// Workaround a bug in MSVC 2017 and earlier.
|
|
|
|
|
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920
|
|
|
|
|
,
|
|
|
|
|
disjunction<
|
|
|
|
|
is_formattable<detail::uncvref_first_type<T>, Char>,
|
|
|
|
|
detail::has_fallback_formatter<detail::uncvref_first_type<T>, Char>
|
|
|
|
|
>,
|
|
|
|
|
disjunction<
|
|
|
|
|
is_formattable<detail::uncvref_second_type<T>, Char>,
|
|
|
|
|
detail::has_fallback_formatter<detail::uncvref_second_type<T>, Char>
|
|
|
|
|
>
|
|
|
|
|
#endif
|
|
|
|
|
>::value
|
|
|
|
|
>> {
|
|
|
|
|
enum class range_format { disabled, map, set, sequence, string, debug_string };
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct range_format_kind_
|
|
|
|
|
: std::integral_constant<range_format,
|
|
|
|
|
std::is_same<uncvref_type<T>, T>::value
|
|
|
|
|
? range_format::disabled
|
|
|
|
|
: is_map<T>::value ? range_format::map
|
|
|
|
|
: is_set<T>::value ? range_format::set
|
|
|
|
|
: range_format::sequence> {};
|
|
|
|
|
|
|
|
|
|
template <range_format K, typename R, typename Char, typename Enable = void>
|
|
|
|
|
struct range_default_formatter;
|
|
|
|
|
|
|
|
|
|
template <range_format K>
|
|
|
|
|
using range_format_constant = std::integral_constant<range_format, K>;
|
|
|
|
|
|
|
|
|
|
template <range_format K, typename R, typename Char>
|
|
|
|
|
struct range_default_formatter<
|
|
|
|
|
K, R, Char,
|
|
|
|
|
enable_if_t<(K == range_format::sequence || K == range_format::map ||
|
|
|
|
|
K == range_format::set)>> {
|
|
|
|
|
using range_type = detail::maybe_const_range<R>;
|
|
|
|
|
range_formatter<detail::uncvref_type<range_type>, Char> underlying_;
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR range_default_formatter() { init(range_format_constant<K>()); }
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void init(range_format_constant<range_format::set>) {
|
|
|
|
|
underlying_.set_brackets(detail::string_literal<Char, '{'>{},
|
|
|
|
|
detail::string_literal<Char, '}'>{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void init(range_format_constant<range_format::map>) {
|
|
|
|
|
underlying_.set_brackets(detail::string_literal<Char, '{'>{},
|
|
|
|
|
detail::string_literal<Char, '}'>{});
|
|
|
|
|
underlying_.underlying().set_brackets({}, {});
|
|
|
|
|
underlying_.underlying().set_separator(
|
|
|
|
|
detail::string_literal<Char, ':', ' '>{});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_CONSTEXPR void init(range_format_constant<range_format::sequence>) {}
|
|
|
|
|
|
|
|
|
|
template <typename ParseContext>
|
|
|
|
|
FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
|
|
|
|
return ctx.begin();
|
|
|
|
|
return underlying_.parse(ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <
|
|
|
|
|
typename FormatContext, typename U,
|
|
|
|
|
FMT_ENABLE_IF(
|
|
|
|
|
std::is_same<U, conditional_t<detail::has_const_begin_end<T>::value,
|
|
|
|
|
const T, T>>::value)>
|
|
|
|
|
auto format(U& map, FormatContext& ctx) const -> decltype(ctx.out()) {
|
|
|
|
|
auto out = ctx.out();
|
|
|
|
|
*out++ = '{';
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (const auto& item : map) {
|
|
|
|
|
if (i > 0) out = detail::write_delimiter(out);
|
|
|
|
|
out = detail::write_range_entry<Char>(out, item.first);
|
|
|
|
|
*out++ = ':';
|
|
|
|
|
*out++ = ' ';
|
|
|
|
|
out = detail::write_range_entry<Char>(out, item.second);
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
*out++ = '}';
|
|
|
|
|
return out;
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
auto format(range_type& range, FormatContext& ctx) const
|
|
|
|
|
-> decltype(ctx.out()) {
|
|
|
|
|
return underlying_.format(range, ctx);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char, typename Enable = void>
|
|
|
|
|
struct range_format_kind
|
|
|
|
|
: conditional_t<
|
|
|
|
|
is_range<T, Char>::value, detail::range_format_kind_<T>,
|
|
|
|
|
std::integral_constant<range_format, range_format::disabled>> {};
|
|
|
|
|
|
|
|
|
|
template <typename R, typename Char>
|
|
|
|
|
struct formatter<
|
|
|
|
|
R, Char,
|
|
|
|
|
enable_if_t<conjunction<bool_constant<range_format_kind<R, Char>::value !=
|
|
|
|
|
range_format::disabled>
|
|
|
|
|
// Workaround a bug in MSVC 2015 and earlier.
|
|
|
|
|
#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910
|
|
|
|
|
,
|
|
|
|
|
detail::is_formattable_delayed<R, Char>
|
|
|
|
|
#endif
|
|
|
|
|
>::value>>
|
|
|
|
|
: detail::range_default_formatter<range_format_kind<R, Char>::value, R,
|
|
|
|
|
Char> {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename... T> struct tuple_join_view : detail::view {
|
|
|
|
|
const std::tuple<T...>& tuple;
|
|
|
|
@ -510,9 +579,6 @@ template <typename Char, typename... T> struct tuple_join_view : detail::view {
|
|
|
|
|
: tuple(t), sep{s} {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename Char, typename... T>
|
|
|
|
|
using tuple_arg_join = tuple_join_view<Char, T...>;
|
|
|
|
|
|
|
|
|
|
// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers
|
|
|
|
|
// support in tuple_join. It is disabled by default because of issues with
|
|
|
|
|
// the dynamic width and precision.
|
|
|
|
@ -582,7 +648,42 @@ struct formatter<tuple_join_view<Char, T...>, Char> {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FMT_MODULE_EXPORT_BEGIN
|
|
|
|
|
namespace detail {
|
|
|
|
|
// Check if T has an interface like a container adaptor (e.g. std::stack,
|
|
|
|
|
// std::queue, std::priority_queue).
|
|
|
|
|
template <typename T> class is_container_adaptor_like {
|
|
|
|
|
template <typename U> static auto check(U* p) -> typename U::container_type;
|
|
|
|
|
template <typename> static void check(...);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static constexpr const bool value =
|
|
|
|
|
!std::is_void<decltype(check<T>(nullptr))>::value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename Container> struct all {
|
|
|
|
|
const Container& c;
|
|
|
|
|
auto begin() const -> typename Container::const_iterator { return c.begin(); }
|
|
|
|
|
auto end() const -> typename Container::const_iterator { return c.end(); }
|
|
|
|
|
};
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
|
|
template <typename T, typename Char>
|
|
|
|
|
struct formatter<T, Char,
|
|
|
|
|
enable_if_t<detail::is_container_adaptor_like<T>::value>>
|
|
|
|
|
: formatter<detail::all<typename T::container_type>, Char> {
|
|
|
|
|
using all = detail::all<typename T::container_type>;
|
|
|
|
|
template <typename FormatContext>
|
|
|
|
|
auto format(const T& t, FormatContext& ctx) const -> decltype(ctx.out()) {
|
|
|
|
|
struct getter : T {
|
|
|
|
|
static auto get(const T& t) -> all {
|
|
|
|
|
return {t.*(&getter::c)}; // Access c through the derived class.
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return formatter<all>::format(getter::get(t), ctx);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FMT_BEGIN_EXPORT
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
\rst
|
|
|
|
@ -625,7 +726,7 @@ auto join(std::initializer_list<T> list, string_view sep)
|
|
|
|
|
return join(std::begin(list), std::end(list), sep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FMT_MODULE_EXPORT_END
|
|
|
|
|
FMT_END_EXPORT
|
|
|
|
|
FMT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
#endif // FMT_RANGES_H_
|
|
|
|
|