From a0a7069ebaabfad18851b39d71c57992afcef77b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz>
Date: Thu, 20 Jan 2022 21:03:13 +0100
Subject: [PATCH] clang-tidy: use auto to avoid writing the same type on both
 sides of the assignment operator [modernize-use-auto]

See https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-auto.html
---
 src/TNL/Algorithms/scan.h          |  8 +++---
 src/TNL/Benchmarks/Logging.h       |  2 +-
 src/TNL/Config/ConfigDescription.h |  4 +--
 src/TNL/Config/parseCommandLine.h  | 43 ++++++++++++++----------------
 src/TNL/Endianness.h               |  2 +-
 src/TNL/Images/DicomSeries_impl.h  |  2 +-
 src/TNL/zlib_compression.h         |  4 +--
 7 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/src/TNL/Algorithms/scan.h b/src/TNL/Algorithms/scan.h
index 4eec25cd87..d80f0fc63d 100644
--- a/src/TNL/Algorithms/scan.h
+++ b/src/TNL/Algorithms/scan.h
@@ -98,7 +98,7 @@ inclusiveScan( const InputArray& input,
 {
    if( end == 0 )
       end = input.getSize();
-   constexpr typename OutputArray::ValueType identity = Reduction::template getIdentity< typename OutputArray::ValueType >();
+   constexpr auto identity = Reduction::template getIdentity< typename OutputArray::ValueType >();
    inclusiveScan( input, output, begin, end, outputBegin, std::forward< Reduction >( reduction ), identity );
 }
 
@@ -184,7 +184,7 @@ exclusiveScan( const InputArray& input,
 {
    if( end == 0 )
       end = input.getSize();
-   constexpr typename OutputArray::ValueType identity = Reduction::template getIdentity< typename OutputArray::ValueType >();
+   constexpr auto identity = Reduction::template getIdentity< typename OutputArray::ValueType >();
    exclusiveScan( input, output, begin, end, outputBegin, std::forward< Reduction >( reduction ), identity );
 }
 
@@ -256,7 +256,7 @@ inplaceInclusiveScan( Array& array,
 {
    if( end == 0 )
       end = array.getSize();
-   constexpr typename Array::ValueType identity = Reduction::template getIdentity< typename Array::ValueType >();
+   constexpr auto identity = Reduction::template getIdentity< typename Array::ValueType >();
    inplaceInclusiveScan( array, begin, end, std::forward< Reduction >( reduction ), identity );
 }
 
@@ -328,7 +328,7 @@ inplaceExclusiveScan( Array& array,
 {
    if( end == 0 )
       end = array.getSize();
-   constexpr typename Array::ValueType identity = Reduction::template getIdentity< typename Array::ValueType >();
+   constexpr auto identity = Reduction::template getIdentity< typename Array::ValueType >();
    inplaceExclusiveScan( array, begin, end, std::forward< Reduction >( reduction ), identity );
 }
 
diff --git a/src/TNL/Benchmarks/Logging.h b/src/TNL/Benchmarks/Logging.h
index d73d4365a3..83e8352d33 100644
--- a/src/TNL/Benchmarks/Logging.h
+++ b/src/TNL/Benchmarks/Logging.h
@@ -115,7 +115,7 @@ public:
    {
       try {
          // check if we got an open file
-         std::ofstream& file = dynamic_cast< std::ofstream& >( log );
+         auto& file = dynamic_cast< std::ofstream& >( log );
          if( file.is_open() )
             // enable exceptions, but only if we got an open file
             // (under MPI, only the master rank typically opens the log file and thus
diff --git a/src/TNL/Config/ConfigDescription.h b/src/TNL/Config/ConfigDescription.h
index cfd46e01d4..df5d5cc480 100644
--- a/src/TNL/Config/ConfigDescription.h
+++ b/src/TNL/Config/ConfigDescription.h
@@ -146,11 +146,11 @@ public:
 
       using CoercedEntryType = typename ParameterTypeCoercion< EntryType >::type;
       if( isCurrentEntryList ) {
-         ConfigEntryList< CoercedEntryType >& entry = dynamic_cast< ConfigEntryList< CoercedEntryType >& >( *currentEntry );
+         auto& entry = dynamic_cast< ConfigEntryList< CoercedEntryType >& >( *currentEntry );
          entry.getEnumValues().push_back( ParameterTypeCoercion< EntryType >::convert( entryEnum ) );
       }
       else {
-         ConfigEntry< CoercedEntryType >& entry = dynamic_cast< ConfigEntry< CoercedEntryType >& >( *currentEntry );
+         auto& entry = dynamic_cast< ConfigEntry< CoercedEntryType >& >( *currentEntry );
          entry.getEnumValues().push_back( ParameterTypeCoercion< EntryType >::convert( entryEnum ) );
       }
    }
diff --git a/src/TNL/Config/parseCommandLine.h b/src/TNL/Config/parseCommandLine.h
index 3e7a766bbd..db48c08fb3 100644
--- a/src/TNL/Config/parseCommandLine.h
+++ b/src/TNL/Config/parseCommandLine.h
@@ -33,52 +33,52 @@ addDefaultValues( const ConfigDescription& config, ParameterContainer& parameter
       const std::string entry_name = entryBase->getName();
       if( entryBase->hasDefaultValue() && ! parameters.checkParameter( entry_name ) ) {
          if( entryBase->getUIEntryType() == "bool" ) {
-            ConfigEntry< bool >& entry = dynamic_cast< ConfigEntry< bool >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntry< bool >& >( *entryBase );
             parameters.addParameter< bool >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "integer" ) {
-            ConfigEntry< Integer >& entry = dynamic_cast< ConfigEntry< Integer >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntry< Integer >& >( *entryBase );
             parameters.addParameter< Integer >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "unsigned integer" ) {
-            ConfigEntry< UnsignedInteger >& entry = dynamic_cast< ConfigEntry< UnsignedInteger >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntry< UnsignedInteger >& >( *entryBase );
             parameters.addParameter< UnsignedInteger >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "real" ) {
-            ConfigEntry< double >& entry = dynamic_cast< ConfigEntry< double >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntry< double >& >( *entryBase );
             parameters.addParameter< double >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "string" ) {
-            ConfigEntry< std::string >& entry = dynamic_cast< ConfigEntry< std::string >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntry< std::string >& >( *entryBase );
             parameters.addParameter< std::string >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "list of bool" ) {
-            ConfigEntryList< bool >& entry = dynamic_cast< ConfigEntryList< bool >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntryList< bool >& >( *entryBase );
             parameters.addList< bool >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "list of integer" ) {
-            ConfigEntryList< Integer >& entry = dynamic_cast< ConfigEntryList< Integer >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntryList< Integer >& >( *entryBase );
             parameters.addList< Integer >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "list of unsigned integer" ) {
-            ConfigEntryList< UnsignedInteger >& entry = dynamic_cast< ConfigEntryList< UnsignedInteger >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntryList< UnsignedInteger >& >( *entryBase );
             parameters.addList< UnsignedInteger >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "list of real" ) {
-            ConfigEntryList< double >& entry = dynamic_cast< ConfigEntryList< double >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntryList< double >& >( *entryBase );
             parameters.addList< double >( entry_name, entry.getDefaultValue() );
             continue;
          }
          else if( entryBase->getUIEntryType() == "list of string" ) {
-            ConfigEntryList< std::string >& entry = dynamic_cast< ConfigEntryList< std::string >& >( *entryBase );
+            auto& entry = dynamic_cast< ConfigEntryList< std::string >& >( *entryBase );
             parameters.addList< std::string >( entry_name, entry.getDefaultValue() );
             continue;
          }
@@ -273,26 +273,24 @@ parseCommandLine( int argc,
                }
                else if( entryType == "list of integer" ) {
                   const Integer v = convertStringValue< Integer >( value, option );
-                  const ConfigEntryList< Integer >& entry = dynamic_cast< const ConfigEntryList< Integer >& >( *entryBase );
+                  const auto& entry = dynamic_cast< const ConfigEntryList< Integer >& >( *entryBase );
                   checkEnumValues( entry, option, v );
                   integer_list.push_back( v );
                }
                else if( entryType == "list of unsigned integer" ) {
-                  const UnsignedInteger v = convertStringValue< UnsignedInteger >( value, option );
-                  const ConfigEntryList< UnsignedInteger >& entry =
-                     dynamic_cast< const ConfigEntryList< UnsignedInteger >& >( *entryBase );
+                  const auto v = convertStringValue< UnsignedInteger >( value, option );
+                  const auto& entry = dynamic_cast< const ConfigEntryList< UnsignedInteger >& >( *entryBase );
                   checkEnumValues( entry, option, v );
                   unsigned_integer_list.push_back( v );
                }
                else if( entryType == "list of real" ) {
                   const double v = convertStringValue< double >( value, option );
-                  const ConfigEntryList< double >& entry = dynamic_cast< const ConfigEntryList< double >& >( *entryBase );
+                  const auto& entry = dynamic_cast< const ConfigEntryList< double >& >( *entryBase );
                   checkEnumValues( entry, option, v );
                   real_list.push_back( v );
                }
                else if( entryType == "list of string" ) {
-                  const ConfigEntryList< std::string >& entry =
-                     dynamic_cast< const ConfigEntryList< std::string >& >( *entryBase );
+                  const auto& entry = dynamic_cast< const ConfigEntryList< std::string >& >( *entryBase );
                   checkEnumValues( entry, option, value );
                   string_list.push_back( value );
                }
@@ -318,25 +316,24 @@ parseCommandLine( int argc,
             }
             else if( entryType == "integer" ) {
                const Integer v = convertStringValue< Integer >( value, option );
-               const ConfigEntry< Integer >& entry = dynamic_cast< const ConfigEntry< Integer >& >( *entryBase );
+               const auto& entry = dynamic_cast< const ConfigEntry< Integer >& >( *entryBase );
                checkEnumValues( entry, option, v );
                parameters.addParameter< Integer >( option, v );
             }
             else if( entryType == "unsigned integer" ) {
-               const UnsignedInteger v = convertStringValue< UnsignedInteger >( value, option );
-               const ConfigEntry< UnsignedInteger >& entry =
-                  dynamic_cast< const ConfigEntry< UnsignedInteger >& >( *entryBase );
+               const auto v = convertStringValue< UnsignedInteger >( value, option );
+               const auto& entry = dynamic_cast< const ConfigEntry< UnsignedInteger >& >( *entryBase );
                checkEnumValues( entry, option, v );
                parameters.addParameter< UnsignedInteger >( option, v );
             }
             else if( entryType == "real" ) {
                const double v = convertStringValue< double >( value, option );
-               const ConfigEntry< double >& entry = dynamic_cast< const ConfigEntry< double >& >( *entryBase );
+               const auto& entry = dynamic_cast< const ConfigEntry< double >& >( *entryBase );
                checkEnumValues( entry, option, v );
                parameters.addParameter< double >( option, v );
             }
             else if( entryType == "string" ) {
-               const ConfigEntry< std::string >& entry = dynamic_cast< const ConfigEntry< std::string >& >( *entryBase );
+               const auto& entry = dynamic_cast< const ConfigEntry< std::string >& >( *entryBase );
                checkEnumValues( entry, option, (std::string) value );
                parameters.addParameter< std::string >( option, value );
             }
diff --git a/src/TNL/Endianness.h b/src/TNL/Endianness.h
index 2840488f1b..8360f5f80a 100644
--- a/src/TNL/Endianness.h
+++ b/src/TNL/Endianness.h
@@ -46,7 +46,7 @@ inline bool
 isLittleEndian()
 {
    const unsigned int tmp1 = 1;
-   const unsigned char* tmp2 = reinterpret_cast< const unsigned char* >( &tmp1 );
+   const auto* tmp2 = reinterpret_cast< const unsigned char* >( &tmp1 );
    if( *tmp2 != 0 )
       return true;
    return false;
diff --git a/src/TNL/Images/DicomSeries_impl.h b/src/TNL/Images/DicomSeries_impl.h
index 91a0a2f0f7..7cc287a559 100644
--- a/src/TNL/Images/DicomSeries_impl.h
+++ b/src/TNL/Images/DicomSeries_impl.h
@@ -164,7 +164,7 @@ DicomSeries::loadImage( const String& filePath, int number )
 {
 #ifdef HAVE_DCMTK_H
    // load header
-   DicomHeader* header = new DicomHeader();
+   auto* header = new DicomHeader();
    dicomSeriesHeaders.setSize( fileList.size() );
    dicomSeriesHeaders.setElement( number, header );
    if( ! header->loadFromFile( filePath ) )
diff --git a/src/TNL/zlib_compression.h b/src/TNL/zlib_compression.h
index 0e07c6a294..d1a347727b 100644
--- a/src/TNL/zlib_compression.h
+++ b/src/TNL/zlib_compression.h
@@ -105,7 +105,7 @@ decompress_block( const char* data )
    // decode the header
    const int encoded_header_length = base64::get_encoded_length( 4 * sizeof( HeaderType ) );
    std::pair< std::size_t, std::unique_ptr< std::uint8_t[] > > decoded_header = base64::decode( data, encoded_header_length );
-   const HeaderType* compression_header = reinterpret_cast< const HeaderType* >( decoded_header.second.get() );
+   const auto* compression_header = reinterpret_cast< const HeaderType* >( decoded_header.second.get() );
 
    if( compression_header[ 0 ] != 1 )
       throw std::length_error( "unexpected number of compressed blocks: " + std::to_string( compression_header[ 0 ] ) );
@@ -147,7 +147,7 @@ decompress_block( std::istream& input_stream )
    // decode the header
    std::pair< std::size_t, std::unique_ptr< std::uint8_t[] > > decoded_header =
       base64::decode( encoded_header.get(), encoded_header_length );
-   const HeaderType* compression_header = reinterpret_cast< const HeaderType* >( decoded_header.second.get() );
+   const auto* compression_header = reinterpret_cast< const HeaderType* >( decoded_header.second.get() );
 
    if( compression_header[ 0 ] != 1 )
       throw std::length_error( "unexpected number of compressed blocks: " + std::to_string( compression_header[ 0 ] ) );
-- 
GitLab