Update <format>
This commit is contained in:
parent
df4ea0c76c
commit
09e2ac5e46
@ -38,14 +38,11 @@ namespace std {
|
|||||||
using format_parse_context = basic_format_parse_context<char>;
|
using format_parse_context = basic_format_parse_context<char>;
|
||||||
using wformat_parse_context = basic_format_parse_context<wchar_t>;
|
using wformat_parse_context = basic_format_parse_context<wchar_t>;
|
||||||
|
|
||||||
template<class O, class charT> FMT_REQUIRES(OutputIterator<O, const charT&>)
|
template<class Out, class charT> class basic_format_context;
|
||||||
class basic_format_context;
|
|
||||||
using format_context = basic_format_context<
|
using format_context = basic_format_context<
|
||||||
/* unspecified */ std::back_insert_iterator<fmt::internal::buffer<char>>,
|
/* unspecified */ std::back_insert_iterator<fmt::internal::buffer<char>>, char>;
|
||||||
char>;
|
|
||||||
using wformat_context = basic_format_context<
|
using wformat_context = basic_format_context<
|
||||||
/* unspecified */ std::back_insert_iterator<fmt::internal::buffer<wchar_t>>,
|
/* unspecified */ std::back_insert_iterator<fmt::internal::buffer<wchar_t>>, wchar_t>;
|
||||||
wchar_t>;
|
|
||||||
|
|
||||||
template<class T, class charT = char> struct formatter {
|
template<class T, class charT = char> struct formatter {
|
||||||
formatter() = delete;
|
formatter() = delete;
|
||||||
@ -63,8 +60,8 @@ namespace std {
|
|||||||
using format_args = basic_format_args<format_context>;
|
using format_args = basic_format_args<format_context>;
|
||||||
using wformat_args = basic_format_args<wformat_context>;
|
using wformat_args = basic_format_args<wformat_context>;
|
||||||
|
|
||||||
template<class O, class charT>
|
template<class Out, class charT>
|
||||||
using format_args_t = basic_format_args<basic_format_context<O, charT>>;
|
using format_args_t = basic_format_args<basic_format_context<Out, charT>>;
|
||||||
|
|
||||||
template<class Context = format_context, class... Args>
|
template<class Context = format_context, class... Args>
|
||||||
format_arg_store<Context, Args...>
|
format_arg_store<Context, Args...>
|
||||||
@ -82,27 +79,27 @@ namespace std {
|
|||||||
string vformat(string_view fmt, format_args args);
|
string vformat(string_view fmt, format_args args);
|
||||||
wstring vformat(wstring_view fmt, wformat_args args);
|
wstring vformat(wstring_view fmt, wformat_args args);
|
||||||
|
|
||||||
template<FMT_CONCEPT(OutputIterator<const char&>) O, class... Args>
|
template<class Out, class... Args>
|
||||||
O format_to(O out, string_view fmt, const Args&... args);
|
Out format_to(Out out, string_view fmt, const Args&... args);
|
||||||
template<FMT_CONCEPT(OutputIterator<const wchar_t&>) O, class... Args>
|
template<class Out, class... Args>
|
||||||
O format_to(O out, wstring_view fmt, const Args&... args);
|
Out format_to(Out out, wstring_view fmt, const Args&... args);
|
||||||
|
|
||||||
template<FMT_CONCEPT(OutputIterator<const char&>) O>
|
template<class Out>
|
||||||
O vformat_to(O out, string_view fmt, format_args_t<O, char> args);
|
Out vformat_to(Out out, string_view fmt, format_args_t<Out, char> args);
|
||||||
template<FMT_CONCEPT(OutputIterator<const wchar_t&>) O>
|
template<class Out>
|
||||||
O vformat_to(O out, wstring_view fmt, format_args_t<O, wchar_t> args);
|
Out vformat_to(Out out, wstring_view fmt, format_args_t<Out, wchar_t> args);
|
||||||
|
|
||||||
template<class O>
|
template<class Out>
|
||||||
struct format_to_n_result {
|
struct format_to_n_result {
|
||||||
O out;
|
Out out;
|
||||||
iter_difference_t<O> size;
|
iter_difference_t<Out> size;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<FMT_CONCEPT(OutputIterator<const char&>) O, class... Args>
|
template<class Out, class... Args>
|
||||||
format_to_n_result<O> format_to_n(O out, iter_difference_t<O> n,
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
||||||
string_view fmt, const Args&... args);
|
string_view fmt, const Args&... args);
|
||||||
template<FMT_CONCEPT(OutputIterator<const wchar_t&>) O, class... Args>
|
template<class Out, class... Args>
|
||||||
format_to_n_result<O> format_to_n(O out, iter_difference_t<O> n,
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
||||||
wstring_view fmt, const Args&... args);
|
wstring_view fmt, const Args&... args);
|
||||||
|
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
@ -229,6 +226,8 @@ template<class O, class charT>
|
|||||||
void basic_format_context<O, charT>::advance_to(typename basic_format_context<O, charT>::iterator it) { out_ = it; }
|
void basic_format_context<O, charT>::advance_to(typename basic_format_context<O, charT>::iterator it) { out_ = it; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
namespace detail {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr bool is_standard_integer_v =
|
constexpr bool is_standard_integer_v =
|
||||||
std::is_same_v<T, signed char> ||
|
std::is_same_v<T, signed char> ||
|
||||||
@ -245,6 +244,10 @@ constexpr bool is_standard_unsigned_integer_v =
|
|||||||
std::is_same_v<T, unsigned long int> ||
|
std::is_same_v<T, unsigned long int> ||
|
||||||
std::is_same_v<T, unsigned long long int>;
|
std::is_same_v<T, unsigned long long int>;
|
||||||
|
|
||||||
|
template <typename T, typename Char> struct formatter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// http://fmtlib.net/Text%20Formatting.html#format.arg
|
// http://fmtlib.net/Text%20Formatting.html#format.arg
|
||||||
namespace std {
|
namespace std {
|
||||||
template<class Context>
|
template<class Context>
|
||||||
@ -269,10 +272,11 @@ namespace std {
|
|||||||
std::is_same_v<I, bool> ||
|
std::is_same_v<I, bool> ||
|
||||||
std::is_same_v<I, char_type> ||
|
std::is_same_v<I, char_type> ||
|
||||||
(std::is_same_v<I, char> && std::is_same_v<char_type, wchar_t>) ||
|
(std::is_same_v<I, char> && std::is_same_v<char_type, wchar_t>) ||
|
||||||
is_standard_integer_v<I> ||
|
detail::is_standard_integer_v<I> ||
|
||||||
is_standard_unsigned_integer_v<I>
|
detail::is_standard_unsigned_integer_v<I> ||
|
||||||
|
is_default_constructible_v<typename Context::template formatter_type<I>>
|
||||||
>>
|
>>
|
||||||
explicit basic_format_arg(I n) noexcept; // exposition only
|
explicit basic_format_arg(const I& n) noexcept; // exposition only
|
||||||
explicit basic_format_arg(float n) noexcept; // exposition only
|
explicit basic_format_arg(float n) noexcept; // exposition only
|
||||||
explicit basic_format_arg(double n) noexcept; // exposition only
|
explicit basic_format_arg(double n) noexcept; // exposition only
|
||||||
explicit basic_format_arg(long double n) noexcept; // exposition only
|
explicit basic_format_arg(long double n) noexcept; // exposition only
|
||||||
@ -290,10 +294,6 @@ namespace std {
|
|||||||
template<class T, typename = std::enable_if_t<std::is_same_v<T, void>>>
|
template<class T, typename = std::enable_if_t<std::is_same_v<T, void>>>
|
||||||
explicit basic_format_arg(const T* p) noexcept; // exposition only
|
explicit basic_format_arg(const T* p) noexcept; // exposition only
|
||||||
|
|
||||||
template<class T, typename = std::enable_if_t<
|
|
||||||
!Integral<T> && is_default_constructible_v<typename Context::template formatter_type<T>>>>
|
|
||||||
explicit basic_format_arg(const T& v) noexcept; // exposition only
|
|
||||||
|
|
||||||
//template<class Visitor>
|
//template<class Visitor>
|
||||||
// friend auto std::visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
|
// friend auto std::visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
|
||||||
|
|
||||||
@ -301,6 +301,8 @@ namespace std {
|
|||||||
friend format_arg_store<Ctx, Args...>
|
friend format_arg_store<Ctx, Args...>
|
||||||
make_format_args(const Args&... args); // exposition only
|
make_format_args(const Args&... args); // exposition only
|
||||||
|
|
||||||
|
template <typename T, typename Char> friend struct detail::formatter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
basic_format_arg() noexcept;
|
basic_format_arg() noexcept;
|
||||||
|
|
||||||
@ -314,19 +316,21 @@ basic_format_arg<Context>::basic_format_arg() noexcept {}
|
|||||||
|
|
||||||
template<class Context>
|
template<class Context>
|
||||||
template<FMT_CONCEPT(Integral) I, typename>
|
template<FMT_CONCEPT(Integral) I, typename>
|
||||||
/* explicit */ basic_format_arg<Context>::basic_format_arg(I n) noexcept {
|
/* explicit */ basic_format_arg<Context>::basic_format_arg(const I& n) noexcept {
|
||||||
if (std::is_same_v<I, bool> || std::is_same_v<I, char_type>)
|
if constexpr (std::is_same_v<I, bool> || std::is_same_v<I, char_type>)
|
||||||
value = n;
|
value = n;
|
||||||
else if (std::is_same_v<I, char> && std::is_same_v<char_type, wchar_t>)
|
else if constexpr (std::is_same_v<I, char> && std::is_same_v<char_type, wchar_t>)
|
||||||
value = static_cast<wchar_t>(n);
|
value = static_cast<wchar_t>(n);
|
||||||
else if (is_standard_integer_v<I> && sizeof(I) <= sizeof(int))
|
else if constexpr (detail::is_standard_integer_v<I> && sizeof(I) <= sizeof(int))
|
||||||
value = static_cast<int>(n);
|
value = static_cast<int>(n);
|
||||||
else if (is_standard_unsigned_integer_v<I> && sizeof(I) <= sizeof(unsigned))
|
else if constexpr (detail::is_standard_unsigned_integer_v<I> && sizeof(I) <= sizeof(unsigned))
|
||||||
value = static_cast<unsigned>(n);
|
value = static_cast<unsigned>(n);
|
||||||
else if (is_standard_integer_v<I>)
|
else if constexpr (detail::is_standard_integer_v<I>)
|
||||||
value = static_cast<long long int>(n);
|
value = static_cast<long long int>(n);
|
||||||
else if (is_standard_unsigned_integer_v<I>)
|
else if constexpr (detail::is_standard_unsigned_integer_v<I>)
|
||||||
value = static_cast<unsigned long long int>(n);
|
value = static_cast<unsigned long long int>(n);
|
||||||
|
else if constexpr (is_default_constructible_v<typename Context::template formatter_type<I>>)
|
||||||
|
value = handle(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Context>
|
template<class Context>
|
||||||
@ -367,11 +371,6 @@ template<class Context>
|
|||||||
template<class T, typename> /* explicit */ basic_format_arg<Context>::basic_format_arg(const T* p) noexcept
|
template<class T, typename> /* explicit */ basic_format_arg<Context>::basic_format_arg(const T* p) noexcept
|
||||||
: value(p) {}
|
: value(p) {}
|
||||||
|
|
||||||
template<class Context>
|
|
||||||
template<class T, typename>
|
|
||||||
/* explicit */ basic_format_arg<Context>::basic_format_arg(const T& v) noexcept
|
|
||||||
: value(handle(v)) {}
|
|
||||||
|
|
||||||
template<class Context>
|
template<class Context>
|
||||||
/* explicit */ basic_format_arg<Context>::operator bool() const noexcept {
|
/* explicit */ basic_format_arg<Context>::operator bool() const noexcept {
|
||||||
return !holds_alternative<monostate>(value);
|
return !holds_alternative<monostate>(value);
|
||||||
@ -387,6 +386,8 @@ namespace std {
|
|||||||
|
|
||||||
template<class T> explicit handle(const T& val) noexcept; // exposition only
|
template<class T> explicit handle(const T& val) noexcept; // exposition only
|
||||||
|
|
||||||
|
friend class basic_format_arg<Context>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void format(basic_format_parse_context<char_type>&, Context& ctx) const;
|
void format(basic_format_parse_context<char_type>&, Context& ctx) const;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user