Topic: Formatted static_assert and nameof
Author: Chris Gary <cgary512@gmail.com>
Date: Thu, 19 Feb 2015 09:33:33 -0800 (PST)
Raw View
------=_Part_1589_997308972.1424367213547
Content-Type: multipart/alternative;
boundary="----=_Part_1590_662027569.1424367213548"
------=_Part_1590_662027569.1424367213548
Content-Type: text/plain; charset=UTF-8
This has been posted somewhere before, asked about before in other places,
thought about and not attempted (AFAIK)... Can't find it here though....
Some code:
template<typename CantBeWeirdType>
class complicated
{
static_assert(
! is_weird<CantBeWeirdType>::value,
"Can't create a complicated<%[0]>, %[0] is weird!\n"
"Also %0 is %1 bytes in size, which is probably bad!\n"
"The alignment of %[0] is 0x%xp[2], which is not supported!",
// Argument 0: Plain string literal (unqualified name)
nameof(CantBeWeirdType),
// Argument 1: Lossless string literal in base-10 by default
sizeof(CantBeWeirdType)
// Argument 2: Lossless string literal in base-16 (%x)
// E.G: ABCD (no 0x)
alignof(CantBeWeirdType)
);
template<typename ArgumentType>
void f(ArgumentType &&x)
{
static_assert(
! is_weird<decay<ArgumentType>>::value,
"Argument %[0] is of a weird type!\n",
// Unqualified name, (reduces to "x", but using symbols helps
refactoring tools...)
nameof(x)
);
}
};
When complicated<> is given a weird_thing:
Error <line><file>: Can't create a complicated<weird_thing>, weird_thing is
weird!
Also, weird_thing is 42 bytes in size, which is
probably bad!
The alignment of weird_thing is 0x0000DC81, which is
not acceptable!
Proposal:
//nameof, qnameof, and dnameof
namespace space_of_names{
struct type{};
}
// Expands to string literal "type"
auto name_str = nameof(space_of_names::type);
// Expands to string literal "space_of_names::type"
auto qname_str = qnameof(space_of_names::type);
// Expands to string literal ".?QUtype@space_of_names@@" (through MSVC)
auto dname_str = dnameof(space_of_names::type);
// And similarly for variable names.
static_assert format specifiers:
%<style-opt><width-opt><[base-10 arg index]>
<style> is one of:
'' <- Decimal (nil)
'x' <- Hexadecimal
'o' <- Octal
'b' <- Binary
<width> can be a base-10 number of spaces to pad up to
or 'p' for 'width of pointer'. Integers are 0-padded,
strings are space-padded.
If an index is out of range, the output prints "ERANGE" in place of the
argument.
Incomplete? Done already? Useful? Not useful? Too hard? Too easy? Niche?
Sufficiently eclipsed by concepts?
I've lost track of how many times a simple type or variable name could
clarify a static_assert error...
--
---
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_1590_662027569.1424367213548
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This has been posted somewhere before, asked about before =
in other places, thought about and not attempted (AFAIK)... Can't find it h=
ere though....<br><br>Some code:<br><br><div class=3D"prettyprint" style=3D=
"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bo=
rder-style: solid; border-width: 1px; word-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;"=
class=3D"styled-by-prettify">template</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">CantBeWeirdType</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">></span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> complicated<br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">static_assert</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">!</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> is_weird</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">CantBeWeirdType</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">>::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">value</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
br> </span><span style=3D"color: #080;" class=3D=
"styled-by-prettify">"Can't create a complicated<%[0]>, %[0] is weird=
!\n"</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; </span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">"Also %0 is %1 bytes in size, which is probably bad!\n"</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #080;" class=3D"styled-by-pr=
ettify">"The alignment of %[0] is 0x%xp[2], which is not supported!"</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br> &nbs=
p; </span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
// Argument 0: Plain string literal (unqualified name)</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br> =
nameof</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">CantBeWeirdT=
ype</span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; <br> </span><span style=3D"colo=
r: #800;" class=3D"styled-by-prettify">// Argument 1: Lossless string liter=
al in base-10 by default</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br> </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">CantBeWeirdType</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br> <br>  =
; </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ Argument 2: Lossless string literal in base-16 (%x)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// E.G: AB=
CD (no 0x)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">alignof</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">CantBeWeirdType</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br> </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">ArgumentType</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> f</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ar=
gumentType</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&&=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">x</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> =
<br> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">static_assert</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">!</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> is_weird</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">decay</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">ArgumentType</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">>>::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">value</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><spa=
n style=3D"color: #080;" class=3D"styled-by-prettify">"Argument %[0] is of =
a weird type!\n"</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
> <br> =
</span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">// Unqualified name, (reduces to "x", but using symbols helps refactori=
ng tools...)</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br> nameof</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">x</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br><br>When=
complicated<> is given a weird_thing:<br><br><div class=3D"prettypri=
nt" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 1=
87, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Error</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify"><line><file></span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Can</span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">'t create a complicated<weird_thing>, weird_thing is=
weird!<br> &=
nbsp; Also, weird_thing is 42 bytes in size, which is probably bad!<br>&nbs=
p; The align=
ment of weird_thing is 0x0000DC81, which is not acceptable!<br></span></div=
></code></div><br>Proposal:<br><br><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">//nameof, qnameof, and dnameof</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> <br> =
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">n=
amespace</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s=
pace_of_names</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> type</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{};</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> <br> </span><span style=3D"color: #800;" clas=
s=3D"styled-by-prettify">// Expands to string literal "type"</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> name_str </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> nameof</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">space_of_names</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">type</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br> <br> </span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// Expands to string literal "sp=
ace_of_names::type"</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> qname_str </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> qnameof</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">space_=
of_names</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">type</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> <br>&n=
bsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// Expands to string literal ".?QUtype@space_of_names@@" (through MSVC)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &=
nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> dname_str=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> dnameof</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">space_of_names</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">type</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br> <br> </span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// And similarly fo=
r variable names.</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span></div></code></div><br><br>static_assert format specifier=
s:<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 25=
0, 250); border-color: rgb(187, 187, 187); border-style: solid; border-widt=
h: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">&n=
bsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">%<</span><span style=3D"color: #000;" class=3D"styled-by-prettify">sty=
le</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">opt</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">><</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">width</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">opt</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">><[</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">base</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">-</span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">10</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> arg index</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">]></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> <br> </span><span style=3D"color: #080;" class=
=3D"styled-by-prettify"><style></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">is</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> one of</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r> <br> </span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">''</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify"><-</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Decimal=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">nil</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br> </span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">'x'</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><-</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Hexadecimal</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br> </span><span style=3D"color: #080;" class=3D"s=
tyled-by-prettify">'o'</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><-</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">Octal</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
; </span><span style=3D"color: #080;" class=3D"styled-by-prettify">'b'</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><-</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Binary</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify"><width></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> can be a </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">base</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">10</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> number of spaces to pad up to<br> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">or</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #080;" class=3D"styled-by-prettify">'p'</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">for</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">'width of pointer'</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Integers</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> are </span><span style=3D"color: #066;" class=3D"styled-by-prettify">0=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">padded</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> strings are sp=
ace</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">padded</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><br>If an index is out of range, the output prints "ERANGE" in place of t=
he argument.<br><br>Incomplete? Done already? Useful? Not useful? Too hard?=
Too easy? Niche? Sufficiently eclipsed by concepts?<br><br>I've lost track=
of how many times a simple type or variable name could clarify a static_as=
sert error...<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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_1590_662027569.1424367213548--
------=_Part_1589_997308972.1424367213547--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 19 Feb 2015 19:39:08 +0200
Raw View
On 19 February 2015 at 19:33, Chris Gary <cgary512@gmail.com> wrote:
> Incomplete? Done already? Useful? Not useful? Too hard? Too easy? Niche?
> Sufficiently eclipsed by concepts?
Seems like SG7 material, a combination of reflection and compile-time strings.
Somewhat hard, somewhat niche, not useful enough imho to put all of that
functionality into static assert. Most of the necessary pieces might
become available
in the future and then you could combine them generally.
--
---
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/.
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Thu, 19 Feb 2015 12:39:48 -0600
Raw View
--089e0160b4b41b443b050f75456d
Content-Type: text/plain; charset=UTF-8
On 19 February 2015 at 11:39, Ville Voutilainen <ville.voutilainen@gmail.com
> wrote:
> On 19 February 2015 at 19:33, Chris Gary <cgary512@gmail.com> wrote:
> > Incomplete? Done already? Useful? Not useful? Too hard? Too easy? Niche?
> > Sufficiently eclipsed by concepts?
>
> Seems like SG7 material, a combination of reflection and compile-time
> strings.
> Somewhat hard, somewhat niche, not useful enough imho to put all of that
> functionality into static assert. Most of the necessary pieces might
> become available
> in the future and then you could combine them generally.
>
I just wonder if there is some middle ground.
After all, if you do:
static_assert(sizeof(int) == 4);
and it fires, it is useful to see what sizeof(int) is in the message.
Right now when I need this kind of thing, I use undefined template
specializations so that the number I'm trying to output shows up
cryptically in the error message:
template<typename T, T v>
struct Expected : std::integral_constant<T, v> {};
template<typename T, T v>
struct Actual : std::integral_constant<T, v> {};
template<typename E, typename A>
struct AssertEqual;
template<template<typename LL, LL> class L, template<typename RR, RR> class
R, typename T, T v>
struct AssertEqual<L<T, v>, R<T, v>> : std::true_type {};
static_assert(AssertEqual<Expected<size_t, 4>, Actual<size_t, sizeof(int)>>(),
"UGH");
We should be able to do better, not that I know what such a proposal would
look like...
--
Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
--
---
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/.
--089e0160b4b41b443b050f75456d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 19 February 2015 at 11:39, Ville Voutilainen <span dir=
=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blan=
k">ville.voutilainen@gmail.com</a>></span> wrote:<br><div class=3D"gmail=
_extra"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><span class=3D"">On 19=
February 2015 at 19:33, Chris Gary <<a href=3D"mailto:cgary512@gmail.co=
m">cgary512@gmail.com</a>> wrote:<br>
> Incomplete? Done already? Useful? Not useful? Too hard? Too easy? Nich=
e?<br>
> Sufficiently eclipsed by concepts?<br>
<br>
</span>Seems like SG7 material, a combination of reflection and compile-tim=
e strings.<br>
Somewhat hard, somewhat niche, not useful enough imho to put all of that<br=
>
functionality into static assert. Most of the necessary pieces might<br>
become available<br>
in the future and then you could combine them generally.<br></blockquote><d=
iv><br></div><div>I just wonder if there is some middle ground.</div><div><=
br></div><div>After all, if you do:</div><div><br></div><div><p style=3D"ma=
rgin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">static_ass=
ert<span style=3D"color:rgb(0,0,0)">(</span>sizeof<span style=3D"color:rgb(=
0,0,0)">(</span>int<span style=3D"color:rgb(0,0,0)">) =3D=3D </span><span s=
tyle=3D"color:rgb(39,42,216)">4</span><span style=3D"color:rgb(0,0,0)">);</=
span></p></div><div><span style=3D"color:rgb(0,0,0)"><br></span></div><div>=
and it fires, it is useful to see what sizeof(int) is in the message.</div>=
<div><br></div><div>Right now when I need this kind of thing, I use undefin=
ed template specializations so that the number I'm trying to output sho=
ws up cryptically in the error message:</div><div><br></div><div><p style=
=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p><p=
style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)=
">template<span style=3D"color:rgb(0,0,0)"><</span>typename<span style=
=3D"color:rgb(0,0,0)"> T, T v></span></p><p style=3D"margin:0px;font-siz=
e:11px;font-family:Menlo"><span style=3D"color:rgb(187,44,162)">struct</spa=
n> Expected : std::integral_constant<T, v> {};</p><p style=3D"margin:=
0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p><p style=3D"m=
argin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)">template<=
span style=3D"color:rgb(0,0,0)"><</span>typename<span style=3D"color:rgb=
(0,0,0)"> T, T v></span></p><p style=3D"margin:0px;font-size:11px;font-f=
amily:Menlo"><span style=3D"color:rgb(187,44,162)">struct</span> Actual : s=
td::integral_constant<T, v> {};</p><p style=3D"margin:0px;font-size:1=
1px;font-family:Menlo;min-height:13px"><br></p><p style=3D"margin:0px;font-=
size:11px;font-family:Menlo;color:rgb(187,44,162)">template<span style=3D"c=
olor:rgb(0,0,0)"><</span>typename<span style=3D"color:rgb(0,0,0)"> E, </=
span>typename<span style=3D"color:rgb(0,0,0)"> A></span></p><p style=3D"=
margin:0px;font-size:11px;font-family:Menlo"><span style=3D"color:rgb(187,4=
4,162)">struct</span> AssertEqual;</p><p style=3D"margin:0px;font-size:11px=
;font-family:Menlo;min-height:13px"><br></p><p style=3D"margin:0px;font-siz=
e:11px;font-family:Menlo;color:rgb(187,44,162)">template<span style=3D"colo=
r:rgb(0,0,0)"><</span>template<span style=3D"color:rgb(0,0,0)"><</spa=
n>typename<span style=3D"color:rgb(0,0,0)"> LL, LL> </span>class<span st=
yle=3D"color:rgb(0,0,0)"> L, </span>template<span style=3D"color:rgb(0,0,0)=
"><</span>typename<span style=3D"color:rgb(0,0,0)"> RR, RR> </span>cl=
ass<span style=3D"color:rgb(0,0,0)"> R, </span>typename<span style=3D"color=
:rgb(0,0,0)"> T, T v></span></p><p style=3D"margin:0px;font-size:11px;fo=
nt-family:Menlo"><span style=3D"color:rgb(187,44,162)">struct</span> Assert=
Equal<L<T, v>, R<T, v>> : std::true_type {};</p><p style=
=3D"margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p><p=
style=3D"margin:0px;font-size:11px;font-family:Menlo;color:rgb(187,44,162)=
">
</p><p style=3D"margin:0px;font-size:11px;font-family:Menlo"><span style=3D=
"color:rgb(187,44,162)">static_assert</span>(AssertEqual<Expected<siz=
e_t, <span style=3D"color:rgb(39,42,216)">4</span>>, Actual<size_t, <=
span style=3D"color:rgb(187,44,162)">sizeof</span>(<span style=3D"color:rgb=
(187,44,162)">int</span>)>>(), <span style=3D"color:rgb(209,47,27)">&=
quot;UGH"</span>);</p></div><div><br></div><div><br></div><div>We shou=
ld be able to do better, not that I know what such a proposal would look li=
ke...</div></div>-- <br><div class=3D"gmail_signature">=C2=A0Nevin ":-=
)" Liber=C2=A0 <mailto:<a href=3D"mailto:nevin@eviloverlord.com" ta=
rget=3D"_blank">nevin@eviloverlord.com</a>>=C2=A0 (847) 691-1404</div>
</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" 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 />
--089e0160b4b41b443b050f75456d--
.
Author: Chris Gary <cgary512@gmail.com>
Date: Sat, 21 Feb 2015 05:36:05 -0800 (PST)
Raw View
------=_Part_1280_709215807.1424525765534
Content-Type: multipart/alternative;
boundary="----=_Part_1281_1255827399.1424525765535"
------=_Part_1281_1255827399.1424525765535
Content-Type: text/plain; charset=UTF-8
> *snip*
>
> We should be able to do better, not that I know what such a proposal would
> look like...
>
These type-safe string formatting APIs are so easy to write its almost
funny.
The only reason printf, ostream, et. al. are a PITA to implement is due to
their type-awareness: printf is a "god method" and "<<" with ostream needs
to be overridden for each and every printable type, creating a kludgey
dependency on IO.
We could require all arguments to static_assert to be strings, and just
provide a way, at compile time, to create formatted strings out of
constants.
Even better, why not just one new utility that just formats strings, and
just use that inside of static_assert:
class coconuts{};
coconuts bunch{};
static const size_t count = 55;
// Inherits the width of the format string.
//
// vnameof() applies only to variables:
// Probably has other options, just makes a lossless base-10 string literal
by default.
//
const auto *str = static_format("I've got a lovely %0 of %2 %1",
nameof(coconuts), nameof(bunch), vnameof(count));
Hardly complete, but the idea is that format specifiers would be replaced
instead by argument specifiers for the sake of type agnosticism.
As opposed to stringifying through the preprocessor, you get type names and
formatted values.
--
---
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_1281_1255827399.1424525765535
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote"><div>*snip*<br></div><div><br></di=
v><div>We should be able to do better, not that I know what such a proposal=
would look like...</div></div></div></div></blockquote><div><br>These type=
-safe string formatting APIs are so easy to write its almost funny.<br><br>=
The only reason printf, ostream, et. al. are a PITA to implement is due to =
their type-awareness: printf is a "god method" and "<<" with ostream =
needs to be overridden for each and every printable type, creating a kludge=
y dependency on IO.<br><br>We could require all arguments to static_assert =
to be strings, and just=20
provide a way, at compile time, to create formatted strings out of=20
constants.<br><br>Even better, why not just one new utility that just forma=
ts strings, and just use that inside of static_assert:<br><br><div class=3D=
"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: =
rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: brea=
k-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><div cla=
ss=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-co=
lor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap:=
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">class coconuts{};<br=
><br>coconuts bunch{};<br><br>static const size_t count =3D 55;<br><br></sp=
an><br><code class=3D"prettyprint"><code class=3D"prettyprint"><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// Inherits the width of the=
format string.</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>//<br>// vnameof() applies only to variables:<br>// Probably has o=
ther options, just makes a lossless base-10 string literal by default.<br>/=
/<br></span></code></code><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">str </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> static_format</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #080;" =
class=3D"styled-by-prettify">"I've got a lovely %0 of %2 %1"</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> nameof(coconuts), nameof(bunch), =
vnameof(count))</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span></div></code></div><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"></span></div></code></div><br>Hardly complete, but the idea is tha=
t format specifiers would be replaced instead by argument specifiers for th=
e sake of type agnosticism.<br><br>As opposed to stringifying through the p=
reprocessor, you get type names and formatted values.<br></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" 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_1281_1255827399.1424525765535--
------=_Part_1280_709215807.1424525765534--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 21 Feb 2015 22:05:42 +0800
Raw View
--Apple-Mail=_DD5963BD-3E98-4DDC-A71D-7E3185A87201
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9302=E2=80=9320, at 1:39 AM, Ville Voutilainen <ville.vouti=
lainen@gmail.com> wrote:
>=20
> Seems like SG7 material, a combination of reflection and compile-time str=
ings.
> Somewhat hard, somewhat niche, not useful enough imho to put all of that
> functionality into static assert. Most of the necessary pieces might
> become available
> in the future and then you could combine them generally.
The only hard part is treating it like a string, which is also totally unne=
cessary.
We already have all we need. The compiler is able to print diagnostics with=
types and values. Just give static_assert a sequence of typenames, templat=
e-names, and values, with string literals being one kind of value. It shoul=
d do its best to present them all nicely to the user.
Any syntactic ambiguity between those categories can be resolved at the imp=
lementation=E2=80=99s discretion, and it should also endeavor to soldier on=
if a failure interrupts computation of part of the diagnostic. Diagnostic =
messages are fundamentally different from exact metaprocessing results, bec=
ause they only exist to convey information about some failure, so it=E2=80=
=99s not appropriate to apply strict constraints while generating them.
If we do get =E2=80=9Ccompile-time printf=E2=80=9D in the future, formatted=
constexpr or variadic template strings are also just another kind of data =
to throw into the pretty-printer.
--=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/.
--Apple-Mail=_DD5963BD-3E98-4DDC-A71D-7E3185A87201
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9320, at 1:39 AM, Ville Voutilainen <<a href=3D"mailto:ville.vout=
ilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>> wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D"">Seems like SG7 m=
aterial, a combination of reflection and compile-time strings.<br class=3D"=
">Somewhat hard, somewhat niche, not useful enough imho to put all of that<=
br class=3D"">functionality into static assert. Most of the necessary piece=
s might<br class=3D"">become available<br class=3D"">in the future and then=
you could combine them generally.<br class=3D""></div></blockquote><div><b=
r class=3D""></div><div>The only hard part is treating it like a string, wh=
ich is also totally unnecessary.</div></div><br class=3D""><div class=3D"">=
We already have all we need. The compiler is able to print diagnostics with=
types and values. Just give <font face=3D"Courier" class=3D"">static_asser=
t</font> a sequence of typenames, template-names, and values, with string l=
iterals being one kind of value. It should do its best to present them all =
nicely to the user.</div><div class=3D""><br class=3D""></div><div class=3D=
"">Any syntactic ambiguity between those categories can be resolved at the =
implementation=E2=80=99s discretion, and it should also endeavor to soldier=
on if a failure interrupts computation of part of the diagnostic. Diagnost=
ic messages are fundamentally different from exact metaprocessing results, =
because they only exist to convey information about some failure, so it=E2=
=80=99s not appropriate to apply strict constraints while generating them.<=
/div><div class=3D""><br class=3D""></div><div class=3D"">If we do get =E2=
=80=9Ccompile-time printf=E2=80=9D in the future, formatted constexpr or va=
riadic template strings are also just another kind of data to throw into th=
e pretty-printer.</div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
--Apple-Mail=_DD5963BD-3E98-4DDC-A71D-7E3185A87201--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 21 Feb 2015 16:42:40 +0200
Raw View
On 21 February 2015 at 16:05, David Krauss <potswa@gmail.com> wrote:
>
> On 2015=E2=80=9302=E2=80=9320, at 1:39 AM, Ville Voutilainen <ville.vouti=
lainen@gmail.com>
> wrote:
>
> Seems like SG7 material, a combination of reflection and compile-time
> strings.
> Somewhat hard, somewhat niche, not useful enough imho to put all of that
> functionality into static assert. Most of the necessary pieces might
> become available
> in the future and then you could combine them generally.
>
>
> The only hard part is treating it like a string, which is also totally
> unnecessary.
I see it as a much superior way forward than just enhancing static_assert.
> We already have all we need.
Oh, ok, end of discussion, then.
--=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/.
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 21 Feb 2015 23:41:26 +0800
Raw View
> On 2015=E2=80=9302=E2=80=9321, at 10:42 PM, Ville Voutilainen <ville.vout=
ilainen@gmail.com> wrote:
>=20
> I see it as a much superior way forward than just enhancing static_assert=
..
String processing is nice to have in general, but relying on it in this cas=
e will sacrifice usability.
>> We already have all we need.
>=20
> Oh, ok, end of discussion, then.
We currently have all that=E2=80=99s needed for the 99% of users who won=E2=
=80=99t be meticulously formatting strings, which is simply to specify a pr=
etty-printer.
If you read to the end of my message, you=E2=80=99ll see that this still do=
esn=E2=80=99t prejudice us against the other 1%. But, it=E2=80=99s up to yo=
u what you want to read, and what you want to skip with such prejudice of y=
our own.
--=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/.
.
Author: sasho648 <sasho648@mail.bg>
Date: Sat, 21 Feb 2015 08:47:01 -0800 (PST)
Raw View
------=_Part_149_875342759.1424537221285
Content-Type: multipart/alternative;
boundary="----=_Part_150_1622768563.1424537221285"
------=_Part_150_1622768563.1424537221285
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I'm really happy that recently people have found some really nice examples=
=20
of when meta-programming is needed. I think that 'constexpr' idea should be=
=20
extended and thus enabling meta-code not only in templates but also in=20
normal functions and possibly even in classes. I have written this in a=20
suggestion here=20
<https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/B5R4IsL=
gRgs>
..
In order your idea to be made the right way - I first suggest removing=20
'static_assert' as a C++ keyword and re-implementing it as a standard C++=
=20
'constexpr' function which takes a 'constexpr' parameter of type boolean=20
and another optional one of type pointer to constant char (supposing that=
=20
'constexpr' parameters are included and you've read my proposal) :
constexpr void static_assert(constexpr bool bool_constexpr, constexpr const=
=20
char *constexpr pmessage =3D nullptr) ;
This is a little more advanced example of my suggestion as it pretends that=
=20
'constexpr' variables can be actually edited. I think this is a good idea=
=20
but for simplicity you could just thought it like:
constexpr void static_assert(constexpr bool bool_constexpr, constexpr char =
*
constexpr pmessage =3D nullptr) ;
Another different part is that there is a 'constexpr' pointer. I suggest=20
that there will be such thing which will point to some place which can be=
=20
told by the compiler without running the program. I could give some=20
examples like:
int var;
int *constexpr ptr_var =3D &var; //here 'ptr_var' is an address which can b=
e=20
represented by the compiler as '&var'
int *ptr_var_n =3D new int; //here 'ptr_var_n' address can't be represented=
=20
by the compiler as it's determined during run-time by an external=20
non-constexpr function call
And also a pointer pointing to 'constexpr' data is something new but it is=
=20
not so different to explain - it'll be just a pointer addressing internal=
=20
compiler memory. Such pointer can be only constexpr by itself because=20
run-time environment have no access to compiler-internal memory.
So a possible implementation of your idea could be as simple as a different=
=20
version of 'static_assert':
constexpr void static_assert(constexpr bool bool_constexpr, constexpr const=
=20
char *constexpr pstrformat, ...) ;
If we use variable parameters.
I think the best solution yet for all meta-programming problems are my=20
'constexpr' changes which could apply for another problem which is includin=
g=20
files as a constexpr variables=20
<https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/b6ncBoj=
U8wI>
..
=D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=80=D1=82=D1=8A=D0=BA, 19 =D1=84=D0=B5=D0=
=B2=D1=80=D1=83=D0=B0=D1=80=D0=B8 2015 =D0=B3., 19:33:33 UTC+2, Chris Gary =
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0:
>
> This has been posted somewhere before, asked about before in other places=
,=20
> thought about and not attempted (AFAIK)... Can't find it here though....
>
> Some code:
>
> template<typename CantBeWeirdType>
> class complicated
> {
> static_assert(
> ! is_weird<CantBeWeirdType>::value,
>
> "Can't create a complicated<%[0]>, %[0] is weird!\n"
> "Also %0 is %1 bytes in size, which is probably bad!\n"
> "The alignment of %[0] is 0x%xp[2], which is not supported!",
>
> // Argument 0: Plain string literal (unqualified name)
> nameof(CantBeWeirdType),
> =20
> // Argument 1: Lossless string literal in base-10 by default
> sizeof(CantBeWeirdType)
> =20
> // Argument 2: Lossless string literal in base-16 (%x)
> // E.G: ABCD (no 0x)
> alignof(CantBeWeirdType)
> );
>
> template<typename ArgumentType>
> void f(ArgumentType &&x)
> { =20
> static_assert(
> ! is_weird<decay<ArgumentType>>::value,
> "Argument %[0] is of a weird type!\n",
> =20
> // Unqualified name, (reduces to "x", but using symbols helps=
=20
> refactoring tools...)
> nameof(x)
> );
> }
> };
>
>
> When complicated<> is given a weird_thing:
>
> Error <line><file>: Can't create a complicated<weird_thing>, weird_thing=
=20
> is weird!
> Also, weird_thing is 42 bytes in size, which is=20
> probably bad!
> The alignment of weird_thing is 0x0000DC81, which is=
=20
> not acceptable!
>
> Proposal:
>
> //nameof, qnameof, and dnameof
> =20
> namespace space_of_names{
> struct type{};
> }
> =20
> // Expands to string literal "type"
> auto name_str =3D nameof(space_of_names::type);
> =20
> // Expands to string literal "space_of_names::type"
> auto qname_str =3D qnameof(space_of_names::type);
> =20
> // Expands to string literal ".?QUtype@space_of_names@@" (through=20
> MSVC)
> auto dname_str =3D dnameof(space_of_names::type);
> =20
> // And similarly for variable names.
>
>
> static_assert format specifiers:
>
> %<style-opt><width-opt><[base-10 arg index]>
> =20
> <style> is one of:
> =20
> '' <- Decimal (nil)
> 'x' <- Hexadecimal
> 'o' <- Octal
> 'b' <- Binary
>
> <width> can be a base-10 number of spaces to pad up to
> or 'p' for 'width of pointer'. Integers are 0-padded,
> strings are space-padded.
>
> If an index is out of range, the output prints "ERANGE" in place of the=
=20
> argument.
>
> Incomplete? Done already? Useful? Not useful? Too hard? Too easy? Niche?=
=20
> Sufficiently eclipsed by concepts?
>
> I've lost track of how many times a simple type or variable name could=20
> clarify a static_assert error...
>
--=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/.
------=_Part_150_1622768563.1424537221285
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm really happy that recently people have found some real=
ly nice examples of when meta-programming is needed. I think that 'constexp=
r' idea should be extended and thus enabling meta-code not only in template=
s but also in normal functions and possibly even in classes. I have written=
this in a suggestion <a href=3D"https://groups.google.com/a/isocpp.org/for=
um/#!topic/std-proposals/B5R4IsLgRgs">here</a>.<div><br></div><div>In order=
your idea to be made the right way - I first suggest removing 'static_asse=
rt' as a C++ keyword and re-implementing it as a standard C++ 'constexpr' f=
unction which takes a 'constexpr' parameter of type boolean and another opt=
ional one of type pointer to constant char (supposing that 'constexpr' para=
meters are included and you've read my proposal) :</div><div><br><div class=
=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: =
break-word; background-color: rgb(250, 250, 250);"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">static_a=
ssert</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> bool_constexpr</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </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"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> pmessage </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">nullptr</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span></div></code></div><br>This is a little mor=
e advanced example of my suggestion as it pretends that 'constexpr' variabl=
es can be actually edited. I think this is a good idea but for simplicity y=
ou could just thought it like:</div><div><br></div><div><div class=3D"prett=
yprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">vo=
id</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">static_assert</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> bool_constexpr</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">char</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> pmessage =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">nullptr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span></div></code></div><span class=3D"styl=
ed-by-prettify" style=3D"font-family: monospace; color: rgb(102, 102, 0); b=
ackground-color: rgb(250, 250, 250);"><br></span>Another different part is =
that there is a 'constexpr' pointer. I suggest that there will be such thin=
g which will point to some place which can be told by the compiler without =
running the program. I could give some examples like:<br><br></div><div cla=
ss=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap=
: break-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyp=
rint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">var</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> ptr_var </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">var</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">//here 'ptr_v=
ar' is an address which can be represented by the compiler as '&var'</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">ptr_var_n </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">new</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #800;" class=3D"styled-by-prettify">//here 'ptr_var_n' add=
ress can't be represented by the compiler as it's determined during run-tim=
e by an external non-constexpr function call</span></div></code></div><div>=
<br></div><div>And also a pointer pointing to 'constexpr' data is something=
new but it is not so different to explain - it'll be just a pointer addres=
sing internal compiler memory. Such pointer can be only constexpr by itself=
because run-time environment have no access to compiler-internal memory.</=
div><div><br></div><div>So a possible implementation of your idea could be =
as simple as a different version of 'static_assert':<br><br><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"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">static_assert=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> bool_constexpr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">char</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> pstrformat</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">...)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></div></code></div></div><div><br></div><div>If w=
e use variable parameters.</div><div><br></div><div>I think the best soluti=
on yet for all meta-programming problems are my 'constexpr' changes which c=
ould apply for another problem which is <a href=3D"https://groups.google.co=
m/a/isocpp.org/forum/#!topic/std-proposals/b6ncBojU8wI">including files as =
a constexpr variables</a>.</div><div><br>=D1=87=D0=B5=D1=82=D0=B2=D1=8A=D1=
=80=D1=82=D1=8A=D0=BA, 19 =D1=84=D0=B5=D0=B2=D1=80=D1=83=D0=B0=D1=80=D0=B8 =
2015 =D0=B3., 19:33:33 UTC+2, Chris Gary =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=
=B0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">This has =
been posted somewhere before, asked about before in other places, thought a=
bout and not attempted (AFAIK)... Can't find it here though....<br><br>Some=
code:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:=
rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word">=
<code><div><span style=3D"color:#008">template</span><span style=3D"color:#=
660"><</span><span style=3D"color:#008">typename</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#606">CantBeWeirdType</span><span st=
yle=3D"color:#660">></span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#008">class</span><span style=3D"color:#000"> complicated<br>=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&n=
bsp; </span><span style=3D"color:#008">static_assert</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000"><br> &nbs=
p; </span><span style=3D"color:#660">!</span><span style=3D"color:#0=
00"> is_weird</span><span style=3D"color:#660"><</span><span style=3D"co=
lor:#606">CantBeWeirdType</span><span style=3D"color:#660">>::</span><sp=
an style=3D"color:#000">val<wbr>ue</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"><br><br> </span><spa=
n style=3D"color:#080">"Can't create a complicated<%[0]>, %[0] is wei=
rd!\n"</span><span style=3D"color:#000"><br> </s=
pan><span style=3D"color:#080">"Also %0 is %1 bytes in size, which is proba=
bly bad!\n"</span><span style=3D"color:#000"><br>  =
; </span><span style=3D"color:#080">"The alignment of %[0] is 0x%xp[2], whi=
ch is not supported!"</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"><br><br> </span><span style=3D"c=
olor:#800">// Argument 0: Plain string literal (unqualified name)</span><sp=
an style=3D"color:#000"><br> nameof</span><span =
style=3D"color:#660">(</span><span style=3D"color:#606">CantBeWeirdType</sp=
an><span style=3D"color:#660">),</span><span style=3D"color:#000"><br> =
; <br> </span><span style=
=3D"color:#800">// Argument 1: Lossless string literal in base-10 by defaul=
t</span><span style=3D"color:#000"><br> </span><=
span style=3D"color:#008">sizeof</span><span style=3D"color:#660">(</span><=
span style=3D"color:#606">CantBeWeirdType</span><span style=3D"color:#660">=
)</span><span style=3D"color:#000"><br> <br>&nbs=
p; </span><span style=3D"color:#800">// Argument 2: Lo=
ssless string literal in base-16 (%x)</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#800">// E.G: ABCD =
(no 0x)</span><span style=3D"color:#000"><br> </=
span><span style=3D"color:#008">alignof</span><span style=3D"color:#660">(<=
/span><span style=3D"color:#606">CantBeWeirdType</span><span style=3D"color=
:#660">)</span><span style=3D"color:#000"><br> <=
/span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br><b=
r> </span><span style=3D"color:#008">template</span><span styl=
e=3D"color:#660"><</span><span style=3D"color:#008">typename</span><span=
style=3D"color:#000"> </span><span style=3D"color:#606">ArgumentType</span=
><span style=3D"color:#660">></span><span style=3D"color:#000"><br> =
; </span><span style=3D"color:#008">void</span><span style=3D"color:=
#000"> f</span><span style=3D"color:#660">(</span><span style=3D"color:#606=
">ArgumentType</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">&&</span><span style=3D"color:#000">x</span><span style=3D"=
color:#660">)</span><span style=3D"color:#000"><br> </span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"> &=
nbsp; <br> </span><span style=3D"color:#00=
8">static_assert</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000"><br> </span><span style=
=3D"color:#660">!</span><span style=3D"color:#000"> is_weird</span><span st=
yle=3D"color:#660"><</span><span style=3D"color:#000">decay</span><span =
style=3D"color:#660"><</span><span style=3D"color:#606">ArgumentType</sp=
an><span style=3D"color:#660">>>:<wbr>:</span><span style=3D"color:#0=
00">value</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"><br> </span><span style=3D"colo=
r:#080">"Argument %[0] is of a weird type!\n"</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"><br> &nbs=
p; <br> </span><span style=
=3D"color:#800">// Unqualified name, (reduces to "x", but using symbols hel=
ps refactoring tools...)</span><span style=3D"color:#000"><br> =
nameof</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">x</span><span style=3D"color:#660">)</span><sp=
an style=3D"color:#000"><br> </spa=
n><span style=3D"color:#660">);</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#660">}</span><span style=3D"color:#000=
"><br></span><span style=3D"color:#660">};</span><span style=3D"color:#000"=
><br></span></div></code></div><br><br>When complicated<> is given a =
weird_thing:<br><br><div style=3D"background-color:rgb(250,250,250);border-=
color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-=
word"><code><div><span style=3D"color:#606">Error</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#080"><line><file></span><=
span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">Can</span><span style=3D"color:#080">'t create a compl=
icated<weird_thing>, weird_thing is weird!<br> &n=
bsp; Also, weird_thing is 42 byte=
s in size, which is probably bad!<br> &nb=
sp; The alignment of weird_thing is 0x0000DC81,=
which is not acceptable!<br></span></div></code></div><br>Proposal:<br><br=
><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,1=
87);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><s=
pan style=3D"color:#000"> </span><span style=3D"color:#800">//=
nameof, qnameof, and dnameof</span><span style=3D"color:#000"><br> &n=
bsp; <br> </span><span style=3D"color:#008">namespace</span><s=
pan style=3D"color:#000"> space_of_names</span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br> </span><s=
pan style=3D"color:#008">struct</span><span style=3D"color:#000"> type</spa=
n><span style=3D"color:#660">{};</span><span style=3D"color:#000"><br> =
; </span><span style=3D"color:#660">}</span><span style=3D"color:#00=
0"><br> <br> </span><span style=3D"color:#800">//=
Expands to string literal "type"</span><span style=3D"color:#000"><br>&nbs=
p; </span><span style=3D"color:#008">auto</span><span style=3D"color=
:#000"> name_str </span><span style=3D"color:#660">=3D</span><span style=3D=
"color:#000"> nameof</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">space_of_names</span><span style=3D"color:#660">::</span><s=
pan style=3D"color:#000">type</span><span style=3D"color:#660">);</span><sp=
an style=3D"color:#000"><br> <br> </span><span st=
yle=3D"color:#800">// Expands to string literal "space_of_names::type"</spa=
n><span style=3D"color:#000"><br> </span><span style=3D"color:=
#008">auto</span><span style=3D"color:#000"> qname_str </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> qnameof</span><span s=
tyle=3D"color:#660">(</span><span style=3D"color:#000">space_of_names</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">type</span>=
<span style=3D"color:#660">);</span><span style=3D"color:#000"><br> &=
nbsp; <br> </span><span style=3D"color:#800">// Expands to str=
ing literal ".?QUtype@space_of_names@@" (through MSVC)</span><span style=3D=
"color:#000"><br> </span><span style=3D"color:#008">auto</span=
><span style=3D"color:#000"> dname_str </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> dnameof</span><span style=3D"color:#6=
60">(</span><span style=3D"color:#000">space_of_names</span><span style=3D"=
color:#660">::</span><span style=3D"color:#000">type</span><span style=3D"c=
olor:#660">);</span><span style=3D"color:#000"><br> <br> =
</span><span style=3D"color:#800">// And similarly for variable nam=
es.</span><span style=3D"color:#000"><br></span></div></code></div><br><br>=
static_assert format specifiers:<br><br><div style=3D"background-color:rgb(=
250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:=
1px;word-wrap:break-word"><code><div><span style=3D"color:#000"> &nbs=
p; </span><span style=3D"color:#660">%<</span><span style=3D"color:#000"=
>style</span><span style=3D"color:#660">-</span><span style=3D"color:#000">=
opt</span><span style=3D"color:#660">><</span><span style=3D"color:#0=
00">width</span><span style=3D"color:#660">-</span><span style=3D"color:#00=
0">opt</span><span style=3D"color:#660">><[</span><span style=3D"colo=
r:#008">base</span><span style=3D"color:#660">-</span><span style=3D"color:=
#066"><wbr>10</span><span style=3D"color:#000"> arg index</span><span style=
=3D"color:#660">]></span><span style=3D"color:#000"><br> <br=
> </span><span style=3D"color:#080"><style></span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">is</span><span styl=
e=3D"color:#000"> one of</span><span style=3D"color:#660">:</span><span sty=
le=3D"color:#000"><br> <br> </span><span style=3D"=
color:#080">''</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660"><-</span><span style=3D"color:#000"> </span><span style=3D"color=
:#606">Decimal</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#008">nil</span><span style=3D"color:#=
660">)</span><span style=3D"color:#000"><br> </span><span styl=
e=3D"color:#080">'x'</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660"><-</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">Hexadecimal</span><span style=3D"color:#000"><br> &nb=
sp; </span><span style=3D"color:#080">'o'</span><span style=3D"color:#000">=
</span><span style=3D"color:#660"><-</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Octal</span><span style=3D"color:#000"><b=
r> </span><span style=3D"color:#080">'b'</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660"><-</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#606">Binary</span><span style=3D"c=
olor:#000"><br><br> </span><span style=3D"color:#080"><widt=
h></span><span style=3D"color:#000"> can be a </span><span style=3D"colo=
r:#008">base</span><span style=3D"color:#660">-</span><span style=3D"color:=
#066">10</span><span style=3D"color:#000"> number of spaces to pad up to<br=
> </span><span style=3D"color:#008">or</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#080">'p'</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">for</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#080">'width of pointer'</span><span style=
=3D"color:#660">.</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">Integers</span><span style=3D"color:#000"> are </span><span styl=
e=3D"color:#066">0</span><span style=3D"color:#660">-</span><span style=3D"=
color:#000">padded</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"><br> strings are space</span><span style=3D"color:=
#660">-</span><span style=3D"color:#000">padded</span><span style=3D"color:=
#660">.</span><span style=3D"color:#000"><br></span></div></code></div><br>=
If an index is out of range, the output prints "ERANGE" in place of the arg=
ument.<br><br>Incomplete? Done already? Useful? Not useful? Too hard? Too e=
asy? Niche? Sufficiently eclipsed by concepts?<br><br>I've lost track of ho=
w many times a simple type or variable name could clarify a static_assert e=
rror...<br></div></blockquote></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" 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_150_1622768563.1424537221285--
------=_Part_149_875342759.1424537221285--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 21 Feb 2015 19:05:53 +0200
Raw View
On 21 February 2015 at 17:41, David Krauss <potswa@gmail.com> wrote:
> We currently have all that=E2=80=99s needed for the 99% of users who won=
=E2=80=99t be meticulously formatting strings, which is simply to specify a=
pretty-printer.
Then by all means let's specify a compile-time printer. Specifying a
static_assert-specific pretty
printer doesn't make much sense. While we are specifying such a
compile-time printer,
we will probably want compile-time string-processing in general, since
it's useful for far
more than just printing diagnostics.
--=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/.
.
Author: David Krauss <potswa@gmail.com>
Date: Sun, 22 Feb 2015 01:59:28 +0800
Raw View
--Apple-Mail=_A9F8E2A0-E105-452C-B5A9-03AE0F33385E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9302=E2=80=9322, at 1:05 AM, Ville Voutilainen <ville.vouti=
lainen@gmail.com> wrote:
>=20
> On 21 February 2015 at 17:41, David Krauss <potswa@gmail.com> wrote:
>> We currently have all that=E2=80=99s needed for the 99% of users who won=
=E2=80=99t be meticulously formatting strings, which is simply to specify a=
pretty-printer.
>=20
> Then by all means let's specify a compile-time printer. Specifying a
> static_assert-specific pretty
> printer doesn't make much sense.
Perhaps I wasn=E2=80=99t clear. I=E2=80=99m not suggesting to specify the b=
ehavior of a pretty printer which is specific to static_assert. I=E2=80=99m=
suggesting to specify an interface to the fault-tolerant pretty-printers t=
hat all implementations already have for ordinary diagnostics.
Grammar:
static_assert-declaration:
static_assert( constant-expression message-seq_opt )
message-seq:
message-seq_opt , message
message:
expression
type-id
template-name
Standardese-ish (sorry, it=E2=80=99s getting late here):
If the constant-expression evaluates to false, the program is ill-formed, a=
nd the implementation shall communicate the identity or value of each messa=
ge, if any. Messages which are string literals, or otherwise evaluate to st=
rings, should be relayed as plain text. If the value or identity of a messa=
ge cannot be determined, the implementation should convey whatever informat=
ion may be useful, and then proceed to communicate the remaining messages.
Currently, static_assert diagnostic messages are required to =E2=80=9Cinclu=
de the text of the string-literal, if one is supplied, except that characte=
rs not in the basic source character set (2.3) are not required to appear i=
n the diagnostic message.=E2=80=9D This is litigious, yet still underspecif=
ied: GCC and Clang vary on whether escape sequences are supposed to be tran=
slated or relayed.
Vague specification and implementation freedom are the way to best serve th=
e user. I want a development environment with interactive, point-and-click =
diagnostic messages. That=E2=80=99s possible if they=E2=80=99re generated n=
atively, not through reflection. (But, as I said, this doesn=E2=80=99t prec=
lude reflection-based strings if they=E2=80=99re available.)
> While we are specifying such a
> compile-time printer,
> we will probably want compile-time string-processing in general, since
> it's useful for far
> more than just printing diagnostics.
Since diagnostic messages are likely to try to expose errors, it=E2=80=99s =
likely that the thing being formatted isn=E2=80=99t completely OK, which wi=
ll cause string processing to fail and no message comes out.
Fault tolerance is impossible to add through reflection.
--=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/.
--Apple-Mail=_A9F8E2A0-E105-452C-B5A9-03AE0F33385E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9302=
=E2=80=9322, at 1:05 AM, Ville Voutilainen <<a href=3D"mailto:ville.vout=
ilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>> wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D"">On 21 February 2=
015 at 17:41, David Krauss <<a href=3D"mailto:potswa@gmail.com" class=3D=
"">potswa@gmail.com</a>> wrote:<br class=3D""><blockquote type=3D"cite" =
class=3D"">We currently have all that=E2=80=99s needed for the 99% of users=
who won=E2=80=99t be meticulously formatting strings, which is simply to s=
pecify a pretty-printer.<br class=3D""></blockquote><br class=3D"">Then by =
all means let's specify a compile-time printer. Specifying a<br class=3D"">=
static_assert-specific pretty<br class=3D"">printer doesn't make much sense=
.. </div></blockquote><div><br class=3D""></div><div>Perhaps I wasn=E2=80=99=
t clear. I=E2=80=99m not suggesting to specify the behavior of a pretty pri=
nter which is specific to <font face=3D"Courier" class=3D"">static_assert</=
font>. I=E2=80=99m suggesting to specify an interface to the fault-tolerant=
pretty-printers that all implementations already have for ordinary diagnos=
tics.</div><div><br class=3D""></div><div>Grammar:</div><div><br class=3D""=
></div><div>static_assert-declaration:</div><div> <font face=
=3D"Courier" class=3D"">static_assert(</font> <i class=3D"">constant-expres=
sion</i> <i class=3D"">message-seq_opt</i> <font face=3D"Courier=
" class=3D"">)</font></div><div>message-seq:</div><div> <i cla=
ss=3D"">message-seq_opt</i> <font face=3D"Courier" class=3D"">,</font> <i c=
lass=3D"">message</i></div><div>message:</div><div> <i class=
=3D"">expression</i></div><div> <i class=3D"">type-id</i></div=
><div> <i class=3D"">template-name</i></div><div><br class=3D"=
"></div><div>Standardese-ish (sorry, it=E2=80=99s getting late here):</div>=
<div><br class=3D""></div><div>If the <i class=3D"">constant-expression</i>=
evaluates to false, the program is ill-formed, and the implementation shal=
l communicate the identity or value of each <i class=3D"">message</i>, if a=
ny. Messages which are string literals, or otherwise evaluate to strings, s=
hould be relayed as plain text. If the value or identity of a message canno=
t be determined, the implementation should convey whatever information may =
be useful, and then proceed to communicate the remaining messages.</div><di=
v><br class=3D""></div><div>Currently, <font face=3D"Courier" class=3D=
"">static_assert</font> diagnostic messages are required to =E2=80=9Cinclud=
e the text of the string-literal, if one is supplied, except that char=
acters not in the basic source character set (2.3) are not required to=
appear in the diagnostic message.=E2=80=9D This is litigious, yet sti=
ll underspecified: GCC and Clang vary on whether escape sequences are suppo=
sed to be translated or relayed.</div><div><br class=3D""></div><div>Vague =
specification and implementation freedom are the way to best serve the user=
.. I want a development environment with interactive, point-and-click diagno=
stic messages. That=E2=80=99s possible if they=E2=80=99re generated nativel=
y, not through reflection. (But, as I said, this doesn=E2=80=99t preclude r=
eflection-based strings if they=E2=80=99re available.)</div><br class=3D"">=
<blockquote type=3D"cite" class=3D""><div class=3D"">While we are specifyin=
g such a<br class=3D"">compile-time printer,<br class=3D"">we will probably=
want compile-time string-processing in general, since<br class=3D"">it's u=
seful for far<br class=3D"">more than just printing diagnostics.<br class=
=3D""></div></blockquote></div><br class=3D""><div class=3D"">Since diagnos=
tic messages are likely to try to expose errors, it=E2=80=99s likely that t=
he thing being formatted isn=E2=80=99t completely OK, which will cause stri=
ng processing to fail and no message comes out.</div><div class=3D""><br cl=
ass=3D""></div><div class=3D"">Fault tolerance is impossible to add through=
reflection.</div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
--Apple-Mail=_A9F8E2A0-E105-452C-B5A9-03AE0F33385E--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sat, 21 Feb 2015 10:46:52 -0800
Raw View
On Saturday 21 February 2015 19:05:53 Ville Voutilainen wrote:
> we will probably want compile-time string-processing in general, since
> it's useful for far
> more than just printing diagnostics.
That ties to the #load discussion going on.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: sasho648 <sasho648@mail.bg>
Date: Sat, 21 Feb 2015 11:04:21 -0800 (PST)
Raw View
------=_Part_1811_1052443656.1424545461591
Content-Type: multipart/alternative;
boundary="----=_Part_1812_1745209700.1424545461591"
------=_Part_1812_1745209700.1424545461591
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This and I think it will be better to implement it using currently defined=
=20
primitives instead of adding new keywords and libraries. Thus I'm=20
suggesting a 'constexpr' version of the current standard library which to=
=20
operate on compiler-time data.=20
=D1=81=D1=8A=D0=B1=D0=BE=D1=82=D0=B0, 21 =D1=84=D0=B5=D0=B2=D1=80=D1=83=D0=
=B0=D1=80=D0=B8 2015 =D0=B3., 19:05:55 UTC+2, Ville Voutilainen =D0=BD=D0=
=B0=D0=BF=D0=B8=D1=81=D0=B0:
>
> On 21 February 2015 at 17:41, David Krauss <pot...@gmail.com <javascript:=
>>=20
> wrote:=20
> > We currently have all that=E2=80=99s needed for the 99% of users who wo=
n=E2=80=99t be=20
> meticulously formatting strings, which is simply to specify a=20
> pretty-printer.=20
>
> Then by all means let's specify a compile-time printer. Specifying a=20
> static_assert-specific pretty=20
> printer doesn't make much sense. While we are specifying such a=20
> compile-time printer,=20
> we will probably want compile-time string-processing in general, since=20
> it's useful for far=20
> more than just printing diagnostics.=20
>
--=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/.
------=_Part_1812_1745209700.1424545461591
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This and I think it will be better to implement it using c=
urrently defined primitives instead of adding new keywords and libraries. T=
hus I'm suggesting a 'constexpr' version of the current standard library wh=
ich to operate on compiler-time data. <br><br>=D1=81=D1=8A=D0=B1=D0=BE=
=D1=82=D0=B0, 21 =D1=84=D0=B5=D0=B2=D1=80=D1=83=D0=B0=D1=80=D0=B8 2015 =D0=
=B3., 19:05:55 UTC+2, Ville Voutilainen =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=
=B0:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">On 21 February 2015 at 17:=
41, David Krauss <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscat=
ed-mailto=3D"M2xblheL_boJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'jav=
ascript:';return true;" onclick=3D"this.href=3D'javascript:';return true;">=
pot...@gmail.com</a>> wrote:
<br>> We currently have all that=E2=80=99s needed for the 99% of users w=
ho won=E2=80=99t be meticulously formatting strings, which is simply to spe=
cify a pretty-printer.
<br>
<br>Then by all means let's specify a compile-time printer. Specifying a
<br>static_assert-specific pretty
<br>printer doesn't make much sense. While we are specifying such a
<br>compile-time printer,
<br>we will probably want compile-time string-processing in general, since
<br>it's useful for far
<br>more than just printing diagnostics.
<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" 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_1812_1745209700.1424545461591--
------=_Part_1811_1052443656.1424545461591--
.