[vlmc-devel] [PATCH 1/2] Use C++11-style for-loop

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Mar 11 11:28:11 CET 2016


Hi,

On 03/11/2016 07:09 AM, Yikai Lu wrote:
> ---
>   src/Settings/Settings.cpp | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/src/Settings/Settings.cpp b/src/Settings/Settings.cpp
> index 2259228..ab48a23 100644
> --- a/src/Settings/Settings.cpp
> +++ b/src/Settings/Settings.cpp
> @@ -71,19 +71,16 @@ Settings::save( QXmlStreamWriter& project )
>   {
>       QReadLocker lock( &m_rwLock );
>
> -    SettingMap::const_iterator     it = m_settings.begin();
> -    SettingMap::const_iterator     end = m_settings.end();
> -
>       project.writeStartElement( "settings" );
> -    for ( ; it != end; ++it )
> +    for ( SettingValue* val: m_settings.values() )

Using a range based for loop with a QMap will yield the value by 
default, so you could simplify to

for ( const auto val : m_settings )

>       {
> -        if ( ( (*it)->flags() & SettingValue::Runtime ) != 0 )
> +        if ( ( val->flags() & SettingValue::Runtime ) != 0 )
>               continue ;
>           project.writeStartElement( "setting" );
> -        project.writeAttribute( "key", (*it)->key() );
> -        if ( (*it)->get().canConvert<QString>() == false )
> -            vlmcWarning() << "Can't serialize" << (*it)->key();
> -        project.writeAttribute( "value", (*it)->get().toString() );
> +        project.writeAttribute( "key", val->key() );
> +        if ( val->get().canConvert<QString>() == false )
> +            vlmcWarning() << "Can't serialize" << val->key();
> +        project.writeAttribute( "value", val->get().toString() );
>           project.writeEndElement();
>       }
>       project.writeEndElement();
>

Regards,


More information about the Vlmc-devel mailing list