[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-frameworks-devel
Subject: Re: Noteworthy changes when porting to C++17
From: Ivan =?utf-8?B?xIx1a2nEhw==?= <ivan.cukic () kde ! org>
Date: 2021-07-19 11:05:57
Message-ID: 20807188.7Cn9Wyc7rS () drako
[Download RAW message or body]
> > What I have seen is that std::mem_fun was used within KIO and has been
> > replaced by std::mem_fn. Not sure if that counts as "commonly used",
> > though.
> Imo, usages of either of these two should be rewritten to use lambdas
> instead.
-1
Member function pointers are more readable than lambdas in cases
where they can be used (std::ranges). Sadly, mem_fn is a syntactic noise
meant as an excuse why some things don't accept all invokables/callables
but only function objects. But, while it is uglier than just a pointer to a
member function, I still find it more readable then lambdas. And it is
optimized out by good compilers (tested on gcc 10) just as lambdas are.
std::ranges::all_of(vs, &some_t::check);
versus
std::all_of(..., std::mem_fn(&some_t::check));
versus
std::all_of(..., [] (const some_t& t) {
return t.check();
});
Cheers,
Ivan
--
dr Ivan Čukić
ivan@cukic.co, https://cukic.co/
gpg key fingerprint: 8FE4 D32F 7061 EA9C 8232 07AE 01C6 CE2B FF04 1C12
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic