From b1d9d17ddb3675c1f663d554ca48facb411c3652 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 24 Sep 2020 15:51:59 +0200 Subject: [PATCH] Simplify some code with C++17 --- .../RicWellPathExportMswCompletionsImpl.cpp | 15 +++------------ .../RicCreateMultipleFracturesFeature.cpp | 6 +++--- .../Commands/RicExportContourMapToTextFeature.cpp | 7 +------ .../RigFemPartResultsCollection.cpp | 6 +++--- .../AnalysisPlots/RimAnalysisPlot.cpp | 4 ++-- .../ProjectDataModel/Rim3dWellLogCurve.cpp | 5 +---- .../ProjectDataModel/RimContourMapProjection.cpp | 10 ++++------ .../RimEclipseContourMapProjection.cpp | 4 ++-- .../Summary/RimEnsembleCurveFilter.cpp | 7 +++---- 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp index 91f9fd75bd..bc1052e67b 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicWellPathExportMswCompletionsImpl.cpp @@ -1677,11 +1677,8 @@ void RicWellPathExportMswCompletionsImpl::writeMainBoreWelsegsSegment( std::shar prevOutTVD = previousSegment->outputTVD(); } - for ( auto mdPair : subSegments ) + for ( const auto& [subStartMD, subEndMD] : subSegments ) { - double subStartMD = mdPair.first; - double subEndMD = mdPair.second; - auto startPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subStartMD ); auto endPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subEndMD ); @@ -1749,13 +1746,10 @@ void RicWellPathExportMswCompletionsImpl::writeValveWelsegsSegment( std::shared_ std::vector> splitSegments = createSubSegmentMDPairs( startMD, endMD, maxSegmentLength ); - for ( auto mdPair : splitSegments ) + for ( const auto& [subStartMD, subEndMD] : splitSegments ) { int subSegmentNumber = ( *segmentNumber )++; - double subStartMD = mdPair.first; - double subEndMD = mdPair.second; - auto startPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subStartMD ); auto endPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subEndMD ); @@ -1815,13 +1809,10 @@ void RicWellPathExportMswCompletionsImpl::writeCompletionWelsegsSegment( std::sh std::vector> splitSegments = createSubSegmentMDPairs( startMD, endMD, maxSegmentLength ); - for ( auto mdPair : splitSegments ) + for ( const auto& [subStartMD, subEndMD] : splitSegments ) { int subSegmentNumber = ( *segmentNumber )++; - double subStartMD = mdPair.first; - double subEndMD = mdPair.second; - auto startPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subStartMD ); auto endPoint = exportInfo.wellPath()->wellPathGeometry()->interpolatedPointAlongWellPath( subEndMD ); diff --git a/ApplicationCode/Commands/FractureCommands/RicCreateMultipleFracturesFeature.cpp b/ApplicationCode/Commands/FractureCommands/RicCreateMultipleFracturesFeature.cpp index 2c7f64637e..d63a732990 100644 --- a/ApplicationCode/Commands/FractureCommands/RicCreateMultipleFracturesFeature.cpp +++ b/ApplicationCode/Commands/FractureCommands/RicCreateMultipleFracturesFeature.cpp @@ -176,9 +176,9 @@ void RicCreateMultipleFracturesFeature::onActionTriggered( bool isChecked ) { firstSourceCase = proj->eclipseCases().front(); - auto ijkRange = ijkRangeForGrid( firstSourceCase ); - int topK = static_cast( ijkRange.first.z() ); - int baseK = static_cast( ijkRange.second.z() ); + auto [top, base] = ijkRangeForGrid( firstSourceCase ); + int topK = static_cast( top.z() ); + int baseK = static_cast( base.z() ); double minimumDistanceFromTip = 100.0; int maxFractureCount = 100; diff --git a/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp b/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp index 86f1d79113..67c66b1b13 100644 --- a/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp +++ b/ApplicationCode/Commands/RicExportContourMapToTextFeature.cpp @@ -62,12 +62,7 @@ RicExportContourMapToTextFeature::RicExportContourMapToTextFeature() //-------------------------------------------------------------------------------------------------- bool RicExportContourMapToTextFeature::isCommandEnabled() { - RimEclipseContourMapView* existingEclipseContourMap = nullptr; - RimGeoMechContourMapView* existingGeoMechContourMap = nullptr; - - auto sourceViews = findContourMapView(); - existingEclipseContourMap = sourceViews.first; - existingGeoMechContourMap = sourceViews.second; + auto [existingEclipseContourMap, existingGeoMechContourMap] = findContourMapView(); return existingEclipseContourMap || existingGeoMechContourMap; } diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp index 8b7958c860..2118f64842 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp @@ -460,12 +460,12 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::findOrLoadScalarResult( i std::map> elementProperties = m_elementPropertyReader->readAllElementPropertiesInFileContainingField( resVarAddr.fieldName ); - for ( std::pair> elem : elementProperties ) + for ( auto [addrString, values] : elementProperties ) { - RigFemResultAddress addressForElement( RIG_ELEMENT, elem.first, "" ); + RigFemResultAddress addressForElement( RIG_ELEMENT, addrString, "" ); RigFemScalarResultFrames* currentFrames = m_femPartResults[partIndex]->createScalarResult( addressForElement ); currentFrames->enableAsSingleFrameResult(); - currentFrames->frameData( 0 ).swap( elem.second ); + currentFrames->frameData( 0 ).swap( values ); } frames = m_femPartResults[partIndex]->findScalarResult( resVarAddr ); diff --git a/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp b/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp index 769ff1ca03..727112aad7 100644 --- a/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp +++ b/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp @@ -1127,9 +1127,9 @@ void RimAnalysisPlot::applyFilter( const RimPlotDataFilterItem* filter, if ( filter->filterOperation() == RimPlotDataFilterItem::RANGE ) { - std::pair minMax = filter->filterRangeMinMax(); + auto [min, max] = filter->filterRangeMinMax(); - if ( minMax.first <= value && value <= minMax.second ) + if ( min <= value && value <= max ) { casesToKeep.insert( sumCase ); } diff --git a/ApplicationCode/ProjectDataModel/Rim3dWellLogCurve.cpp b/ApplicationCode/ProjectDataModel/Rim3dWellLogCurve.cpp index c449fad854..e8b57132ef 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dWellLogCurve.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dWellLogCurve.cpp @@ -304,10 +304,7 @@ cvf::ref Rim3dWellLogCurve::geometryGenerato //-------------------------------------------------------------------------------------------------- void Rim3dWellLogCurve::resetMinMaxValues() { - std::pair valueRange = findCurveValueRange(); - - m_minCurveDataValue = valueRange.first; - m_maxCurveDataValue = valueRange.second; + std::tie( m_minCurveDataValue, m_maxCurveDataValue ) = findCurveValueRange(); m_minCurveUIValue = m_minCurveDataValue; m_maxCurveUIValue = m_maxCurveDataValue; diff --git a/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp b/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp index 7a53c83ed0..68352ead07 100644 --- a/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp +++ b/ApplicationCode/ProjectDataModel/RimContourMapProjection.cpp @@ -466,13 +466,12 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s case RESULTS_MEAN_VALUE: { RiaWeightedMeanCalculator calculator; - for ( auto cellIdxAndWeight : matchingCells ) + for ( auto [cellIdx, weight] : matchingCells ) { - size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[cellIdx]; if ( cellValue != std::numeric_limits::infinity() ) { - calculator.addValueAndWeight( cellValue, cellIdxAndWeight.second ); + calculator.addValueAndWeight( cellValue, weight ); } } if ( calculator.validAggregatedWeight() ) @@ -484,9 +483,8 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s case RESULTS_GEOM_VALUE: { RiaWeightedGeometricMeanCalculator calculator; - for ( auto cellIdxAndWeight : matchingCells ) + for ( auto [cellIdx, weight] : matchingCells ) { - size_t cellIdx = cellIdxAndWeight.first; double cellValue = gridCellValues[cellIdx]; if ( cellValue < 1.0e-8 ) { @@ -494,7 +492,7 @@ double RimContourMapProjection::calculateValueInMapCell( uint i, uint j, const s } if ( cellValue != std::numeric_limits::infinity() ) { - calculator.addValueAndWeight( cellValue, cellIdxAndWeight.second ); + calculator.addValueAndWeight( cellValue, weight ); } } if ( calculator.validAggregatedWeight() ) diff --git a/ApplicationCode/ProjectDataModel/RimEclipseContourMapProjection.cpp b/ApplicationCode/ProjectDataModel/RimEclipseContourMapProjection.cpp index 5013d4ab07..a104dca8ba 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseContourMapProjection.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseContourMapProjection.cpp @@ -125,9 +125,9 @@ void RimEclipseContourMapProjection::updateLegend() double minVal = minValue( m_aggregatedResults ); double maxVal = maxValue( m_aggregatedResults ); - std::pair minmaxValAllTimeSteps = minmaxValuesAllTimeSteps(); + auto [minValAllTimeSteps, maxValAllTimeSteps] = minmaxValuesAllTimeSteps(); - legendConfig()->setAutomaticRanges( minmaxValAllTimeSteps.first, minmaxValAllTimeSteps.second, minVal, maxVal ); + legendConfig()->setAutomaticRanges( minValAllTimeSteps, maxValAllTimeSteps, minVal, maxVal ); if ( m_resultAggregation() == RESULTS_OIL_COLUMN || m_resultAggregation() == RESULTS_GAS_COLUMN || m_resultAggregation() == RESULTS_HC_COLUMN ) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp index b4e2cf0407..a687e84707 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp @@ -142,12 +142,11 @@ QList if ( curveSet ) { auto params = curveSet->correlationSortedEnsembleParameters(); - for ( const auto& paramCorrPair : params ) + for ( const auto& [param, corr] : params ) { - QString name = paramCorrPair.first.name; - double corr = paramCorrPair.second; options.push_back( - caf::PdmOptionItemInfo( QString( "%1 (Avg. correlation: %2)" ).arg( name ).arg( corr ), name ) ); + caf::PdmOptionItemInfo( QString( "%1 (Avg. correlation: %2)" ).arg( param.name ).arg( corr ), + param.name ) ); } } }