declare the postal service iterators as values, not as references

PostalService.h names every type twice, once plainly and once as a reference:
RefToDestinationStruct is DestinationStruct&, RefToShipmentList is
ShipmentList&. That scheme was extended to the iterators, and there it does
not work. Every one of the seventeen uses looks like this:

    RefToShipmentListIterator sli = _Shipments.begin();

begin() returns a value, so this binds a non-const reference to a temporary.
MSVC allows it as an extension; the temporary still dies at the end of the
full expression, which leaves sli referring to a dead object for the whole
rest of the function. It works only because nothing has reused the stack slot
yet. clang rejects it outright.

Iterators are already handles into their container, so a reference to one buys
nothing: the plain typedef says exactly what these seventeen variables want to
be. DESTINATION and SHIPMENT now take theirs by value, which changes nothing
for either, as both only dereference the iterator they are given.

Two of the reference typedefs, RefToDestinationDeliveryInfoTableIterator and
RefToDeliveryCallbackDataListIterator, had no uses at all. They are removed
rather than left behind, since their only possible use is the pattern this
commit removes.

Verification:

    grep -rn 'RefTo[A-Za-z]*Iterator' --include=*.cpp --include=*.h .   # nothing
    ninja -C build parse         # bind-to-temporary class gone: 91 -> 60 sites
    ninja -C build -k 0          # Release, four applications, green
    ninja -C build-debug -k 0    # Debug, four applications, green

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-23 19:29:55 -03:00
committed by majcosta
co-authored by Claude Opus 4.8
parent 70b11ee120
commit b5ea70aa44
7 changed files with 22 additions and 26 deletions
+10 -10
View File
@@ -124,7 +124,7 @@ UINT16 CPostalService::CreateNewShipment(UINT16 usDestinationID, UINT8 ubDelive
}
_Destinations.sort(DESTINATION_LIST_ASCENDING);
RefToDestinationListIterator dli = _Destinations.begin();
DestinationListIterator dli = _Destinations.begin();
while(DESTINATION(dli).usID != usDestinationID)
{
@@ -186,7 +186,7 @@ BOOLEAN CPostalService::AddPackageToShipment(UINT16 usShipmentID, UINT16 usItemI
}
_Shipments.sort(SHIPMENT_LIST_ASCENDING);
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
while(SHIPMENT(sli).usID != usShipmentID)
{
@@ -218,7 +218,7 @@ BOOLEAN CPostalService::SendShipment(UINT16 usShipmentID)
return FALSE;
}
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
while(SHIPMENT(sli).usID != usShipmentID)
{
@@ -272,7 +272,7 @@ BOOLEAN CPostalService::DeliverShipment(UINT16 usShipmentID)
return FALSE;
}
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
while(SHIPMENT(sli).usID != usShipmentID)
{
@@ -622,7 +622,7 @@ BOOLEAN CPostalService::DeliverShipmentForMultiplayer(UINT16 usShipmentID)
return FALSE;
}
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
while(SHIPMENT(sli).usID != usShipmentID)
{
@@ -897,7 +897,7 @@ BOOLEAN CPostalService::SaveShipmentListToSaveGameFile(HWFILE hFile)
return TRUE;
}
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
ShipmentSaveFileDataStruct sfs;
ShipmentPackageStruct sps;
@@ -1022,7 +1022,7 @@ BOOLEAN CPostalService::IsSectorAShipmentSector(UINT8 ubMapX, UINT8 ubMapY, UINT
BOOLEAN isShipmentSector = FALSE;
vector<PDestinationStruct> destinations;
RefToDestinationListIterator dli = LookupDestinationList().begin();
DestinationListIterator dli = LookupDestinationList().begin();
while (dli != LookupDestinationList().end())
{
@@ -1055,7 +1055,7 @@ UINT16 CPostalService::GetShipmentCount(SHIPMENT_STATUS TargetedShipmentStatus)
return 0;
}
RefToShipmentListIterator sli = _Shipments.begin();
ShipmentListIterator sli = _Shipments.begin();
UINT16 usCnt=0;
while(sli != _Shipments.end())
@@ -1119,7 +1119,7 @@ UINT16 CPostalService::SetDestinationDeliveryInfo(UINT8 ubDeliveryMethodIndex, U
_Destinations.sort(DESTINATION_LIST_ASCENDING);
RefToDestinationListIterator dli = _Destinations.begin();
DestinationListIterator dli = _Destinations.begin();
while( DESTINATION(dli).uiIndex != uiDestinationIndex)
{
@@ -1160,7 +1160,7 @@ RefToDestinationStruct CPostalService::_GetDestination(UINT16 usDestinationID)
return DESTINATION(_Destinations.end());
}
RefToDestinationListIterator dli = _Destinations.begin();
DestinationListIterator dli = _Destinations.begin();
while(DESTINATION(dli).usID != usDestinationID)
{