2020-11-26 18:12:18 +00:00
|
|
|
// -*- C++ -*-
|
2021-11-17 21:25:01 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-11-26 18:12:18 +00:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_FORMAT
|
|
|
|
#define _LIBCPP_FORMAT
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
namespace std {
|
2020-12-05 10:45:21 +00:00
|
|
|
// [format.context], class template basic_format_context
|
|
|
|
template<class Out, class charT>
|
|
|
|
class basic_format_context {
|
|
|
|
basic_format_args<basic_format_context> args_; // exposition only
|
|
|
|
Out out_; // exposition only
|
|
|
|
|
|
|
|
public:
|
|
|
|
using iterator = Out;
|
|
|
|
using char_type = charT;
|
|
|
|
template<class T> using formatter_type = formatter<T, charT>;
|
|
|
|
|
|
|
|
basic_format_arg<basic_format_context> arg(size_t id) const;
|
|
|
|
std::locale locale();
|
|
|
|
|
|
|
|
iterator out();
|
|
|
|
void advance_to(iterator it);
|
|
|
|
};
|
|
|
|
using format_context = basic_format_context<unspecified, char>;
|
|
|
|
using wformat_context = basic_format_context<unspecified, wchar_t>;
|
|
|
|
|
|
|
|
// [format.args], class template basic_format_args
|
|
|
|
template<class Context>
|
|
|
|
class basic_format_args {
|
|
|
|
size_t size_; // exposition only
|
|
|
|
const basic_format_arg<Context>* data_; // exposition only
|
|
|
|
|
|
|
|
public:
|
|
|
|
basic_format_args() noexcept;
|
|
|
|
|
|
|
|
template<class... Args>
|
|
|
|
basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
|
|
|
|
|
|
|
|
basic_format_arg<Context> get(size_t i) const noexcept;
|
|
|
|
};
|
|
|
|
using format_args = basic_format_args<format_context>;
|
|
|
|
using wformat_args = basic_format_args<wformat_context>;
|
|
|
|
|
|
|
|
|
2020-12-19 12:52:07 +00:00
|
|
|
// [format.functions], formatting functions
|
|
|
|
template<class... Args>
|
|
|
|
string format(string_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
wstring format(wstring_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
string format(const locale& loc, string_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
wstring format(const locale& loc, wstring_view fmt, const Args&... args);
|
|
|
|
|
|
|
|
string vformat(string_view fmt, format_args args);
|
|
|
|
wstring vformat(wstring_view fmt, wformat_args args);
|
|
|
|
string vformat(const locale& loc, string_view fmt, format_args args);
|
|
|
|
wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
|
|
|
|
|
|
|
|
template<class Out, class... Args>
|
|
|
|
Out format_to(Out out, string_view fmt, const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
Out format_to(Out out, wstring_view fmt, const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
Out format_to(Out out, const locale& loc, string_view fmt, const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
Out format_to(Out out, const locale& loc, wstring_view fmt, const Args&... args);
|
|
|
|
|
|
|
|
template<class Out>
|
2021-09-04 11:26:58 +00:00
|
|
|
Out vformat_to(Out out, string_view fmt, format_args args);
|
2020-12-19 12:52:07 +00:00
|
|
|
template<class Out>
|
2021-09-04 11:26:58 +00:00
|
|
|
Out vformat_to(Out out, wstring_view fmt, wformat_args args);
|
2020-12-19 12:52:07 +00:00
|
|
|
template<class Out>
|
|
|
|
Out vformat_to(Out out, const locale& loc, string_view fmt,
|
2021-09-04 11:26:58 +00:00
|
|
|
format_args char> args);
|
2020-12-19 12:52:07 +00:00
|
|
|
template<class Out>
|
|
|
|
Out vformat_to(Out out, const locale& loc, wstring_view fmt,
|
2021-09-04 11:26:58 +00:00
|
|
|
wformat_args args);
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template<class Out> struct format_to_n_result {
|
|
|
|
Out out;
|
|
|
|
iter_difference_t<Out> size;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Out, class... Args>
|
|
|
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
|
|
|
string_view fmt, const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
|
|
|
wstring_view fmt, const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
|
|
|
const locale& loc, string_view fmt,
|
|
|
|
const Args&... args);
|
|
|
|
template<class Out, class... Args>
|
|
|
|
format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
|
|
|
|
const locale& loc, wstring_view fmt,
|
|
|
|
const Args&... args);
|
|
|
|
|
|
|
|
template<class... Args>
|
|
|
|
size_t formatted_size(string_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
size_t formatted_size(wstring_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
size_t formatted_size(const locale& loc, string_view fmt, const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
size_t formatted_size(const locale& loc, wstring_view fmt, const Args&... args);
|
|
|
|
|
|
|
|
// [format.formatter], formatter
|
|
|
|
template<> struct formatter<char, char>;
|
|
|
|
template<> struct formatter<char, wchar_t>;
|
|
|
|
template<> struct formatter<wchar_t, wchar_t>;
|
|
|
|
|
|
|
|
template<> struct formatter<charT*, charT>;
|
|
|
|
template<> struct formatter<const charT*, charT>;
|
|
|
|
template<size_t N> struct formatter<const charT[N], charT>;
|
|
|
|
template<class traits, class Allocator>
|
|
|
|
struct formatter<basic_string<charT, traits, Allocator>, charT>;
|
|
|
|
template<class traits>
|
|
|
|
struct formatter<basic_string_view<charT, traits>, charT>;
|
|
|
|
|
2020-12-05 10:45:21 +00:00
|
|
|
// [format.parse.ctx], class template basic_format_parse_context
|
|
|
|
template<class charT>
|
|
|
|
class basic_format_parse_context {
|
|
|
|
public:
|
|
|
|
using char_type = charT;
|
|
|
|
using const_iterator = typename basic_string_view<charT>::const_iterator;
|
|
|
|
using iterator = const_iterator;
|
|
|
|
|
|
|
|
private:
|
|
|
|
iterator begin_; // exposition only
|
|
|
|
iterator end_; // exposition only
|
|
|
|
enum indexing { unknown, manual, automatic }; // exposition only
|
|
|
|
indexing indexing_; // exposition only
|
|
|
|
size_t next_arg_id_; // exposition only
|
|
|
|
size_t num_args_; // exposition only
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
|
|
|
|
size_t num_args = 0) noexcept;
|
|
|
|
basic_format_parse_context(const basic_format_parse_context&) = delete;
|
|
|
|
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
|
|
|
|
|
|
|
|
constexpr const_iterator begin() const noexcept;
|
|
|
|
constexpr const_iterator end() const noexcept;
|
|
|
|
constexpr void advance_to(const_iterator it);
|
|
|
|
|
|
|
|
constexpr size_t next_arg_id();
|
|
|
|
constexpr void check_arg_id(size_t id);
|
|
|
|
};
|
|
|
|
using format_parse_context = basic_format_parse_context<char>;
|
|
|
|
using wformat_parse_context = basic_format_parse_context<wchar_t>;
|
|
|
|
|
|
|
|
// [format.arguments], arguments
|
|
|
|
// [format.arg], class template basic_format_arg
|
|
|
|
template<class Context>
|
|
|
|
class basic_format_arg {
|
|
|
|
public:
|
|
|
|
class handle;
|
|
|
|
|
|
|
|
private:
|
|
|
|
using char_type = typename Context::char_type; // exposition only
|
|
|
|
|
|
|
|
variant<monostate, bool, char_type,
|
|
|
|
int, unsigned int, long long int, unsigned long long int,
|
|
|
|
float, double, long double,
|
|
|
|
const char_type*, basic_string_view<char_type>,
|
|
|
|
const void*, handle> value; // exposition only
|
|
|
|
|
|
|
|
template<class T> explicit basic_format_arg(const T& v) 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(long double n) noexcept; // exposition only
|
|
|
|
explicit basic_format_arg(const char_type* s); // exposition only
|
|
|
|
|
|
|
|
template<class traits>
|
|
|
|
explicit basic_format_arg(
|
|
|
|
basic_string_view<char_type, traits> s) noexcept; // exposition only
|
|
|
|
|
|
|
|
template<class traits, class Allocator>
|
|
|
|
explicit basic_format_arg(
|
|
|
|
const basic_string<char_type, traits, Allocator>& s) noexcept; // exposition only
|
|
|
|
|
|
|
|
explicit basic_format_arg(nullptr_t) noexcept; // exposition only
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
explicit basic_format_arg(const T* p) noexcept; // exposition only
|
|
|
|
|
|
|
|
public:
|
|
|
|
basic_format_arg() noexcept;
|
|
|
|
|
|
|
|
explicit operator bool() const noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Visitor, class Context>
|
|
|
|
see below visit_format_arg(Visitor&& vis, basic_format_arg<Context> arg);
|
|
|
|
|
|
|
|
// [format.arg.store], class template format-arg-store
|
|
|
|
template<class Context, class... Args>
|
|
|
|
struct format-arg-store { // exposition only
|
|
|
|
array<basic_format_arg<Context>, sizeof...(Args)> args;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Context = format_context, class... Args>
|
|
|
|
format-arg-store<Context, Args...>
|
|
|
|
make_format_args(const Args&... args);
|
|
|
|
template<class... Args>
|
|
|
|
format-arg-store<wformat_context, Args...>
|
|
|
|
make_wformat_args(const Args&... args);
|
|
|
|
|
2020-11-26 18:12:18 +00:00
|
|
|
// [format.error], class format_error
|
|
|
|
class format_error : public runtime_error {
|
|
|
|
public:
|
|
|
|
explicit format_error(const string& what_arg);
|
|
|
|
explicit format_error(const char* what_arg);
|
|
|
|
};
|
2021-02-02 17:10:33 +00:00
|
|
|
|
|
|
|
// [format.parse.ctx], class template basic_format_parse_context
|
|
|
|
template<class charT>
|
|
|
|
class basic_format_parse_context {
|
|
|
|
public:
|
|
|
|
using char_type = charT;
|
|
|
|
using const_iterator = typename basic_string_view<charT>::const_iterator;
|
|
|
|
using iterator = const_iterator;
|
|
|
|
|
|
|
|
private:
|
|
|
|
iterator begin_; // exposition only
|
|
|
|
iterator end_; // exposition only
|
|
|
|
enum indexing { unknown, manual, automatic }; // exposition only
|
|
|
|
indexing indexing_; // exposition only
|
|
|
|
size_t next_arg_id_; // exposition only
|
|
|
|
size_t num_args_; // exposition only
|
|
|
|
|
|
|
|
public:
|
|
|
|
constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt,
|
|
|
|
size_t num_args = 0) noexcept;
|
|
|
|
basic_format_parse_context(const basic_format_parse_context&) = delete;
|
|
|
|
basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
|
|
|
|
|
|
|
|
constexpr const_iterator begin() const noexcept;
|
|
|
|
constexpr const_iterator end() const noexcept;
|
|
|
|
constexpr void advance_to(const_iterator it);
|
|
|
|
|
|
|
|
constexpr size_t next_arg_id();
|
|
|
|
constexpr void check_arg_id(size_t id);
|
|
|
|
};
|
|
|
|
using format_parse_context = basic_format_parse_context<char>;
|
|
|
|
using wformat_parse_context = basic_format_parse_context<wchar_t>;
|
2020-11-26 18:12:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2021-08-11 15:33:54 +00:00
|
|
|
// Make sure all feature-test macros are available.
|
2021-07-30 18:35:37 +00:00
|
|
|
#include <version>
|
2021-08-11 15:33:54 +00:00
|
|
|
// Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
|
2021-07-30 18:35:37 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
|
|
|
|
|
2020-11-26 18:12:18 +00:00
|
|
|
#include <__config>
|
2020-12-19 12:52:07 +00:00
|
|
|
#include <__debug>
|
2020-12-05 10:45:21 +00:00
|
|
|
#include <__format/format_arg.h>
|
|
|
|
#include <__format/format_args.h>
|
|
|
|
#include <__format/format_context.h>
|
2021-04-25 15:58:03 +00:00
|
|
|
#include <__format/format_error.h>
|
[libc++][format] Adds integer formatter.
Implements the formatter for all fundamental integer types
(except `char`, `wchar_t`, and `bool`).
[format.formatter.spec]/2.3
For each charT, for each cv-unqualified arithmetic type ArithmeticT other
than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
```
template<> struct formatter<ArithmeticT, charT>;
```
This removes the stub implemented in D96664.
As an extension it adds partial support for 128-bit integer types.
Implements parts of:
- P0645 Text Formatting
- P1652 Printf corner cases in std::format
Completes:
- LWG-3248 #b, #B, #o, #x, and #X presentation types misformat negative numbers
Reviewed By: #libc, ldionne, vitaut
Differential Revision: https://reviews.llvm.org/D103433
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/format_fwd.h>
|
2021-04-25 16:23:42 +00:00
|
|
|
#include <__format/format_parse_context.h>
|
2020-12-19 12:52:07 +00:00
|
|
|
#include <__format/format_string.h>
|
2021-11-13 18:43:32 +00:00
|
|
|
#include <__format/format_to_n_result.h>
|
2020-12-19 12:52:07 +00:00
|
|
|
#include <__format/formatter.h>
|
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/formatter_bool.h>
|
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/formatter_char.h>
|
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/formatter_floating_point.h>
|
[libc++][format] Adds integer formatter.
Implements the formatter for all fundamental integer types
(except `char`, `wchar_t`, and `bool`).
[format.formatter.spec]/2.3
For each charT, for each cv-unqualified arithmetic type ArithmeticT other
than char, wchar_t, char8_t, char16_t, or char32_t, a specialization
```
template<> struct formatter<ArithmeticT, charT>;
```
This removes the stub implemented in D96664.
As an extension it adds partial support for 128-bit integer types.
Implements parts of:
- P0645 Text Formatting
- P1652 Printf corner cases in std::format
Completes:
- LWG-3248 #b, #B, #o, #x, and #X presentation types misformat negative numbers
Reviewed By: #libc, ldionne, vitaut
Differential Revision: https://reviews.llvm.org/D103433
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/formatter_integer.h>
|
2021-11-28 13:43:43 +00:00
|
|
|
#include <__format/formatter_pointer.h>
|
[libc++][format] Adds string formatter.
Implements the formatter for all string types.
[format.formatter.spec]/2.2
For each charT, the string type specializations
```
template<> struct formatter<charT*, charT>;
template<> struct formatter<const charT*, charT>;
template<size_t N> struct formatter<const charT[N], charT>;
template<class traits, class Allocator>
struct formatter<basic_string<charT, traits, Allocator>, charT>;
template<class traits>
struct formatter<basic_string_view<charT, traits>, charT>;
```
This removes the stub implemented in D96664.
Implements parts of:
- P0645 Text Formatting
- P1868 width: clarifying units of width and precision in std::format
Reviewed By: #libc, ldionne, vitaut
Differential Revision: https://reviews.llvm.org/D103425
2020-12-14 16:39:15 +00:00
|
|
|
#include <__format/formatter_string.h>
|
|
|
|
#include <__format/parser_std_format_spec.h>
|
2020-12-19 12:52:07 +00:00
|
|
|
#include <__variant/monostate.h>
|
2020-12-05 10:45:21 +00:00
|
|
|
#include <array>
|
2020-12-19 12:52:07 +00:00
|
|
|
#include <concepts>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
|
|
|
|
#include <locale>
|
|
|
|
#endif
|
2021-07-25 07:18:53 +00:00
|
|
|
|
2020-11-26 18:12:18 +00:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2020-12-05 10:45:21 +00:00
|
|
|
#pragma GCC system_header
|
2020-11-26 18:12:18 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-19 12:52:07 +00:00
|
|
|
_LIBCPP_PUSH_MACROS
|
|
|
|
#include <__undef_macros>
|
|
|
|
|
2020-12-05 10:45:21 +00:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 17
|
|
|
|
|
|
|
|
// TODO FMT Remove this once we require compilers with proper C++20 support.
|
|
|
|
// If the compiler has no concepts support, the format header will be disabled.
|
|
|
|
// Without concepts support enable_if needs to be used and that too much effort
|
|
|
|
// to support compilers with partial C++20 support.
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
|
|
|
|
2021-11-16 14:55:17 +00:00
|
|
|
// TODO FMT Move the implementation in this file to its own granular headers.
|
|
|
|
|
2020-12-05 10:45:21 +00:00
|
|
|
// TODO FMT Evaluate which templates should be external templates. This
|
|
|
|
// improves the efficiency of the header. However since the header is still
|
|
|
|
// under heavy development and not all classes are stable it makes no sense
|
|
|
|
// to do this optimization now.
|
|
|
|
|
|
|
|
using format_args = basic_format_args<format_context>;
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-05 10:45:21 +00:00
|
|
|
using wformat_args = basic_format_args<wformat_context>;
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-05 10:45:21 +00:00
|
|
|
|
|
|
|
template <class _Context, class... _Args>
|
|
|
|
struct _LIBCPP_TEMPLATE_VIS __format_arg_store {
|
|
|
|
// TODO FMT Use a built-in array.
|
|
|
|
array<basic_format_arg<_Context>, sizeof...(_Args)> __args;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class _Context = format_context, class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI __format_arg_store<_Context, _Args...>
|
|
|
|
make_format_args(const _Args&... __args) {
|
|
|
|
return {basic_format_arg<_Context>(__args)...};
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-05 10:45:21 +00:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI __format_arg_store<wformat_context, _Args...>
|
|
|
|
make_wformat_args(const _Args&... __args) {
|
|
|
|
return _VSTD::make_format_args<wformat_context>(__args...);
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-19 12:52:07 +00:00
|
|
|
namespace __format {
|
|
|
|
|
|
|
|
template <class _CharT, class _ParseCtx, class _Ctx>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI const _CharT*
|
|
|
|
__handle_replacement_field(const _CharT* __begin, const _CharT* __end,
|
|
|
|
_ParseCtx& __parse_ctx, _Ctx& __ctx) {
|
|
|
|
__format::__parse_number_result __r =
|
|
|
|
__format::__parse_arg_id(__begin, __end, __parse_ctx);
|
|
|
|
|
|
|
|
switch (*__r.__ptr) {
|
|
|
|
case _CharT(':'):
|
|
|
|
// The arg-id has a format-specifier, advance the input to the format-spec.
|
|
|
|
__parse_ctx.advance_to(__r.__ptr + 1);
|
|
|
|
break;
|
|
|
|
case _CharT('}'):
|
|
|
|
// The arg-id has no format-specifier.
|
|
|
|
__parse_ctx.advance_to(__r.__ptr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__throw_format_error(
|
|
|
|
"The replacement field arg-id should terminate at a ':' or '}'");
|
|
|
|
}
|
|
|
|
|
|
|
|
_VSTD::visit_format_arg(
|
|
|
|
[&](auto __arg) {
|
|
|
|
if constexpr (same_as<decltype(__arg), monostate>)
|
|
|
|
__throw_format_error("Argument index out of bounds");
|
2021-12-16 17:17:47 +00:00
|
|
|
else if constexpr (same_as<decltype(__arg), typename basic_format_arg<_Ctx>::handle>)
|
|
|
|
__arg.format(__parse_ctx, __ctx);
|
2020-12-19 12:52:07 +00:00
|
|
|
else {
|
|
|
|
formatter<decltype(__arg), _CharT> __formatter;
|
|
|
|
__parse_ctx.advance_to(__formatter.parse(__parse_ctx));
|
|
|
|
__ctx.advance_to(__formatter.format(__arg, __ctx));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
__ctx.arg(__r.__value));
|
|
|
|
|
|
|
|
__begin = __parse_ctx.begin();
|
|
|
|
if (__begin == __end || *__begin != _CharT('}'))
|
|
|
|
__throw_format_error("The replacement field misses a terminating '}'");
|
|
|
|
|
|
|
|
return ++__begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class _ParseCtx, class _Ctx>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI typename _Ctx::iterator
|
|
|
|
__vformat_to(_ParseCtx&& __parse_ctx, _Ctx&& __ctx) {
|
|
|
|
using _CharT = typename _ParseCtx::char_type;
|
|
|
|
static_assert(same_as<typename _Ctx::char_type, _CharT>);
|
|
|
|
|
|
|
|
const _CharT* __begin = __parse_ctx.begin();
|
|
|
|
const _CharT* __end = __parse_ctx.end();
|
|
|
|
typename _Ctx::iterator __out_it = __ctx.out();
|
|
|
|
while (__begin != __end) {
|
|
|
|
switch (*__begin) {
|
|
|
|
case _CharT('{'):
|
|
|
|
++__begin;
|
|
|
|
if (__begin == __end)
|
|
|
|
__throw_format_error("The format string terminates at a '{'");
|
|
|
|
|
|
|
|
if (*__begin != _CharT('{')) [[likely]] {
|
|
|
|
__ctx.advance_to(_VSTD::move(__out_it));
|
|
|
|
__begin =
|
|
|
|
__handle_replacement_field(__begin, __end, __parse_ctx, __ctx);
|
|
|
|
__out_it = __ctx.out();
|
|
|
|
|
|
|
|
// The output is written and __begin points to the next character. So
|
|
|
|
// start the next iteration.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// The string is an escape character.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _CharT('}'):
|
|
|
|
++__begin;
|
|
|
|
if (__begin == __end || *__begin != _CharT('}'))
|
|
|
|
__throw_format_error(
|
|
|
|
"The format string contains an invalid escape sequence");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the character to the output verbatim.
|
|
|
|
*__out_it++ = *__begin++;
|
|
|
|
}
|
|
|
|
return __out_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __format
|
|
|
|
|
2021-09-04 11:26:58 +00:00
|
|
|
template <class _OutIt, class _CharT, class _FormatOutIt>
|
2020-12-19 12:52:07 +00:00
|
|
|
requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
|
2021-09-04 11:26:58 +00:00
|
|
|
__vformat_to(
|
|
|
|
_OutIt __out_it, basic_string_view<_CharT> __fmt,
|
|
|
|
basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
|
|
|
|
if constexpr (same_as<_OutIt, _FormatOutIt>)
|
|
|
|
return _VSTD::__format::__vformat_to(
|
|
|
|
basic_format_parse_context{__fmt, __args.__size()},
|
|
|
|
_VSTD::__format_context_create(_VSTD::move(__out_it), __args));
|
|
|
|
else {
|
|
|
|
basic_string<_CharT> __str;
|
|
|
|
_VSTD::__format::__vformat_to(
|
|
|
|
basic_format_parse_context{__fmt, __args.__size()},
|
|
|
|
_VSTD::__format_context_create(_VSTD::back_inserter(__str), __args));
|
|
|
|
return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
|
|
|
|
}
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
|
|
|
|
vformat_to(_OutIt __out_it, string_view __fmt, format_args __args) {
|
2020-12-19 12:52:07 +00:00
|
|
|
return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
|
|
|
|
vformat_to(_OutIt __out_it, wstring_view __fmt, wformat_args __args) {
|
2020-12-19 12:52:07 +00:00
|
|
|
return _VSTD::__vformat_to(_VSTD::move(__out_it), __fmt, __args);
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt, class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
|
2020-12-19 12:52:07 +00:00
|
|
|
format_to(_OutIt __out_it, string_view __fmt, const _Args&... __args) {
|
2021-09-04 11:26:58 +00:00
|
|
|
return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
|
|
|
|
_VSTD::make_format_args(__args...));
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt
|
2020-12-19 12:52:07 +00:00
|
|
|
format_to(_OutIt __out_it, wstring_view __fmt, const _Args&... __args) {
|
2021-09-04 11:26:58 +00:00
|
|
|
return _VSTD::vformat_to(_VSTD::move(__out_it), __fmt,
|
|
|
|
_VSTD::make_wformat_args(__args...));
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
|
2020-12-19 12:52:07 +00:00
|
|
|
vformat(string_view __fmt, format_args __args) {
|
|
|
|
string __res;
|
|
|
|
_VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
|
2020-12-19 12:52:07 +00:00
|
|
|
vformat(wstring_view __fmt, wformat_args __args) {
|
|
|
|
wstring __res;
|
|
|
|
_VSTD::vformat_to(_VSTD::back_inserter(__res), __fmt, __args);
|
|
|
|
return __res;
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
|
2020-12-19 12:52:07 +00:00
|
|
|
format(string_view __fmt, const _Args&... __args) {
|
|
|
|
return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
|
2020-12-19 12:52:07 +00:00
|
|
|
format(wstring_view __fmt, const _Args&... __args) {
|
|
|
|
return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt, class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
|
|
|
|
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, string_view __fmt,
|
|
|
|
const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
string __str = _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...));
|
|
|
|
iter_difference_t<_OutIt> __s = __str.size();
|
|
|
|
iter_difference_t<_OutIt> __m =
|
|
|
|
_VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
|
|
|
|
__out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
|
|
|
|
return {_VSTD::move(__out_it), __s};
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
|
|
|
|
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, wstring_view __fmt,
|
|
|
|
const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
wstring __str = _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...));
|
|
|
|
iter_difference_t<_OutIt> __s = __str.size();
|
|
|
|
iter_difference_t<_OutIt> __m =
|
|
|
|
_VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
|
|
|
|
__out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
|
|
|
|
return {_VSTD::move(__out_it), __s};
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
|
|
|
|
formatted_size(string_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
return _VSTD::vformat(__fmt, _VSTD::make_format_args(__args...)).size();
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
|
|
|
|
formatted_size(wstring_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
return _VSTD::vformat(__fmt, _VSTD::make_wformat_args(__args...)).size();
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
#ifndef _LIBCPP_HAS_NO_LOCALIZATION
|
|
|
|
|
2021-09-04 11:26:58 +00:00
|
|
|
template <class _OutIt, class _CharT, class _FormatOutIt>
|
2020-12-19 12:52:07 +00:00
|
|
|
requires(output_iterator<_OutIt, const _CharT&>) _LIBCPP_HIDE_FROM_ABI _OutIt
|
2021-09-04 11:26:58 +00:00
|
|
|
__vformat_to(
|
|
|
|
_OutIt __out_it, locale __loc, basic_string_view<_CharT> __fmt,
|
|
|
|
basic_format_args<basic_format_context<_FormatOutIt, _CharT>> __args) {
|
|
|
|
if constexpr (same_as<_OutIt, _FormatOutIt>)
|
|
|
|
return _VSTD::__format::__vformat_to(
|
|
|
|
basic_format_parse_context{__fmt, __args.__size()},
|
|
|
|
_VSTD::__format_context_create(_VSTD::move(__out_it), __args,
|
|
|
|
_VSTD::move(__loc)));
|
|
|
|
else {
|
|
|
|
basic_string<_CharT> __str;
|
|
|
|
_VSTD::__format::__vformat_to(
|
|
|
|
basic_format_parse_context{__fmt, __args.__size()},
|
|
|
|
_VSTD::__format_context_create(_VSTD::back_inserter(__str), __args,
|
|
|
|
_VSTD::move(__loc)));
|
|
|
|
return _VSTD::copy_n(__str.begin(), __str.size(), _VSTD::move(__out_it));
|
|
|
|
}
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
|
|
|
|
_OutIt __out_it, locale __loc, string_view __fmt, format_args __args) {
|
2020-12-19 12:52:07 +00:00
|
|
|
return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
|
|
|
|
__args);
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt vformat_to(
|
|
|
|
_OutIt __out_it, locale __loc, wstring_view __fmt, wformat_args __args) {
|
2020-12-19 12:52:07 +00:00
|
|
|
return _VSTD::__vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
|
|
|
|
__args);
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt, class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
|
2020-12-19 12:52:07 +00:00
|
|
|
_OutIt __out_it, locale __loc, string_view __fmt, const _Args&... __args) {
|
2021-09-04 11:26:58 +00:00
|
|
|
return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_format_args(__args...));
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT _OutIt format_to(
|
2020-12-19 12:52:07 +00:00
|
|
|
_OutIt __out_it, locale __loc, wstring_view __fmt, const _Args&... __args) {
|
2021-09-04 11:26:58 +00:00
|
|
|
return _VSTD::vformat_to(_VSTD::move(__out_it), _VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_wformat_args(__args...));
|
2020-12-19 12:52:07 +00:00
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
|
2020-12-19 12:52:07 +00:00
|
|
|
vformat(locale __loc, string_view __fmt, format_args __args) {
|
|
|
|
string __res;
|
|
|
|
_VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
|
|
|
|
__args);
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
|
2020-12-19 12:52:07 +00:00
|
|
|
vformat(locale __loc, wstring_view __fmt, wformat_args __args) {
|
|
|
|
wstring __res;
|
|
|
|
_VSTD::vformat_to(_VSTD::back_inserter(__res), _VSTD::move(__loc), __fmt,
|
|
|
|
__args);
|
|
|
|
return __res;
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT string
|
2020-12-19 12:52:07 +00:00
|
|
|
format(locale __loc, string_view __fmt, const _Args&... __args) {
|
|
|
|
return _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_format_args(__args...));
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <class... _Args>
|
2021-09-04 11:26:58 +00:00
|
|
|
_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT wstring
|
2020-12-19 12:52:07 +00:00
|
|
|
format(locale __loc, wstring_view __fmt, const _Args&... __args) {
|
|
|
|
return _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_wformat_args(__args...));
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <output_iterator<const char&> _OutIt, class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
|
|
|
|
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
|
|
|
|
string_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
string __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_format_args(__args...));
|
|
|
|
iter_difference_t<_OutIt> __s = __str.size();
|
|
|
|
iter_difference_t<_OutIt> __m =
|
|
|
|
_VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
|
|
|
|
__out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
|
|
|
|
return {_VSTD::move(__out_it), __s};
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <output_iterator<const wchar_t&> _OutIt, class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT format_to_n_result<_OutIt>
|
|
|
|
format_to_n(_OutIt __out_it, iter_difference_t<_OutIt> __n, locale __loc,
|
|
|
|
wstring_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
wstring __str = _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_wformat_args(__args...));
|
|
|
|
iter_difference_t<_OutIt> __s = __str.size();
|
|
|
|
iter_difference_t<_OutIt> __m =
|
|
|
|
_VSTD::clamp(__n, iter_difference_t<_OutIt>(0), __s);
|
|
|
|
__out_it = _VSTD::copy_n(__str.begin(), __m, _VSTD::move(__out_it));
|
|
|
|
return {_VSTD::move(__out_it), __s};
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
|
|
|
|
formatted_size(locale __loc, string_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
return _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_format_args(__args...))
|
|
|
|
.size();
|
|
|
|
}
|
|
|
|
|
2021-08-23 19:32:36 +00:00
|
|
|
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
|
2020-12-19 12:52:07 +00:00
|
|
|
template <class... _Args>
|
|
|
|
_LIBCPP_HIDE_FROM_ABI _LIBCPP_AVAILABILITY_FORMAT size_t
|
|
|
|
formatted_size(locale __loc, wstring_view __fmt, const _Args&... __args) {
|
|
|
|
// TODO FMT Improve PoC: using std::string is inefficient.
|
|
|
|
return _VSTD::vformat(_VSTD::move(__loc), __fmt,
|
|
|
|
_VSTD::make_wformat_args(__args...))
|
|
|
|
.size();
|
|
|
|
}
|
2021-08-23 19:32:36 +00:00
|
|
|
#endif
|
2020-12-19 12:52:07 +00:00
|
|
|
|
2021-09-09 18:43:02 +00:00
|
|
|
#endif // _LIBCPP_HAS_NO_LOCALIZATION
|
2020-12-19 12:52:07 +00:00
|
|
|
|
2020-12-05 10:45:21 +00:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
|
|
|
|
#endif //_LIBCPP_STD_VER > 17
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2020-12-19 12:52:07 +00:00
|
|
|
_LIBCPP_POP_MACROS
|
|
|
|
|
2021-07-30 18:35:37 +00:00
|
|
|
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_FORMAT)
|
|
|
|
|
2020-11-26 18:12:18 +00:00
|
|
|
#endif // _LIBCPP_FORMAT
|