Skip to content

Commit 9120d66

Browse files
authored
Use forwarding reference in std::formatter specializations (#308)
1 parent 9ea540a commit 9120d66

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/dsf/headers/Agent.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ template <>
125125
struct std::formatter<dsf::Agent> {
126126
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
127127
template <typename FormatContext>
128-
auto format(const dsf::Agent& agent, FormatContext& ctx) const {
128+
auto format(const dsf::Agent& agent, FormatContext&& ctx) const {
129129
auto const strItinerary = agent.trip().empty() ? std::string("RANDOM")
130130
: std::to_string(agent.itineraryId());
131131
return std::format_to(ctx.out(),
@@ -140,4 +140,4 @@ struct std::formatter<dsf::Agent> {
140140
agent.speed(),
141141
agent.distance());
142142
}
143-
};
143+
};

src/dsf/headers/Street.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ namespace dsf {
220220
template <>
221221
struct std::formatter<dsf::Street> {
222222
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
223-
template <typename fmtContext>
224-
auto format(const dsf::Street& street, fmtContext& ctx) const {
223+
template <typename FormatContext>
224+
auto format(const dsf::Street& street, FormatContext&& ctx) const {
225225
return std::format_to(
226226
ctx.out(),
227227
"Street \"{}\" ({}: {} -> {}). {} m - {} m/s - {} lanes - {} agents ({} exiting)",
@@ -235,4 +235,4 @@ struct std::formatter<dsf::Street> {
235235
street.nAgents(),
236236
street.nExitingAgents());
237237
}
238-
};
238+
};

src/dsf/headers/TrafficLight.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ template <>
170170
struct std::formatter<dsf::TrafficLightCycle> {
171171
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
172172
template <typename FormatContext>
173-
auto format(const dsf::TrafficLightCycle& cycle, FormatContext& ctx) const {
173+
auto format(const dsf::TrafficLightCycle& cycle, FormatContext&& ctx) const {
174174
return std::format_to(ctx.out(),
175175
"TrafficLightCycle (green time: {} - phase shift: {})",
176176
cycle.greenTime(),
@@ -182,7 +182,7 @@ template <>
182182
struct std::formatter<dsf::TrafficLight> {
183183
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
184184
template <typename FormatContext>
185-
auto format(const dsf::TrafficLight& tl, FormatContext& ctx) const {
185+
auto format(const dsf::TrafficLight& tl, FormatContext&& ctx) const {
186186
std::string strCycles;
187187
for (auto const& [streetId, cycles] : tl.cycles()) {
188188
std::string strStreetCycles{std::format("\tStreet {}:\n", streetId)};
@@ -201,4 +201,4 @@ struct std::formatter<dsf::TrafficLight> {
201201
tl.counter(),
202202
strCycles);
203203
}
204-
};
204+
};

0 commit comments

Comments
 (0)