Skip to content

Commit

Permalink
Capture explicit var for lambdas (#2170)
Browse files Browse the repository at this point in the history
close  #2169

---------

Co-authored-by: Florian Omnès <[email protected]>
  • Loading branch information
payetvin and flomnes authored Jun 17, 2024
1 parent 08003e3 commit 708128c
Show file tree
Hide file tree
Showing 34 changed files with 303 additions and 353 deletions.
12 changes: 8 additions & 4 deletions src/libs/antares/inifile/inifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void IniFile::Section::saveToStream(std::ostream& stream_out, uint64_t& written)
stream_out << '[' << name << "]\n";
written += 4 /* []\n\n */ + name.size();

each([&](const IniFile::Property& p) { p.saveToStream(stream_out, written); });
each([&stream_out, &written](const IniFile::Property& p) {
p.saveToStream(stream_out, written);
});

stream_out << '\n';
}
Expand Down Expand Up @@ -168,9 +170,9 @@ static std::string getSectionName(const std::string& line)
return splitLine[1];
}

static bool isProperty(const std::string& line)
static bool isProperty(std::string_view line)
{
return std::ranges::count(line.begin(), line.end(), '=') == 1;
return std::ranges::count(line, '=') == 1;
}

static IniFile::Property getProperty(std::string line)
Expand Down Expand Up @@ -264,7 +266,9 @@ bool IniFile::open(const fs::path& filename, bool warnings)

