[Development] Proposal: Deprecating platforms in Qt 5.6 that don't support lambda

Matthew Woehlke mw_triad at users.sourceforge.net
Fri Feb 20 18:33:56 CET 2015

On 2015-02-20 04:04, André Somers wrote:
> One example I could come up with as a potential new API is 
> QSortFilterProxyModel. Currently, it requires subclassing to change the 
> sort or the filter functions: it supplies protected filterAcceptsRow, 
> filterAcceptsColumn and lessThan functions. I think that it would be 
> much more convenient if these filters and the comparator could be 
> supplied as a function object (a lambda, or a functor, or a std::mem_fn, 
> anything callable as a function). While this wasn't all that practical 
> in the past, I think C++/11 makes this much more convenient than 
> subclassing.

While that would certainly work... I'm not entirely convinced I would
actually use it. Not with lambdas, anyway, unless they just handed off
to member functions anyway. This sort of thing is above my threshold of
'things I'd want in inline (source-inline, i.e. lambdas) functions'.

That said... QThread. Taking a functor that can be a lambda for
something like QtConcurrent::run (which I think may already do this) or
to replace the run() of a QThread seems useful.

There are probably other examples along similar lines as QThread and
QSortFilterProxyModel where currently one must override a virtual method
that might be much easier to use a stateful functor instead.

Another thing that might be useful is variadic templates. I suspect
there are a number of places that right now have overloads for 0-N / 1-N
arguments or use default parameters to achieve similar effects that
could use variadic templates instead. (QMetaObject::invokeMethod and
QString::arg come to mind...)


More information about the Development mailing list