From ff6ac0d4cbe1bbbbaf894026af425d5da0de5422 Mon Sep 17 00:00:00 2001 From: Ko van der Sloot Date: Wed, 28 Aug 2024 20:09:49 +0200 Subject: [PATCH] modernizing, using c++17 stuff --- src/IGExperiment.cxx | 4 ++-- src/Targets.cxx | 20 +++++--------------- src/TimblExperiment.cxx | 4 ++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/IGExperiment.cxx b/src/IGExperiment.cxx index 629c204..1734c17 100644 --- a/src/IGExperiment.cxx +++ b/src/IGExperiment.cxx @@ -87,8 +87,8 @@ namespace Timbl { ostream& operator<< ( ostream& os, const fileDoubleIndex& fmi ){ os << "["; - for ( const auto& it : fmi ){ - os << it.first << " " << it.second << endl; + for ( const auto& [fv,index] : fmi ){ + os << fv << " " << index << endl; } os << "]"; return os; diff --git a/src/Targets.cxx b/src/Targets.cxx index e98b71c..80d4b91 100644 --- a/src/Targets.cxx +++ b/src/Targets.cxx @@ -247,9 +247,7 @@ namespace Timbl { ClassDistribution *ClassDistribution::to_VD_Copy( ) const { ClassDistribution *res = new ClassDistribution(); - for ( const auto& d : distribution ){ - size_t key = d.first; - const Vfield *vdf = d.second; + for ( const auto& [key,vdf] : distribution ){ res->distribution[key] = new Vfield( vdf->Value(), vdf->Freq(), vdf->Freq() ); @@ -260,9 +258,7 @@ namespace Timbl { WClassDistribution *ClassDistribution::to_WVD_Copy() const { WClassDistribution *res = new WClassDistribution(); - for ( const auto& d : distribution ){ - size_t key = d.first; - const Vfield *vdf = d.second; + for ( const auto& [key,vdf] : distribution ){ res->distribution[key] = new Vfield( vdf->Value(), vdf->Freq(), vdf->Freq() ); @@ -273,9 +269,7 @@ namespace Timbl { WClassDistribution *WClassDistribution::to_WVD_Copy( ) const { WClassDistribution *result = new WClassDistribution(); - for ( const auto& d : distribution ){ - size_t key = d.first; - const Vfield *vdf = d.second; + for ( const auto& [key,vdf] : distribution ){ result->distribution[key] = new Vfield( vdf->Value(), vdf->Freq(), vdf->Weight() ); @@ -433,9 +427,7 @@ namespace Timbl { } void ClassDistribution::Merge( const ClassDistribution& VD ){ - for ( const auto& it : VD.distribution ){ - size_t key = it.first; - const Vfield *vd = it.second; + for ( const auto& [key,vd] : VD.distribution ){ if ( distribution.find(key) != distribution.end() ){ // the key is already present, increment the frequency distribution[key]->AddFreq( vd->Freq() ); @@ -453,9 +445,7 @@ namespace Timbl { void WClassDistribution::MergeW( const ClassDistribution& VD, double Weight ){ - for ( const auto& it : VD.distribution ){ - size_t key = it.first; - const Vfield *vd = it.second; + for ( const auto& [key,vd] : VD.distribution ){ if ( distribution.find(key) != distribution.end() ){ distribution[key]->SetWeight( distribution[key]->Weight() + vd->Weight() *Weight ); } diff --git a/src/TimblExperiment.cxx b/src/TimblExperiment.cxx index b1bfbb1..2814241 100644 --- a/src/TimblExperiment.cxx +++ b/src/TimblExperiment.cxx @@ -485,9 +485,9 @@ namespace Timbl { } ostream& operator<< ( ostream& os, const fileIndex& fi ){ - for ( const auto& it : fi ){ + for ( const auto& [fv,index] : fi ){ os << "<"; - os << it.first << "," << it.second; + os << fv << "," << index; os << ">"; } return os;