[Development] QtCS: Notes from Modern C++ session
Marc Mutz
marc.mutz at kdab.com
Fri Jun 12 10:17:21 CEST 2015
Hi Andre,
thanks for the write-up!
On Friday 12 June 2015 08:08:51 André Somers wrote:
> Available for use then:
range-for?
variadic macros (these we already use in tests/ and no-one complained so far).
> No for now: std::for_each (issues with leaks)
Which leaks?
> For now, don’t put std lib ABI into Qt ABI, except for nulltpr_t.
Too late: QException inherits std::exception (for a looong time already), and
by virtue of various exported subclasses of QVector and QList, we export ABI
that contains std::vector and std::list (toStdList(), toStdVector()). We
probably also export ABI using std::string, because I'm sure someone somewhere
has inherited an exported class from QString...
std::list and std::string are BiC in GCC, probably each at different releases,
and probably between C++98 and 11 builds.
FTR: Making std::list::size() O(1) in C++11 was a huge mistake, IMO. It
pessimises the one use-case I have _ever_ used std::list for: splicing. Maybe
forward_list is a replacement now...
> For lambda’s: how to deal with captures? They are dangerous. Default to
> capture by value, capture by reference or pointer is problem.
The first thing *I* think when thinking lambdas is: code bloat. Please be
_very_ careful. Every lambda has it's own unique type, even if they are token-
for-token identical. Using the same one on a template makes the whole template
code duplicate. And I don't know any compiler that does a merge of binary
identical code (does anyone?).
So, when a lambda is used in more than one place, please consider making it a
namespace-level auto variable (only possible if it doesn't use local captures)
or, yes, go the extra mile and write the function object explicitly.
Then again, using a lambda instead of a member-function private slot tends to
leads to more compact executable code (at least than the SLOT()-based
connect()).
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
More information about the Development
mailing list