<br><br>On Tuesday, December 12, 2023, Thiago Macieira wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tuesday, 12 December 2023 15:11:00 -03 Frederick Virchanza Gotham via Std-<br>
Proposals wrote:<br>
&gt; I don&#39;t know if it would ever make sense to have an<br>
&gt; &#39;unaligned&lt;std::string&gt;&#39;<br>
<br>
It doesn&#39;t. Unaligned only makes sense if you&#39;re trying to match the layout as <br>
specified by some external ABI, which means it is not std::string or any <br>
complex type.<br>
</blockquote><div><br></div><div><br></div><div>In a previous post, I gave two use cases for &#39;unaligned&#39;:</div><div>(1) Reading fields from a header from a file or network card</div><div>(2) Conserving RAM / EEPROM</div><div><br></div><div>On a desktop PC, if you had a million strings in a vector, you could possibly instead use an &#39;unaligned_vector&#39; which would wrap T in &#39;aligned&#39;. This would save some space if std::string has any tail padding. Actually if &#39;std::string&#39; contains padding other than tail padding, i.e. passing between members, then we could save even more space with:</div><div><br></div><div>    using packed_str = std::string - padding;</div><div><br></div><div>Of course though if we were to have an object of &#39;packed_str&#39;, it would need to be memcpy&#39;d back to an std:: string before performing any operation on it.</div><div><br></div><div>But anyway std::string was just an arbitrary example in order to show that we need not restrict what &#39;unaligned&#39; can be used for -- perhaps someone in the future will fathom a new use case.</div><div><br></div><div> <br></div>

