mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-23 10:50:05 +00:00
Make format_to a non-member
This commit is contained in:
parent
3df0ea34e5
commit
a5bd3ddb28
@ -185,14 +185,6 @@ class prepared_format {
|
||||
|
||||
prepared_format() = delete;
|
||||
|
||||
template <typename OutputIt>
|
||||
inline OutputIt format_to(OutputIt out, const Args&... args) const {
|
||||
typedef format_context_t<OutputIt, char_type> context;
|
||||
typedef output_range<OutputIt, char_type> range;
|
||||
format_arg_store<context, Args...> as(args...);
|
||||
return this->vformat_to(range(out), basic_format_args<context>(as));
|
||||
}
|
||||
|
||||
typedef buffer_context<char_type> context;
|
||||
|
||||
template <typename Range, typename Context>
|
||||
@ -682,6 +674,17 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
|
||||
return to_string(buffer);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename CompiledFormat, typename... Args>
|
||||
OutputIt format_to(OutputIt out, const CompiledFormat& cf,
|
||||
const Args&... args) {
|
||||
using char_type = typename CompiledFormat::char_type;
|
||||
using range = internal::output_range<OutputIt, char_type>;
|
||||
using context = format_context_t<OutputIt, char_type>;
|
||||
format_arg_store<context, Args...> as(args...);
|
||||
return cf.template vformat_to<range, context>(
|
||||
range(out), {make_format_args<context>(args...)});
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename CompiledFormat, typename... Args,
|
||||
FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value)>
|
||||
format_to_n_result<OutputIt> format_to_n(OutputIt out, unsigned n,
|
||||
|
@ -3368,11 +3368,10 @@ inline OutputIt vformat_to(OutputIt out, const S& format_str,
|
||||
fmt::format_to(std::back_inserter(out), "{}", 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename OutputIt, typename S, typename... Args>
|
||||
template <typename OutputIt, typename S, typename... Args,
|
||||
FMT_ENABLE_IF(internal::is_output_iterator<OutputIt>::value&&
|
||||
internal::is_string<S>::value)>
|
||||
inline OutputIt format_to(OutputIt out, const S& format_str, Args&&... args) {
|
||||
static_assert(internal::is_output_iterator<OutputIt>::value &&
|
||||
internal::is_string<S>::value,
|
||||
"");
|
||||
internal::check_format_string<Args...>(format_str);
|
||||
using context = format_context_t<OutputIt, char_t<S>>;
|
||||
return vformat_to(out, to_string_view(format_str),
|
||||
|
@ -257,16 +257,14 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
|
||||
|
||||
// multiply with Factor::num without overflow or underflow
|
||||
if (Factor::num != 1) {
|
||||
constexpr auto max1 =
|
||||
std::numeric_limits<IntermediateRep>::max() /
|
||||
static_cast<IntermediateRep>(Factor::num);
|
||||
constexpr auto max1 = std::numeric_limits<IntermediateRep>::max() /
|
||||
static_cast<IntermediateRep>(Factor::num);
|
||||
if (count > max1) {
|
||||
ec = 1;
|
||||
return {};
|
||||
}
|
||||
constexpr auto min1 =
|
||||
std::numeric_limits<IntermediateRep>::lowest() /
|
||||
static_cast<IntermediateRep>(Factor::num);
|
||||
constexpr auto min1 = std::numeric_limits<IntermediateRep>::lowest() /
|
||||
static_cast<IntermediateRep>(Factor::num);
|
||||
if (count < min1) {
|
||||
ec = 1;
|
||||
return {};
|
||||
|
@ -643,32 +643,32 @@ TEST(PrepareTest, PassUserTypeFormat) {
|
||||
TEST(PrepareTest, FormatToArrayOfChars) {
|
||||
char buffer[32] = {0};
|
||||
const auto prepared = fmt::compile<int>("4{}");
|
||||
prepared.format_to(buffer, 2);
|
||||
fmt::format_to(buffer, prepared, 2);
|
||||
EXPECT_EQ(std::string("42"), buffer);
|
||||
wchar_t wbuffer[32] = {0};
|
||||
const auto wprepared = fmt::compile<int>(L"4{}");
|
||||
wprepared.format_to(wbuffer, 2);
|
||||
fmt::format_to(wbuffer, wprepared, 2);
|
||||
EXPECT_EQ(std::wstring(L"42"), wbuffer);
|
||||
}
|
||||
|
||||
TEST(PrepareTest, FormatToIterator) {
|
||||
std::string s(2, ' ');
|
||||
const auto prepared = fmt::compile<int>("4{}");
|
||||
prepared.format_to(s.begin(), 2);
|
||||
fmt::format_to(s.begin(), prepared, 2);
|
||||
EXPECT_EQ("42", s);
|
||||
std::wstring ws(2, L' ');
|
||||
const auto wprepared = fmt::compile<int>(L"4{}");
|
||||
wprepared.format_to(ws.begin(), 2);
|
||||
fmt::format_to(ws.begin(), wprepared, 2);
|
||||
EXPECT_EQ(L"42", ws);
|
||||
}
|
||||
|
||||
TEST(PrepareTest, FormatToBackInserter) {
|
||||
std::string s;
|
||||
const auto prepared = fmt::compile<int>("4{}");
|
||||
prepared.format_to(std::back_inserter(s), 2);
|
||||
fmt::format_to(std::back_inserter(s), prepared, 2);
|
||||
EXPECT_EQ("42", s);
|
||||
std::wstring ws;
|
||||
const auto wprepared = fmt::compile<int>(L"4{}");
|
||||
wprepared.format_to(std::back_inserter(ws), 2);
|
||||
fmt::format_to(std::back_inserter(ws), wprepared, 2);
|
||||
EXPECT_EQ(L"42", ws);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user