Skip to content

Commit

Permalink
environment: Use std::find_if() instead of range-based for loops (#1260)
Browse files Browse the repository at this point in the history
`std::find_if()`が使えるとcppcheckに指摘されたためforループ文を
修正します。

cppcheck 2.11.1のレポート
```
src/environment.cpp:261:13: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm]
            {
            ^
```
  • Loading branch information
ma8ma committed Sep 30, 2023
1 parent 350e30a commit 2129ed2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/environment.cpp
Expand Up @@ -251,17 +251,15 @@ std::string ENVIRONMENT::get_distname()
else if( CACHE::load_rawdata( "/etc/release", text_data ) )
{
std::list< std::string > lines = MISC::get_lines( text_data );
for( std::string& line : lines )
{
// 名前が含まれている行を取得
if( line.find( "BeleniX" ) != std::string::npos
|| line.find( "Nexenta" ) != std::string::npos
|| line.find( "SchilliX" ) != std::string::npos
|| line.find( "Solaris" ) != std::string::npos )
{
tmp = std::move( line );
break;
}
auto it = std::find_if( lines.begin(), lines.end(),
// 名前が含まれている行を取得
[]( const std::string& line )
{ return line.find( "BeleniX" ) != std::string::npos
|| line.find( "Nexenta" ) != std::string::npos
|| line.find( "SchilliX" ) != std::string::npos
|| line.find( "Solaris" ) != std::string::npos; } );
if( it != lines.end() ) {
tmp = std::move( *it );
}
}
// ファイルの中身がそのままディストリ名として扱える物
Expand Down

0 comments on commit 2129ed2

Please sign in to comment.