void IniFile::saveToStream(std::ostream& stream_out, uint64_t& written) const
{
each([&](const IniFile::Section& s) {s.saveToStream(stream_out, written); });
each([&stream_out, &written](const IniFile::Section& s) {
s.saveToStream(stream_out, written);
});

if (written != 0)
{
Expand Down
27 changes: 11 additions & 16 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,13 +1275,10 @@ Area* AreaList::findFromPosition(const int x, const int y) const
for (auto i = this->areas.rbegin(); i != end; ++i)
{
auto lastArea = i->second;
if (lastArea->ui)
if (lastArea->ui && std::abs(lastArea->ui->x - x) < nearestDistance
&& std::abs(lastArea->ui->y - y) < nearestDistance)
{
if (std::abs(lastArea->ui->x - x) < nearestDistance
&& std::abs(lastArea->ui->y - y) < nearestDistance)
{
nearestItem = lastArea;
}
nearestItem = lastArea;
}
}
return nearestItem;
Expand Down Expand Up @@ -1327,14 +1324,12 @@ void AreaListEnsureDataLoadPrepro(AreaList* l)
/* Asserts */
assert(l);

l->each(
[&](Data::Area& area)
{
if (!area.load.prepro)
{
area.load.prepro = new Antares::Data::Load::Prepro();
}
});
l->each([](Data::Area& area) {
if (!area.load.prepro)
{
area.load.prepro = new Antares::Data::Load::Prepro();
}
});
}

void AreaListEnsureDataSolarPrepro(AreaList* l)
Expand Down Expand Up @@ -1700,9 +1695,9 @@ void AreaList::removeWindTimeseries()
void AreaList::removeThermalTimeseries()
{
each(
[](Data::Area& area)
[](const Data::Area& area)
{
for (auto& c: area.thermal.list.all())
for (const auto& c: area.thermal.list.all())
{
c->series.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@ bool BindingConstraintGroupRepository::buildFrom(const BindingConstraintsReposit

bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const
{
bool allConsistent = !std::any_of(
groups_.begin(),
groups_.end(),
[](const auto& group)
bool allConsistent = !std::ranges::any_of(groups_, [](const auto& group)
{
const auto& constraints = group->constraints();
if (constraints.empty())
{
return false;
}
auto width = (*constraints.begin())->RHSTimeSeries().width;
bool isConsistent = std::all_of(
constraints.begin(),
constraints.end(),
bool isConsistent = std::ranges::all_of(constraints,
[&width](const std::shared_ptr<BindingConstraint>& bc)
{
bool sameWidth = bc->RHSTimeSeries().width == width;
Expand All @@ -94,18 +89,15 @@ bool BindingConstraintGroupRepository::timeSeriesWidthConsistentInGroups() const

void BindingConstraintGroupRepository::resizeAllTimeseriesNumbers(unsigned int nb_years)
{
std::for_each(groups_.begin(),
groups_.end(),
[&](auto& group) { group->timeseriesNumbers.reset(nb_years); });
std::ranges::for_each(groups_, [&nb_years](auto& group)
{ group->timeseriesNumbers.reset(nb_years); });
}

BindingConstraintGroup* BindingConstraintGroupRepository::operator[](const std::string& name) const
{
if (auto group = std::find_if(groups_.begin(),
groups_.end(),
[&name](auto& group_of_constraint)
{ return group_of_constraint->name() == name; });
group != groups_.end())
if (auto group = std::ranges::find_if(groups_, [&name](auto& group_of_constraint)
{ return group_of_constraint->name() == name; });
group != groups_.end())
{
return group->get();
}
Expand Down
10 changes: 5 additions & 5 deletions src/libs/antares/study/cleaner/cleaner-v20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,20 @@ bool listOfFilesAnDirectoriesToKeep(StudyCleaningInfos* infos)
buffer.clear() << infos->folder << "/input/bindingconstraints/bindingconstraints.ini";
if (ini.open(buffer))
{
String v;

ini.each(
[&](const IniFile::Section& section)
[&e](const IniFile::Section& section)
{
auto* property = section.firstProperty;
for (; property; property = property->next)
{
if (property->key == "id")
{
v = property->value;
String v = property->value;
v.toLower();
buffer.clear() << "input/bindingconstraints/" << v << ".txt";
e.add(buffer);
String tmp;
tmp << "input/bindingconstraints/" << v << ".txt";
e.add(tmp);
// Go to the next binding constraint
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ uint stringIntoDatePrecision(const AnyString& string)
uint flag = 0;

string.words(",; \r\n\t",
[&](const AnyString& word) -> bool
[&flag](const AnyString& word) -> bool
{
ShortString16 s = word;
s.toLower();
Expand Down
19 changes: 2 additions & 17 deletions src/libs/antares/study/include/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ namespace Antares::Data
class Parameters final
{
public:
//! \name Constructor
//@{
/*!
** \brief Default Constructor
**
** \warning None of the variables are initialized. You must explicitly use
** the method `reset()` or the method `loadFromFile()`
** \see reset()
** \see loadFromFile()
*/
Parameters();
//! Destructor
~Parameters();
//@}

//! \name Simulation mode
//@{
//! Get if the simulation is in economy mode
Expand All @@ -91,7 +76,7 @@ class Parameters final
** \return True if the settings have been loaded, false if at least one error has occured
*/
bool loadFromFile(const AnyString& filename,
StudyVersion& version,
const StudyVersion& version,
const StudyLoadOptions& options);

/*!
Expand Down Expand Up @@ -493,7 +478,7 @@ class Parameters final
//@{
//! No output
// This variable is not stored within the study but only used by the solver
bool noOutput;
bool noOutput = false;
//@}

bool hydroDebug;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ bool Study::internalLoadBindingConstraints(const StudyLoadOptions& options)
class SetHandlerAreas
{
public:
SetHandlerAreas(Study& study):
explicit SetHandlerAreas(Study& study):
pStudy(study)
{
}
Expand Down Expand Up @@ -411,7 +411,7 @@ bool Study::reloadXCastData()
// if changes are required, please update AreaListLoadFromFolderSingleArea()
bool ret = true;
areas.each(
[&](Data::Area& area)
[this, &ret](Data::Area& area)
{
assert(area.load.prepro);
assert(area.solar.prepro);
Expand Down
15 changes: 4 additions & 11 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static bool ConvertCStrToListTimeSeries(const String& value, uint& v)
}

value.words(" ,;\t\r\n",
[&](const AnyString& element) -> bool
[&v](const AnyString& element)
{
ShortString16 word(element);
word.toLower();
Expand Down Expand Up @@ -208,13 +208,6 @@ const char* SimulationModeToCString(SimulationMode mode)
}
}

Parameters::Parameters():
noOutput(false)
{
}

Parameters::~Parameters() = default;

bool Parameters::economy() const
{
return mode == SimulationMode::Economy;
Expand All @@ -231,8 +224,8 @@ void Parameters::resetSeeds()
// For retro-compatibility, the wind ts-generator should produce the
// same results than before 3.8.
// It must have the same seed than before
auto increment = (unsigned)antaresSeedIncrement;
auto s = (unsigned)antaresSeedDefaultValue;
auto increment = antaresSeedIncrement;
auto s = antaresSeedDefaultValue;

seed[seedTsGenWind] = s;
// The same way for all others
Expand Down Expand Up @@ -1981,7 +1974,7 @@ void Parameters::saveToINI(IniFile& ini) const
}

bool Parameters::loadFromFile(const AnyString& filename,
StudyVersion& version,
const StudyVersion& version,
const StudyLoadOptions& options)
{
// Loading the INI file
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/parts/common/cluster_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ bool ClusterList<ClusterT>::saveDataSeriesToFolder(const AnyString& folder) cons
template<class ClusterT>
bool ClusterList<ClusterT>::loadDataSeriesFromFolder(Study& s, const AnyString& folder)
{
return std::ranges::all_of(allClusters_,
[&](auto c) { return c->loadDataSeriesFromFolder(s, folder); });
return std::ranges::all_of(allClusters_, [&s, &folder](auto c)
{ return c->loadDataSeriesFromFolder(s, folder); });
}

template<class ClusterT>
Expand Down
41 changes: 19 additions & 22 deletions src/libs/antares/study/parts/hydro/allocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,31 +170,28 @@ bool HydroAllocation::loadFromFile(const AreaName& referencearea,
clear();

IniFile ini;
if (fs::exists(filename) && ini.open(filename))
{
if (!ini.empty())
{
AreaName areaname;
ini.each(
[&](const IniFile::Section& section)
{
for (auto* p = section.firstProperty; p; p = p->next)
{
double coeff = p->value.to<double>();
if (!Utils::isZero(coeff))
{
areaname = p->key;
areaname.toLower();
pValues[areaname] = coeff;
}
}
});
}
}
else
if (!fs::exists(filename) || !ini.open(filename))
{
pValues[referencearea] = 1.0;
return true;
}

if (ini.empty())
return true;

ini.each([this](const IniFile::Section& section)
{
for (auto* p = section.firstProperty; p; p = p->next)
{
double coeff = p->value.to<double>();
if (!Utils::isZero(coeff))
{
AreaName areaname = p->key;
areaname.toLower();
pValues[areaname] = coeff;
}
}
});
return true;
}

Expand Down
Loading

0 comments on commit 708128c

Please sign in to comment.