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 | [email protected] | 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

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to