std::format_to
cppreference.com
<tbody>
</tbody>
template< class OutputIt, class... Args > OutputIt format_to( OutputIt out, std::format_string<Args...> fmt, Args&&... args ); |
(1) | ( C++20) |
template< class OutputIt, class... Args > OutputIt format_to( OutputIt out, std::wformat_string<Args...> fmt, Args&&... args ); |
(2) | ( C++20) |
template< class OutputIt, class... Args > OutputIt format_to( OutputIt out, const std::locale& loc, std::format_string<Args...> fmt, Args&&... args ); |
(3) | ( C++20) |
template< class OutputIt, class... Args > OutputIt format_to( OutputIt out, const std::locale& loc, std::wformat_string<Args...> fmt, Args&&... args ); |
(4) | ( C++20) |
args fmt out. , loc , .
1)
return std::vformat_to(out, fmt.str, std::make_format_args(args...));2)
return std::vformat_to(std::move(out), fmt.str, std::make_wformat_args(args...));3)
return std::vformat_to(out, loc, fmt.str, std::make_format_args(args...));4)
return std::vformat_to(std::move(out), loc, fmt.str, std::make_wformat_args(args...)); CharT char (1,3), wchar_t (2,4).
,
OutputIt std::output_iterator<const CharT&>.
, OutputIt ( ) std::output_iterator<const CharT&> std::formatter<Ti, CharT> BasicFormatter Ti Args ( std::make_format_args std::make_wformat_args).
| out | ||||||||||||||||||||||||||||||||||||||||||||
| fmt |
:
1)
2)
| |||||||||||||||||||||||||||||||||||||||||||
| args... | ||||||||||||||||||||||||||||||||||||||||||||
| loc | std::locale , | |||||||||||||||||||||||||||||||||||||||||||
.
, .
P2216R3, , . std::vformat_to.
#include <format>
#include <iostream>
#include <iterator>
#include <string>
auto main() -> int
{
std::string buffer;
std::format_to(
std::back_inserter(buffer), //< OutputIt
", C++{}!\n", //< fmt
"20"); //<
std::cout << buffer;
buffer.clear();
std::format_to(
std::back_inserter(buffer), //< OutputIt
", {0}::{1}!{2}", //< fmt
"std", //< {0}
"format_to()", //< {1}
"\n", //< {2}
" ()..."); //<
std::cout << buffer;
std::wstring wbuffer;
std::format_to(
std::back_inserter(wbuffer),//< OutputIt
L", {2}::{1}!{0}", //< fmt
L"\n", //< {0}
L"format_to()", //< {1}
L"std", //< {2}
L"... ..." //<
L"...!"); //<
std::wcout << wbuffer;
}
:
, C++20!
, std::format_to()!
, std::format_to()!
C++:
| WG | C++20 | std::format_error | |
| WG | C++20 | , , (, , ), |
|
| WG | C++20 | basic_format_string
|
(C++20) |
( ) |
(C++20) |
, ( ) |