[Development] What's Q_PRIMITIVE_TYPE for?
Giuseppe D'Angelo
giuseppe.dangelo at kdab.com
Thu Nov 12 15:37:11 CET 2020
Il 12/11/20 15:13, Lars Knoll ha scritto:
>
> Is_trivial() explicitly states that you can memcpy/memmove objects and I
> really want to keep this. With your change, those will by default fall
> back to the complex case, slowing down operations on that list.
The right detection for copies and copy assignments isn't is_trivial,
but is_trivially_copyiable. At the beginning of the thread, I was indeed
confused by this; we are conflating multiple independent semantics into
the "primitive" / "isComplex" case.
Should they be split in *independent* semantics? At least 1/2 are different:
1) Can be value constructed with memset(0)
* Primitive: yes by definition
* Trivial(ly constructible): not in general, see the PDM example
* Relocatable: not in general
2) Can be copy/move constructed/assigned with memcpy
* Primitive: yes by definition
* Trivial(ly copy constructible): yes
* Relocatable: not in general
3) Can be relocated with memcpy
* Primitive: yes by definition
* Trivial(ly copy constructible, destructible): yes
* Relocatable: yes by definition
4) Can be destroyed by just freeing memory
* Primitive: yes by definition
* Trivial(ly destructible): yes
* Relocatable: not in general
(Note: I'm completely ignoring the lifetime issues at just blessing a
block of memory and saying "there are N objects here". Thiago is right,
we shouldn't ignore that. But I'm not sure how, except by biting the
bullet and calling constructors/destructors, then relying on the
compiler to do the right thing.)
--
Language Lawyer Hat: is_trivial is the wrong type trait when it comes to
detect trivial copiability anyhow, example:
struct S { int i; S operator=(const S &)=delete; };
is trivial and not copy assignable. Isn't C++ a fun language to work
with... :P
--
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20201112/45f1d87c/attachment.bin>
More information about the Development
mailing list