mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Cleanup ranges formatting
This commit is contained in:
@ -22,27 +22,25 @@ FMT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename RangeT, typename OutputIterator>
|
template <typename Range, typename OutputIt>
|
||||||
OutputIterator copy(const RangeT& range, OutputIterator out) {
|
auto copy(const Range& range, OutputIt out) -> OutputIt {
|
||||||
for (auto it = range.begin(), end = range.end(); it != end; ++it)
|
for (auto it = range.begin(), end = range.end(); it != end; ++it)
|
||||||
*out++ = *it;
|
*out++ = *it;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename OutputIterator>
|
template <typename OutputIt>
|
||||||
OutputIterator copy(const char* str, OutputIterator out) {
|
auto copy(const char* str, OutputIt out) -> OutputIt {
|
||||||
while (*str) *out++ = *str++;
|
while (*str) *out++ = *str++;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename OutputIterator>
|
template <typename OutputIt> auto copy(char ch, OutputIt out) -> OutputIt {
|
||||||
OutputIterator copy(char ch, OutputIterator out) {
|
|
||||||
*out++ = ch;
|
*out++ = ch;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename OutputIterator>
|
template <typename OutputIt> auto copy(wchar_t ch, OutputIt out) -> OutputIt {
|
||||||
OutputIterator copy(wchar_t ch, OutputIterator out) {
|
|
||||||
*out++ = ch;
|
*out++ = ch;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -69,7 +67,7 @@ template <typename T> class is_map {
|
|||||||
template <typename> static void check(...);
|
template <typename> static void check(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef FMT_FORMAT_MAP_AS_LIST
|
#ifdef FMT_FORMAT_MAP_AS_LIST // DEPRECATED!
|
||||||
static constexpr const bool value = false;
|
static constexpr const bool value = false;
|
||||||
#else
|
#else
|
||||||
static constexpr const bool value =
|
static constexpr const bool value =
|
||||||
@ -82,7 +80,7 @@ template <typename T> class is_set {
|
|||||||
template <typename> static void check(...);
|
template <typename> static void check(...);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef FMT_FORMAT_SET_AS_LIST
|
#ifdef FMT_FORMAT_SET_AS_LIST // DEPRECATED!
|
||||||
static constexpr const bool value = false;
|
static constexpr const bool value = false;
|
||||||
#else
|
#else
|
||||||
static constexpr const bool value =
|
static constexpr const bool value =
|
||||||
@ -230,14 +228,14 @@ template <typename T, typename C> class is_tuple_formattable_<T, C, true> {
|
|||||||
template <class Tuple, class F, size_t... Is>
|
template <class Tuple, class F, size_t... Is>
|
||||||
void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) noexcept {
|
void for_each(index_sequence<Is...>, Tuple&& tup, F&& f) noexcept {
|
||||||
using std::get;
|
using std::get;
|
||||||
// using free function get<I>(T) now.
|
// Using free function get<I>(T) now.
|
||||||
const int _[] = {0, ((void)f(get<Is>(tup)), 0)...};
|
const int unused[] = {0, ((void)f(get<Is>(tup)), 0)...};
|
||||||
(void)_; // blocks warnings
|
(void)unused;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
FMT_CONSTEXPR make_index_sequence<std::tuple_size<T>::value> get_indexes(
|
FMT_CONSTEXPR auto get_indexes(T const&)
|
||||||
T const&) {
|
-> make_index_sequence<std::tuple_size<T>::value> {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,18 +293,18 @@ inline auto write_range_entry(OutputIt out, const T& str) -> OutputIt {
|
|||||||
return write_range_entry<Char>(out, basic_string_view<Char>(sv));
|
return write_range_entry<Char>(out, basic_string_view<Char>(sv));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt, typename Arg,
|
template <typename Char, typename OutputIt, typename T,
|
||||||
FMT_ENABLE_IF(std::is_same<Arg, Char>::value)>
|
FMT_ENABLE_IF(std::is_same<T, Char>::value)>
|
||||||
OutputIt write_range_entry(OutputIt out, const Arg v) {
|
auto write_range_entry(OutputIt out, T value) -> OutputIt {
|
||||||
return write_escaped_char(out, v);
|
return write_escaped_char(out, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename Char, typename OutputIt, typename Arg,
|
typename Char, typename OutputIt, typename T,
|
||||||
FMT_ENABLE_IF(!is_std_string_like<typename std::decay<Arg>::type>::value &&
|
FMT_ENABLE_IF(!is_std_string_like<typename std::decay<T>::type>::value &&
|
||||||
!std::is_same<Arg, Char>::value)>
|
!std::is_same<T, Char>::value)>
|
||||||
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
auto write_range_entry(OutputIt out, const T& value) -> OutputIt {
|
||||||
return write<Char>(out, v);
|
return write<Char>(out, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@ -321,10 +319,10 @@ template <typename T, typename C> struct is_tuple_formattable {
|
|||||||
detail::is_tuple_formattable_<T, C>::value;
|
detail::is_tuple_formattable_<T, C>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename TupleT, typename Char>
|
template <typename Tuple, typename Char>
|
||||||
struct formatter<TupleT, Char,
|
struct formatter<Tuple, Char,
|
||||||
enable_if_t<fmt::is_tuple_like<TupleT>::value &&
|
enable_if_t<fmt::is_tuple_like<Tuple>::value &&
|
||||||
fmt::is_tuple_formattable<TupleT, Char>::value>> {
|
fmt::is_tuple_formattable<Tuple, Char>::value>> {
|
||||||
private:
|
private:
|
||||||
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{};
|
basic_string_view<Char> separator_ = detail::string_literal<Char, ',', ' '>{};
|
||||||
basic_string_view<Char> opening_bracket_ =
|
basic_string_view<Char> opening_bracket_ =
|
||||||
@ -363,11 +361,10 @@ struct formatter<TupleT, Char,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext = format_context>
|
template <typename FormatContext = format_context>
|
||||||
auto format(const TupleT& values, FormatContext& ctx) const
|
auto format(const Tuple& value, FormatContext& ctx) const
|
||||||
-> decltype(ctx.out()) {
|
-> decltype(ctx.out()) {
|
||||||
auto out = ctx.out();
|
auto out = detail::copy_str<Char>(opening_bracket_, ctx.out());
|
||||||
out = detail::copy_str<Char>(opening_bracket_, out);
|
detail::for_each(value, format_each<FormatContext>{0, out, separator_});
|
||||||
detail::for_each(values, format_each<FormatContext>{0, out, separator_});
|
|
||||||
out = detail::copy_str<Char>(closing_bracket_, out);
|
out = detail::copy_str<Char>(closing_bracket_, out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -594,9 +591,6 @@ template <typename Char, typename... T> struct tuple_join_view : detail::view {
|
|||||||
: tuple(t), sep{s} {}
|
: 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
|
// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers
|
||||||
// support in tuple_join. It is disabled by default because of issues with
|
// support in tuple_join. It is disabled by default because of issues with
|
||||||
// the dynamic width and precision.
|
// the dynamic width and precision.
|
||||||
|
Reference in New Issue
Block a user