Skip to content

style: use -> instead of value(). for std::optionals - #3809

Open
flomnes wants to merge 3 commits into
developfrom
fix/style-opt
Open

style: use -> instead of value(). for std::optionals#3809
flomnes wants to merge 3 commits into
developfrom
fix/style-opt

Conversation

@flomnes

@flomnes flomnes commented Jul 15, 2026

Copy link
Copy Markdown
Member

std::optional has an -> operator which is more compact than .value().

Example

std::optional<std::string> myString("hello, world");
std::size_t size = myString.value().size();
std::size_t size2 = myString->size();
assert(size == size2);

See std::optional<T>::value, std::optional<T>::operator->

@pull-request-size

Copy link
Copy Markdown

This PR is too big. Please break it up into smaller PRs.

if (!tryParseYamlField(
param.second,
area.allCapacityReservations.value().maxGlobalEnergyActivationRatio.up,
area.allCapacityReservations->maxGlobalEnergyActivationRatio.up,

@YoshuaLisasi YoshuaLisasi Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined?
if not
if(area.allCapacityReservations) should be added to dodge the UB that comes with the "->" operator.

    if (root["global-parameters"])
    {
        ret = readReservesAreaParameters(area, root["global-parameters"]) && ret;
    }
 
    if (root["reserves"])
    {
        for (const auto& reserveNode: root["reserves"])
        {
            ret = readReserveParameters(folderInput, area, reserveNode) && ret;
        }
    }
 
    validateCapacityReservations(area);
    return ret;

it seems that the validations is done after the function is called.

if (!tryParseYamlField(
param.second,
area.allCapacityReservations.value().maxGlobalEnergyActivationRatio.down,
area.allCapacityReservations->maxGlobalEnergyActivationRatio.down,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

if (!tryParseYamlField(
param.second,
area.allCapacityReservations.value().referenceGlobalActivationDuration.up,
area.allCapacityReservations->referenceGlobalActivationDuration.up,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

if (!tryParseYamlField(
param.second,
area.allCapacityReservations.value().referenceGlobalActivationDuration.down,
area.allCapacityReservations->referenceGlobalActivationDuration.down,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment


ReserveID reserveId = transformNameIntoID(reserveName);
if (area.allCapacityReservations.value().contains(reserveId))
if (area.allCapacityReservations->contains(reserveId))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

capacityReservation.loadNeedFromFile(filePath);
area.allCapacityReservations.value().areaCapacityReservations.emplace(capacityReservation.id(),
capacityReservation);
area.allCapacityReservations->areaCapacityReservations.emplace(capacityReservation.id(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

const std::string& reserveID)
{
const auto* reserve = area.allCapacityReservations.value().getReserveByID(reserveID);
const auto* reserve = area.allCapacityReservations->getReserveByID(reserveID);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

if constexpr (std::is_same_v<ClusterT, ShortTermStorage::STStorageCluster>)
{
area.allCapacityReservations.value().reserveGroupPartSTS[reserveID].insert(
area.allCapacityReservations->reserveGroupPartSTS[reserveID].insert(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

else if constexpr (std::is_same_v<ClusterT, ThermalCluster>)
{
area.allCapacityReservations.value().reserveGroupPartThermal[reserveID].insert(
area.allCapacityReservations->reserveGroupPartThermal[reserveID].insert(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

readProperties(cert, rp);

const auto* reserve = area.allCapacityReservations.value().getReserveByID(reserveId);
const auto* reserve = area.allCapacityReservations->getReserveByID(reserveId);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?


for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

unsigned int column = 0;
for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?


for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

area->allCapacityReservations->areaCapacityReservations | std::views::keys)
{
if (reserveParticipationContainer.value().isParticipatingInReserve(reserveID))
if (reserveParticipationContainer->isParticipatingInReserve(reserveID))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveParticipationContainer defined ?


for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

unsigned int column = 0;
for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

{
for (const auto& [_, reserveParticipation]:
cluster->reserveParticipationContainer.value().getReservesParticipations())
cluster->reserveParticipationContainer->getReservesParticipations())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveParticipationContainer always defined ?

r.counts.reserveParticipations += area.hydro.reserveParticipationsCount();
r.counts.capacityReservations += area.allCapacityReservations.value()
.areaCapacityReservations.size();
r.counts.capacityReservations += area.allCapacityReservations->areaCapacityReservations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

.reservesIndices.value()
.HydroEnergyLevelParticipation[reserveParticipation
.globalIndexClusterParticipation]
.reservesIndices->HydroEnergyLevelParticipation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

data.CorrespondanceCntNativesCntOptim[pdt]
.reservesIndices.value()
.HydroGlobalEnergyLevelParticipationUp[globalClusterIdx]
.reservesIndices->HydroGlobalEnergyLevelParticipationUp[globalClusterIdx]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

data.CorrespondanceCntNativesCntOptim[pdt]
.reservesIndices.value()
.HydroGlobalEnergyLevelParticipationDown[globalClusterIdx]
.reservesIndices->HydroGlobalEnergyLevelParticipationDown[globalClusterIdx]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

data.CorrespondanceCntNativesCntOptim[pdt]
.reservesIndices.value()
.HydroLevelParticipation[type][globalClusterIdx]
.reservesIndices->HydroLevelParticipation[type][globalClusterIdx]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

data.CorrespondanceCntNativesCntOptim[pdt]
.reservesIndices.value()
.HydroReleaseCapacityThresholdsMin[globalClusterIdx]
.reservesIndices->HydroReleaseCapacityThresholdsMin[globalClusterIdx]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?


cnt = CorrespondanceCntNativesCntOptim.reservesIndices.value()
.HydroGlobalEnergyLevelParticipationDown[globalClusterIdx];
cnt = CorrespondanceCntNativesCntOptim.reservesIndices

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?


cnt = CorrespondanceCntNativesCntOptim.reservesIndices.value()
.HydroGlobalEnergyLevelParticipationUp[globalClusterIdx];
cnt = CorrespondanceCntNativesCntOptim.reservesIndices

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

int cnt = CorrespondanceCntNativesCntOptim.reservesIndices.value()
.HydroMaxReleaseParticipation[reserveParticipation
.globalIndexClusterParticipation];
int cnt = CorrespondanceCntNativesCntOptim.reservesIndices->HydroMaxReleaseParticipation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

cnt = CorrespondanceCntNativesCntOptim.reservesIndices.value()
.HydroMaxStoreParticipation[reserveParticipation
.globalIndexClusterParticipation];
cnt = CorrespondanceCntNativesCntOptim.reservesIndices->HydroMaxStoreParticipation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

cnt = CorrespondanceCntNativesCntOptim.reservesIndices.value()
.HydroEnergyLevelParticipation[reserveParticipation
.globalIndexClusterParticipation];
cnt = CorrespondanceCntNativesCntOptim.reservesIndices->HydroEnergyLevelParticipation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

.internalUnsatisfied.assign(capacityReservationCount, 0);
variablesMapping.reservesIndices.value().internalExcess.assign(capacityReservationCount,
0);
variablesMapping.reservesIndices->runningThermalClusterParticipation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reservesIndices always defined ?

{
areaReserves.referenceGlobalActivationDuration[type]
= area->allCapacityReservations.value().referenceGlobalActivationDuration[type];
= area->allCapacityReservations->referenceGlobalActivationDuration[type];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?


for (const auto& [reserveID, reserveCapacity]:
area->allCapacityReservations.value().areaCapacityReservations)
area->allCapacityReservations->areaCapacityReservations)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

int areaReserveIdx = 0;
for (const auto& [reserveID, _]:
area->allCapacityReservations.value().areaCapacityReservations)
area->allCapacityReservations->areaCapacityReservations)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

{
if (cluster.reserveParticipationContainer
&& cluster.reserveParticipationContainer.value().isParticipatingInReserve(
&& cluster.reserveParticipationContainer->isParticipatingInReserve(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

if (hasIndexMapping(state.study, state.area))
{
const auto& resData = state.reserveData.value().at(state.area->index);
const auto& resData = state.reserveData->at(state.area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

if (hasIndexMapping(state.study, state.area))
{
const auto& resData = state.reserveData.value().at(state.area->index);
const auto& resData = state.reserveData->at(state.area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

for (const auto& [reserveName, reserveParticipation]:
state.reserveData.value()
.at(state.area->index)
state.reserveData->at(state.area->index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

if (hasIndexMapping(state.study, state.area))
{
const auto& resData = state.reserveData.value().at(state.area->index);
const auto& resData = state.reserveData->at(state.area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

int column = 0;
for (const auto& reserveID:
area->allCapacityReservations.value().areaCapacityReservations | std::views::keys)
area->allCapacityReservations->areaCapacityReservations | std::views::keys)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

pValuesForTheCurrentYear[numSpace][column].hour[state.hourInTheYear]
+= state.reserveData.value()
.at(area->index)
+= state.reserveData->at(area->index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

int column = 0;
for (const auto& reserveID:
results.data.area->allCapacityReservations.value().areaCapacityReservations
results.data.area->allCapacityReservations->areaCapacityReservations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

pValuesForTheCurrentYear[numSpace][column].hour[state.hourInTheYear]
+= state.reserveData.value()
.at(area->index)
+= state.reserveData->at(area->index)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?


pSize = study->parameters.include.reserves
? area->allCapacityReservations.value().areaCapacityReservations.size()
? area->allCapacityReservations->areaCapacityReservations.size()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

int column = 0;
for (const auto& reserveID:
results.data.area->allCapacityReservations.value().areaCapacityReservations
results.data.area->allCapacityReservations->areaCapacityReservations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?


pSize = study->parameters.include.reserves
? area->allCapacityReservations.value().areaCapacityReservations.size() * 2
? area->allCapacityReservations->areaCapacityReservations.size() * 2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

{
auto [unsuppliedOrSpilled, reserveID] = results.data.area->allCapacityReservations.value()
.reserveParticipationUnsuppliedSpilledAt(i);
auto [unsuppliedOrSpilled, reserveID] = results.data.area->allCapacityReservations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

{
const auto& reserveID = results.data.area->allCapacityReservations.value()
.getReserveAtIndex(i);
const auto& reserveID = results.data.area->allCapacityReservations->getReserveAtIndex(i);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is allCapacityReservations always defined ?

&& study.parameters.include.reserves && STStorageCluster->reserveParticipationContainer)
{
auto& resData = reserveData.value().at(area->index);
auto& resData = reserveData->at(area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

&& study.parameters.include.reserves && Hydro.reserveParticipationContainer)
{
auto& resData = reserveData.value().at(area->index);
auto& resData = reserveData->at(area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

&& study.parameters.include.reserves && thermalCluster->reserveParticipationContainer)
{
auto& resData = reserveData.value().at(area->index);
auto& resData = reserveData->at(area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

uint endHourForCurrentYear = startHourForCurrentYear
+ study.runtime.rangeLimits.hour[Data::rangeCount];
auto& resData = reserveData.value().at(area->index);
auto& resData = reserveData->at(area->index);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reserveData always defined ?

@YoshuaLisasi YoshuaLisasi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the optinals is always defined and not nullopt

# Conflicts:
#	src/solver/variable/include/antares/solver/variable/economy/reserves/reserveParticipationByHydro.h
#	src/solver/variable/include/antares/solver/variable/economy/reserves/reserveParticipationBySTStorage.h
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
16.4% Coverage on New Code (required ≥ 60%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants