Skip to content

Commit

Permalink
Fixed the compiler error of C2664, covert double to double& in make_f…
Browse files Browse the repository at this point in the history
…ormat_args function.
  • Loading branch information
007havegone committed Oct 3, 2024
1 parent e36b607 commit 95c5f9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 9 additions & 3 deletions 05.15-stdFmtStockIndexCustomFormatter1/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ struct std::formatter<StockIndex> {
return it;
}

template<typename T>
const T& unmove(T&& x) const
{
return x;
}

auto format(const StockIndex& index, auto& ctx) const
{
if(IndexFormat::Short == indexFormat) {
Expand All @@ -102,9 +108,9 @@ struct std::formatter<StockIndex> {
ctx.out(),
fmt,
std::make_format_args(index.name(),
index.points(),
index.pointsDiff(),
index.pointsPercent()));
unmove(index.points()),
unmove(index.pointsDiff()),
unmove(index.pointsPercent())));
}
}
};
Expand Down
14 changes: 10 additions & 4 deletions 05.17-stdFmtStockIndexCustomFormatter2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ struct std::formatter<StockIndex> {
return it;
}

template<typename T>
const T& unmove(T&& x) const
{
return x;
}

auto format(const StockIndex& index, auto& ctx) const
{
// #D Add localized
Expand All @@ -110,7 +116,7 @@ struct std::formatter<StockIndex> {
return std::vformat_to(
ctx.out(),
fmt,
std::make_format_args(index.name(), index.points()));
std::make_format_args(index.name(), unmove(index.points())));

} else {
const auto fmt{
Expand All @@ -123,9 +129,9 @@ struct std::formatter<StockIndex> {
ctx.out(),
fmt,
std::make_format_args(index.name(),
index.points(),
index.pointsDiff(),
index.pointsPercent()));
unmove(index.points()),
unmove(index.pointsDiff()),
unmove(index.pointsPercent())));
}
}
};
Expand Down

0 comments on commit 95c5f9e

Please sign in to comment.