Skip to content

Commit

Permalink
Remove last calls to vformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rprospero committed Jan 6, 2025
1 parent ccabac8 commit 0094384
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/base/lineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class LineParser
// Write line to file
bool writeLine(std::string_view s) const;
// Write formatted line to file
template <typename... Args> bool writeLineF(std::string_view format, Args... args) const
template <typename... Args> bool writeLineF(std::format_string<Args...> format, Args... args) const
{
auto result = true;

Expand Down Expand Up @@ -171,9 +171,9 @@ class LineParser

// Format the line and store it
if (directOutput_)
(*outputFile_) << std::vformat(format, std::make_format_args(args...));
(*outputFile_) << std::format(format, std::forward<Args>(args)...);
else
(*cachedFile_) << std::vformat(format, std::make_format_args(args...));
(*cachedFile_) << std::format(format, std::forward<Args>(args)...);
}

// Broadcast result of write
Expand All @@ -183,15 +183,15 @@ class LineParser
return result;
}
// Print banner comment of fixed width
template <typename... Args> bool writeBannerComment(std::string_view format, Args... args)
template <typename... Args> bool writeBannerComment(std::format_string<Args...> format, Args... args)
{
const auto bannerWidth = 80;
static std::string bannerBorder = std::format("#{0:=^{1}}#", "", bannerWidth - 2);

// Finally, print the banner
if (!writeLineF("\n{}\n", bannerBorder))
return false;
if (!writeLineF("#{:^{}}#", std::vformat(format, std::make_format_args(args...)), bannerWidth - 2))
if (!writeLineF("#{:^{}}#", std::format(format, std::forward<Args>(args)...), bannerWidth - 2))
return false;
if (!writeLineF("\n{}\n", bannerBorder))
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/base/sysFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DissolveSys
return !nameFunction(object).empty() &&
DissolveSys::sameString(nameFunction(object), uniqueName);
}) != objects.end())
uniqueName = std::vformat("{}{:02d}", std::make_format_args(base, ++suffix));
uniqueName = std::format("{}{:02d}", base, ++suffix);

return uniqueName;
}
Expand Down
15 changes: 7 additions & 8 deletions src/classes/species_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,15 @@ bool Species::write(LineParser &parser, std::string_view prefix)
{
// Write new 1-4 scale factor line if this torsion has different values
if ((torsion.electrostatic14Scaling() != elec14Scaling || torsion.vanDerWaals14Scaling() != vdw14Scaling) &&
!parser.writeLineF(std::format("{}{} {} {}\n", newPrefix,
keywords().keyword(Species::SpeciesKeyword::Scaling14),
torsion.electrostatic14Scaling(), torsion.vanDerWaals14Scaling())))
!parser.writeLineF("{}{} {} {}\n", newPrefix, keywords().keyword(Species::SpeciesKeyword::Scaling14),
torsion.electrostatic14Scaling(), torsion.vanDerWaals14Scaling()))
return false;

if (!parser.writeLineF(std::format("{}{} {:3d} {:3d} {:3d} {:3d} {} {}\n", newPrefix,
keywords().keyword(Species::SpeciesKeyword::Torsion), torsion.indexI() + 1,
torsion.indexJ() + 1, torsion.indexK() + 1, torsion.indexL() + 1,
TorsionFunctions::forms().keyword(torsion.interactionForm()),
torsion.interactionPotential().parametersAsString())))
if (!parser.writeLineF("{}{} {:3d} {:3d} {:3d} {:3d} {} {}\n", newPrefix,
keywords().keyword(Species::SpeciesKeyword::Torsion), torsion.indexI() + 1,
torsion.indexJ() + 1, torsion.indexK() + 1, torsion.indexL() + 1,
TorsionFunctions::forms().keyword(torsion.interactionForm()),
torsion.interactionPotential().parametersAsString()))
return false;

elec14Scaling = torsion.electrostatic14Scaling();
Expand Down
4 changes: 2 additions & 2 deletions src/main/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ bool Dissolve::saveInput(std::string_view filename)
{
// Write new 1-4 scale factor line if this torsion has different values
if ((t->electrostatic14Scaling() != elec14Scaling || t->vanDerWaals14Scaling() != vdw14Scaling) &&
!parser.writeLineF(std::format(" {} {} {}\n", MasterBlock::keywords().keyword(MasterBlock::Scaling14Keyword),
t->electrostatic14Scaling(), t->vanDerWaals14Scaling())))
!parser.writeLineF(" {} {} {}\n", MasterBlock::keywords().keyword(MasterBlock::Scaling14Keyword),
t->electrostatic14Scaling(), t->vanDerWaals14Scaling()))
return false;

if (!parser.writeLineF(" {} '{}' {} {}\n", MasterBlock::keywords().keyword(MasterBlock::TorsionKeyword),
Expand Down

0 comments on commit 0094384

Please sign in to comment.