Issue |
133583
|
Summary |
[clang-tidy] Check request: boost-use-lambda2
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
denzor200
|
C++11 lambdas are known to be cumbersome. Even for a simple STL algorithm predicate its mandatory to specify:
-Three different braces;
-List of arguments;
-Return statement with the _expression_.
While specifying only the _expression_ would be more than enough for STL algorithms. Thats the reason why some programmers refrain from STL algorithms usage and would prefer to write manual `for` loop. The [Boost Lambda 2 library](https://www.boost.org/doc/libs/1_87_0/libs/lambda2/doc/html/lambda2.html) is intended to resolve the described problem.
Need a check that will find a C++11 lambdas which might be converted to lambdas from Boost Lambda 2 and will suggest to convert them.
BEFORE:
```
int count_even( int const * first, int const * last )
{
return std::count_if( first, last, [](int val) {
return val % 2 == 0;
});
}
char const * find_whitespace( char const * first, char const * last )
{
return std::find_if( first, last, [](char ch) {
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
});
}
void print( std::map<int, std::string> const & m )
{
std::for_each( m.begin(), m.end(), [](const auto& node) {
std::cout << node->first << ": " << node->second << '\n';
});
}
```
AFTER:
```
int count_even( int const * first, int const * last )
{
using namespace boost::lambda2;
return std::count_if( first, last, _1 % 2 == 0 );
}
char const * find_whitespace( char const * first, char const * last )
{
using namespace boost::lambda2;
return std::find_if( first, last,
_1 == ' ' || _1 == '\t' || _1 == '\r' || _1 == '\n' );
}
void print( std::map<int, std::string> const & m )
{
using namespace boost::lambda2;
std::for_each( m.begin(), m.end(),
std::cout << _1->*first << ": " << _1->*second << '\n' );
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs