<div dir="ltr"><div dir="ltr">On Wed, Nov 6, 2019 at 10:28 PM Thiago Macieira <<a href="mailto:thiago@macieira.org" target="_blank">thiago@macieira.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesday, 6 November 2019 12:34:23 PST JeanHeyd Meneide wrote:<br>
> It is not exactly trivial for #embed or #embed_str. #embed generates a<br>
> brace-delimeted list of the bytes. It's as if the contents are directly<br>
> replaced by:<br>
> <br>
> { 102, 111, 111 }<br>
> <br>
> You cannot "just append" a null terminator in there, so it would<br>
> require a copy. If that's okay (copying things), then we can throw<br>
> #embed_str out the window. As far as requiring bytes, you would need to<br>
> generate a brace-delimeted list with all of the entries cast to the right<br>
> type, because each of those entries is not trivially convertible to a<br>
> std::byte: <a href="https://godbolt.org/z/NRkSfK" rel="noreferrer" target="_blank">https://godbolt.org/z/NRkSfK</a><br>
<br>
It's easy to add the terminating null with constexpr. And that function should <br>
be provided. Similarly, it should be easy to concatenate such arrays.<br></blockquote><div><br></div><div>Arrays in C++ (and C) do not have any syntax or behavior for compile-time concatenation. String literals get away with it by having "foo" "bar" be acceptable syntax, meaning someone could add a null terminator with "\0" for #embed_str, but not #embed.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
It should be easy to import non-terminated byte data, null-terminated byte <br>
data and UTF-8 text.<br>
<br>
SG16 should also provide a way to constexpr-time convert UTF-8 text to UTF-16 <br>
or UTF-32<br></blockquote><div><br></div><div>That is something I am already working on (and a separate proposal); all of the UTF8/16/32 encoding objects are constexpr, and one of Corentin's upcoming papers is a consteval ways to detect the compile-time literal encoding. That should be enough.<br><br></div><div>I think this is highlighting that #embed is the only thing we need, and that #embed_str only real benefit is a null terminating code unit and that there should be better ways to provide that to the user.<br></div></div></div>