Topic: static_string


Author: Benjamin Lindley <benjameslindley@gmail.com>
Date: Wed, 16 Sep 2015 11:00:28 -0700 (PDT)
Raw View
------=_Part_3542_211486315.1442426428271
Content-Type: multipart/alternative;
 boundary="----=_Part_3543_57293726.1442426428272"

------=_Part_3543_57293726.1442426428272
Content-Type: text/plain; charset=UTF-8

String literals (or rather, the arrays they refer to) have a couple of very
useful guaranteed properties. They are constant, and they have static
storage duration. Unfortunately, there's not much we can do to exploit
these properties, because there is no syntax to detect them in function
signatures. I would personally prefer that there was such a syntax, but
barring that, I would propose the following library solution. A class,
static_string, which has most of the same functionality as string_view,
except for the constructors. It should have a private constructor:

private:
    constexpr static_string(char const* _begin, size_t _count) noexcept;

Copy construction would be public, but the only way to construct a new
static_string would be through a string literal. And since we can't detect
string literals, we would have to do it through a user-defined literal
function, which would use the above constructor (it would of course need to
be a friend)

constexpr static_string operator""_ss(char const* _lit, size_t _count)
noexcept {
    return static_string(_lit, _count);
}

With this extension, we could pass around strings and chop them up very
cheaply (like string_view offers), but also have the extra guarantees that
the string will never be invalidated, and that nobody can change the
characters through some other non-const pathway. The class could of course
be converted to, but not from, string_view.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_3543_57293726.1442426428272
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">String literals (or rather, the arrays they refer to) have=
 a couple of very useful guaranteed properties. They are constant, and they=
 have static storage duration. Unfortunately, there&#39;s not much we can d=
o to exploit these properties, because there is no syntax to detect them in=
 function signatures. I would personally prefer that there was such a synta=
x, but barring that, I would propose the following library solution. A clas=
s, static_string, which has most of the same functionality as string_view, =
except for the constructors. It should have a private constructor:<div><br>=
</div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 1=
87, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">private</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">constexpr</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> static_string</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">char</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> _begin</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> size_t _co=
unt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> noexcept</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div></c=
ode></div><br><div>Copy construction would be public, but the only way to c=
onstruct a new static_string would be through a string literal. And since w=
e can&#39;t detect string literals, we would have to do it through a user-d=
efined literal function, which would use the above constructor (it would of=
 course need to be a friend)</div></div><div><br></div><div><div class=3D"p=
rettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break=
-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><div class=3D"subprettyprint">constexpr static=
_string operator&quot;&quot;_ss(char const* _lit, size_t _count) noexcept {=
</div><div class=3D"subprettyprint">=C2=A0 =C2=A0 return static_string(_lit=
, _count);</div><div class=3D"subprettyprint">}</div></div></code></div><br=
>With this extension, we could pass around strings and chop them up very ch=
eaply (like string_view offers), but also have the extra guarantees that th=
e string will never be invalidated, and that nobody can change the characte=
rs through some other non-const pathway. The class could of course be conve=
rted to, but not from, string_view.</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3543_57293726.1442426428272--
------=_Part_3542_211486315.1442426428271--

.


Author: "dgutson ." <danielgutson@gmail.com>
Date: Wed, 16 Sep 2015 15:14:47 -0300
Raw View
--001a1140c2a82289d1051fe1467e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Please see the static_alloc thread, which goal is to have STL containers in
ROM (where the string is the most basic example). We have a working
prototype with strings and sets as a use case.
El 16/9/2015 15:00, "Benjamin Lindley" <benjameslindley@gmail.com> escribi=
=C3=B3:

> String literals (or rather, the arrays they refer to) have a couple of
> very useful guaranteed properties. They are constant, and they have stati=
c
> storage duration. Unfortunately, there's not much we can do to exploit
> these properties, because there is no syntax to detect them in function
> signatures. I would personally prefer that there was such a syntax, but
> barring that, I would propose the following library solution. A class,
> static_string, which has most of the same functionality as string_view,
> except for the constructors. It should have a private constructor:
>
> private:
>     constexpr static_string(char const* _begin, size_t _count) noexcept;
>
> Copy construction would be public, but the only way to construct a new
> static_string would be through a string literal. And since we can't detec=
t
> string literals, we would have to do it through a user-defined literal
> function, which would use the above constructor (it would of course need =
to
> be a friend)
>
> constexpr static_string operator""_ss(char const* _lit, size_t _count)
> noexcept {
>     return static_string(_lit, _count);
> }
>
> With this extension, we could pass around strings and chop them up very
> cheaply (like string_view offers), but also have the extra guarantees tha=
t
> the string will never be invalidated, and that nobody can change the
> characters through some other non-const pathway. The class could of cours=
e
> be converted to, but not from, string_view.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--001a1140c2a82289d1051fe1467e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">Please see the static_alloc thread, which goal is to have ST=
L containers in ROM (where the string is the most basic example). We have a=
 working prototype with strings and sets as a use case.<br>
</p>
<div class=3D"gmail_quote">El 16/9/2015 15:00, &quot;Benjamin Lindley&quot;=
 &lt;<a href=3D"mailto:benjameslindley@gmail.com">benjameslindley@gmail.com=
</a>&gt; escribi=C3=B3:<br type=3D"attribution"><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr">String literals (or rather, the arrays they refer to) =
have a couple of very useful guaranteed properties. They are constant, and =
they have static storage duration. Unfortunately, there&#39;s not much we c=
an do to exploit these properties, because there is no syntax to detect the=
m in function signatures. I would personally prefer that there was such a s=
yntax, but barring that, I would propose the following library solution. A =
class, static_string, which has most of the same functionality as string_vi=
ew, except for the constructors. It should have a private constructor:<div>=
<br></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:br=
eak-word;background-color:rgb(250,250,250)"><code><div><span style=3D"color=
:#008">private</span><span style=3D"color:#660">:</span><span style=3D"colo=
r:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span=
><span style=3D"color:#000"> static_string</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#008">char</span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">const</span><span style=3D"color:#660">*<=
/span><span style=3D"color:#000"> _begin</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> size_t _count</span><span style=3D"color=
:#660">)</span><span style=3D"color:#000"> noexcept</span><span style=3D"co=
lor:#660">;</span></div></code></div><br><div>Copy construction would be pu=
blic, but the only way to construct a new static_string would be through a =
string literal. And since we can&#39;t detect string literals, we would hav=
e to do it through a user-defined literal function, which would use the abo=
ve constructor (it would of course need to be a friend)</div></div><div><br=
></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><div>constexpr static_s=
tring operator&quot;&quot;_ss(char const* _lit, size_t _count) noexcept {</=
div><div>=C2=A0 =C2=A0 return static_string(_lit, _count);</div><div>}</div=
></div></code></div><br>With this extension, we could pass around strings a=
nd chop them up very cheaply (like string_view offers), but also have the e=
xtra guarantees that the string will never be invalidated, and that nobody =
can change the characters through some other non-const pathway. The class c=
ould of course be converted to, but not from, string_view.</div></div>

<p></p>

-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a1140c2a82289d1051fe1467e--

.