r202590 - [C++11] Replace verbose functors with succinct lambdas

Benjamin Kramer benny.kra at gmail.com
Wed Mar 5 03:46:29 PST 2014


On 05.03.2014, at 02:25, Jonathan Roelofs <jonathan at codesourcery.com> wrote:

> 
> 
> On 3/1/14, 6:48 AM, Benjamin Kramer wrote:
>> Modified: cfe/trunk/lib/Driver/Multilib.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Multilib.cpp?rev=202590&r1=202589&r2=202590&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/Multilib.cpp (original)
>> +++ cfe/trunk/lib/Driver/Multilib.cpp Sat Mar  1 08:48:57 2014
>> @@ -338,20 +338,11 @@ MultilibSet::filterCopy(const MultilibSe
>>    return Copy;
>>  }
>> 
>> -namespace {
>> -// Wrapper for FilterCallback to make operator() nonvirtual so it
>> -// can be passed by value to std::remove_if
>> -class FilterWrapper {
>> -  const MultilibSet::FilterCallback &F;
>> -public:
>> -  FilterWrapper(const MultilibSet::FilterCallback &F) : F(F) {}
>> -  bool operator()(const Multilib &M) const { return F(M); }
>> -};
>> -} // end anonymous namespace
>> -
>>  void MultilibSet::filterInPlace(const MultilibSet::FilterCallback &F,
>>                                  multilib_list &Ms) {
>> -  Ms.erase(std::remove_if(Ms.begin(), Ms.end(), FilterWrapper(F)), Ms.end());
>> +  Ms.erase(std::remove_if(Ms.begin(), Ms.end(),
>> +                          [&F](const Multilib &M) { return F(M); }),
> IMHO `std::cref(F)` would be even more succinct than the lambda for this case. (That's what I had originally intended to write here, but couldn't because we didn't have c++11 turned on at the time).

Good idea; replaced the λ with std::cref in r202968.

- Ben

>> +           Ms.end());
>>  }
>> 
>>  raw_ostream &clang::driver::operator<<(raw_ostream &OS, const MultilibSet &MS) {
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> 
> 
> -- 
> Jon Roelofs
> jonathan at codesourcery.com
> CodeSourcery / Mentor Embedded





More information about the cfe-commits mailing list