std::basic_format_arg
來自 cppreference.com
定義於標頭檔案 <format> |
||
template< class Context > class basic_format_arg; |
(C++20 起) | |
提供對格式化引數的訪問。
basic_format_arg
物件通常由 std::make_format_args 建立,並透過 std::visit_format_arg 或 visit
成員函式(C++26 起) 訪問。
basic_format_arg
物件的行為如同它儲存了以下型別的 std::variant
- std::monostate (僅當物件是預設構造時)
- bool
- Context::char_type
- int
- unsigned int
- long long int
- unsigned long long int
- float
- double
- long double
- const Context::char_type*
- std::basic_string_view<Context::char_type>
- const void*
- basic_format_arg::handle
目錄 |
[編輯] 成員類
(C++20) |
型別擦除的包裝器,允許格式化使用者定義型別的物件 (公有成員類) |
[編輯] 成員函式
(建構函式) (C++20) |
構造一個 std::basic_format_arg (公開成員函式) |
operator bool (C++20) |
檢查當前物件是否持有格式化引數 (公開成員函式) |
visit (C++26) |
訪問儲存的格式化引數 (公開成員函式) |
[編輯] 非成員函式
(C++20) (在 C++26 中廢棄) |
使用者定義格式化器的引數訪問介面 (函式模板) |
std::basic_format_arg::basic_format_arg
basic_format_arg() noexcept; |
(C++20 起) | |
預設建構函式。構造一個不持有格式化引數的 basic_format_arg
。儲存的物件型別為 std::monostate。
要建立一個持有格式化引數的 basic_format_arg
,必須使用 std::make_format_args。
std::basic_format_arg::operator bool
explicit operator bool() const noexcept; |
(C++20 起) | |
檢查 *this 是否持有格式化引數。
如果 *this 持有格式化引數(即儲存的物件型別不是 std::monostate),則返回 true,否則返回 false。
std::basic_format_arg::visit
template< class Visitor > decltype(auto) visit( this basic_format_arg arg, Visitor&& vis ); |
(1) | (C++26 起) |
template< class R, class Visitor > R visit( this basic_format_arg arg, Visitor&& vis ); |
(2) | (C++26 起) |
將訪問器 vis 應用於 arg 中包含的物件。
visit
函式不會修改它所呼叫的 basic_format_arg
物件,因為在呼叫 vis 時會使用物件的副本。
[編輯] 註解
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_format |
202306L |
(C++26) | 成員 visit |
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
(C++20)(C++20)(C++20) |
提供對所有格式化引數訪問的類 (類模板) |