<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div>
<blockquote type="cite" class="">
<div class="">On 12 Nov 2020, at 15:37, Giuseppe D'Angelo <<a href="mailto:giuseppe.dangelo@kdab.com" class="">giuseppe.dangelo@kdab.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Il 12/11/20 15:13, Lars Knoll ha scritto:<br class="">
<blockquote type="cite" class="">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.<br class="">
</blockquote>
<br class="">
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.<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
is_trivial implies is_trivially_copyable, see <a href="https://en.cppreference.com/w/cpp/types/is_trivial" class="">https://en.cppreference.com/w/cpp/types/is_trivial</a>.</div>
<div><span class="Apple-tab-span" style="white-space: pre;"></span></div>
<div>
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
<br class="">
Should they be split in *independent* semantics? At least 1/2 are different:<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
I was thinking about that as well, but that’s more refactoring that I’m willing to do just now before 6.0. Maybe for 6.1?<br class="">
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
1) Can be value constructed with memset(0)<br class="">
 * Primitive: yes by definition<br class="">
 * Trivial(ly constructible): not in general, see the PDM example<br class="">
 * Relocatable: not in general<br class="">
<br class="">
2) Can be copy/move constructed/assigned with memcpy<br class="">
 * Primitive: yes by definition<br class="">
 * Trivial(ly copy constructible): yes<br class="">
 * Relocatable: not in general<br class="">
<br class="">
3) Can be relocated with memcpy<br class="">
 * Primitive: yes by definition<br class="">
 * Trivial(ly copy constructible, destructible): yes<br class="">
 * Relocatable: yes by definition<br class="">
<br class="">
4) Can be destroyed by just freeing memory<br class="">
 * Primitive: yes by definition<br class="">
 * Trivial(ly destructible): yes<br class="">
 * Relocatable: not in general<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
So except for the memset(0) for default construction, Primitive and Trivial have the same conditions in your list here. My proposal would be to drop the memset(0) optimisation and with that unify those two groups.<br class="">
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
(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.)<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
Those lifetime issues need to be tackled differently. One option could be to abandon all our optimizations in a checked build, and only enable them in release mode.<br class="">
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
--<br class="">
<br class="">
Language Lawyer Hat: is_trivial is the wrong type trait when it comes to detect trivial copiability anyhow, example:<br class="">
<br class="">
 struct S { int i; S operator=(const S &)=delete; };<br class="">
<br class="">
is trivial and not copy assignable. Isn't C++ a fun language to work with... :P<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Sigh… is_trival implies is_trivially_copyable. That one implies <a href="https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable" class="">https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable</a>, which implies that all “eligible” copy/move
 constructor and assignment operators are trivial. But they don’t disallow deleting them (as that makes the operator not eligible).</div>
<div><br class="">
</div>
<div>So what are the correct traits then? Sounds like “is_trivially_copyable and no deleted copy/move operators” is about what we need :/</div>
<div><br class="">
</div>
<div>Cheers,</div>
<div>Lars</div>
<div><br class="">
</div>
</div>
<br class="">
</body>
</html>