Topic: Extension of templates, syntactic macros


Author: Yuriy Smirnov <neoprogramming@gmail.com>
Date: Tue, 13 Jan 2015 13:26:35 -0800 (PST)
Raw View
------=_Part_5250_967025104.1421184395352
Content-Type: multipart/alternative;
 boundary="----=_Part_5251_634682432.1421184395352"

------=_Part_5251_634682432.1421184395352
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Currently, C++ template is a function or class/struct/union (starting with=
=20
C++14 is also constant, https://isocpp.org/files/papers/N3651.pdf), and=20
template parameters can be types or integer constants. I propose to extend=
=20
the set of language constructs that can be templates and template=20
parameters.

Template is a compile-time construct. We can say that the passing of a=20
parameter (type or integer constant) to template, you actually do not pass=
=20
the type and not a constant, but a fragment of the syntax tree (AST).=20
Similarly, the code of template is aslo AST fragment with "placeholders",=
=20
which are are replaced by actual template arguments.

Therefore, I propose to expand the possibilities of templates, bringing=20
them to the possibilities of syntactic macros. To this end, I propose to=20
introduce a few extra features.

1. allow to pass as template arguments any valid AST nodes, not only the=20
types and integer constants. In particular, the template parameter can be:

   - constant strings;=20
   - floating-point numbers;=20
   - syntactically correct C++ identifiers
   - syntactically correct expressions
   - syntactically correct blocks of code
  =20

2. introduce template parameterization not only for the of classes and=20
functions, but also for some other language constructs.

   - typedefs
   - enums
   - named blocks of code (*see below)
  =20
Consider the proposal in more detail.

*The first extension -  allow to pass any correct AST as template=20
arguments. *
Passing of string and floating-point literals is obvious and arranged as=20
well as the passing of integer literals. String, character and=20
floating-point literals are no worse than integer literals; and there is no=
=20
reason to prohibit to pass them into the templates.

template<double d, const char*s>=20
void foo() { }

foo<3.14159, "Hello World"> ();


A more interesting case is the passing of names, expressions and code=20
blocks. In fact, this is more general case. We must introduce keyword or=20
keywords (similar "typename") for describing arbitrary AST fragment in=20
template parameter list. For common case, we can use an existing word=20
"inline":

template<inline Expr>
void Foo()
{
   while(need_execute_loop())
     Expr;
}

int i, x, y;
Foo<{ if(i>0) x++; else bar(y); } >();

It is advisable to come up with separate keywords for identifers,=20
expressions and code blocks (or come up with a mechanism that limits the=20
allowable kinds of parameters, similar concepts).=20

*The second extension - templates can be not only classes and functions.*

It is obvious that we can implement the enum templates and typedef=20
templates.=20

template<int N>
enum E {
  E1 =3D N,
  E2
};

template<typename T>=20
typedef const MyClass<T>&   My=D0=A1Ref;

Furthermore, I suggest interesting extension - Template code blocks. But=20
first, we should consider the concept of "inline code blocks". This is a=20
separate proposal.

*Inline code blocks*
The code block is named declarative construct including an arbitrary code.=
=20
It is like lexical macro from C/C++ preprocessor, but deeply integrated=20
into the language; as we remember, the preprocessor is not related to the=
=20
language: it ignores the scope rules and namespaces, and even keywords of=
=20
C++ - we can write "#define true false" and it compiles! In fact,=20
preprocessor is dangerous thing.=20

Instead, I propose to introduce a declarative code blocks with the=20
possibility of substitution in any place of the program. We can use an=20
existing keyword "inline" or use another keyword.

// declare block, like struct or class;=20
inline MyBlock
{
  foo();
  bar();
  baz();
}

// some code
MyBlock; // substitution of AST 'MyBlock' into main AST

These blocks differ from the functions that they not called. They=20
substituted as inline-functions directly into code. It is assumed that such=
=20
units must be used instead of Macros. Unlike inline functions, it is simply=
=20
AST fragments. I am faced with the necessity of such constructions in=20
embedded programming. Braces allow to do without the dreaded "\" in=20
multiline macros.

*Template code blocks*
Of course, these blocks can be templates.=20

template<int N>
inline MyBlock
{
  foo();
  for(int i=3D0; i<n; i++)
    bar();
  baz();
}

// some code
MyBlock<10>; // substitution of AST 'MyBlock' into main AST

These examples are simple, but I have no doubt that there is plenty of=20
real-world applications of these features. Boost library allows you to do=
=20
amazing things, but its code is very complex and non-obvious. This feature=
=20
is quite simple, but with great potential.=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_5251_634682432.1421184395352
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span style=3D"orphans: 2; text-align: -webkit-auto; widow=
s: 2;"><font color=3D"#000000" face=3D"Tahoma" size=3D"3">Currently, C++ te=
mplate is a function or class/struct/union (starting with C++14 is also con=
stant,&nbsp;https://isocpp.org/files/papers/N3651.pdf), and template&nbsp;p=
arameters can be types or integer constants.&nbsp;I propose to extend the s=
et of language constructs that can be templates and template parameters.</f=
ont></span><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans:=
 2; text-align: -webkit-auto; widows: 2; font-size: medium;"><br></div><div=
 style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; text-align:=
 -webkit-auto; widows: 2; font-size: medium;">Template is a compile-time co=
nstruct. We can say that the passing of a parameter (type or integer consta=
nt) to template, you actually do not pass the type and not a constant, but =
a fragment of the syntax tree (AST). Similarly, the code of template is asl=
o AST fragment with "placeholders", which are&nbsp;are replaced&nbsp;by act=
ual template arguments.</div><div style=3D"color: rgb(0, 0, 0); font-family=
: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2; font-size: mediu=
m;"><br></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orpha=
ns: 2; text-align: -webkit-auto; widows: 2; font-size: medium;">Therefore, =
I propose to expand the possibilities of templates, bringing them to the po=
ssibilities of syntactic macros.&nbsp;To this end, I propose to introduce a=
 few extra features.</div><div style=3D"orphans: 2; text-align: -webkit-aut=
o; widows: 2;"><br><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; =
font-size: medium;">1. allow to pass as template arguments any valid AST no=
des, not only the types and integer constants. In particular, the template =
parameter can be:</div><div><ul><li><span style=3D"color: rgb(0, 0, 0); fon=
t-family: Tahoma; font-size: medium; text-align: -webkit-auto;">constant st=
rings;&nbsp;</span><br></li><li><span style=3D"color: rgb(0, 0, 0); font-fa=
mily: Tahoma; font-size: medium; text-align: -webkit-auto;">floating-point =
numbers;&nbsp;</span><br></li><li><span style=3D"color: rgb(0, 0, 0); font-=
family: Tahoma; font-size: medium; text-align: -webkit-auto;">syntactically=
&nbsp;correct C++ identifiers</span><br></li><li><span style=3D"color: rgb(=
0, 0, 0); font-family: Tahoma; font-size: medium; text-align: -webkit-auto;=
">syntactically correct expressions</span><br></li><li><span style=3D"color=
: rgb(0, 0, 0); font-family: Tahoma; font-size: medium; text-align: -webkit=
-auto;">syntactically correct&nbsp;blocks of code</span><br></li></ul></div=
></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; =
text-align: -webkit-auto; widows: 2; font-size: medium;"><br></div><div sty=
le=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; text-align: -we=
bkit-auto; widows: 2; font-size: medium;">2.&nbsp;introduce template&nbsp;p=
arameterization&nbsp;not only for the of classes and functions, but also fo=
r some other language constructs.</div><div style=3D"orphans: 2; text-align=
: -webkit-auto; widows: 2;"><ul><li><span style=3D"color: rgb(0, 0, 0); fon=
t-family: Tahoma; font-size: medium; text-align: -webkit-auto;">typedefs</s=
pan><br></li><li><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; f=
ont-size: medium; text-align: -webkit-auto;">enums</span><br></li><li><span=
 style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium; text=
-align: -webkit-auto;">named blocks of code (*see below)</span><br></li></u=
l></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2;=
 text-align: -webkit-auto; widows: 2; font-size: medium;"><span style=3D"te=
xt-align: -webkit-auto;">Consider the proposal in more detail.</span><br></=
div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; tex=
t-align: -webkit-auto; widows: 2; font-size: medium;"><span style=3D"text-a=
lign: -webkit-auto;"><br></span></div><div><div style=3D"color: rgb(0, 0, 0=
); font-family: Tahoma; font-size: medium;"><div style=3D"text-align: -webk=
it-auto;"><b>The first extension -&nbsp;&nbsp;allow to pass any correct AST=
&nbsp;as template arguments.&nbsp;</b></div><div style=3D"text-align: -webk=
it-auto;">Passing of string and floating-point literals is&nbsp;obvious and=
 arranged as well as the passing of integer literals.&nbsp;String, characte=
r and floating-point literals are no worse than integer literals; and there=
 is no reason to prohibit to pass them into the templates.</div></div><div>=
<br></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 18=
7, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">double</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> d</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
onst</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">char</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">s</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> <br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/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"><br><br>foo</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">3.14159</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D=
"styled-by-prettify">"Hello World"</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br></span></div></code></div><div style=3D"color: rgb(0, 0, 0); font=
-family: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2; font-size=
: medium;"><br><div><span style=3D"text-align: -webkit-auto;">A more intere=
sting case is the passing of names, expressions and code blocks.&nbsp;In fa=
ct, this is more general case. We must introduce keyword or keywords (simil=
ar "typename") for describing arbitrary AST fragment in template parameter =
list.&nbsp;For common case, we can use an existing word "inline":</span></d=
iv><div><span style=3D"text-align: -webkit-auto;"><br></span></div><div><di=
v><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"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">&lt;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Expr</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp;</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">while</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">need_execute_loop</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">())</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp; &nbsp; &nbsp;</span><span style=3D"color: #606;=
" class=3D"styled-by-prettify">Expr</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-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><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">i=
nt</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> x</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: #008;" class=3D"styled-by-prettify">else</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">y</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"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;();</span></div></code></div><div style=3D"text-align: -webkit-auto;=
"><br></div></div></div></div><div><span style=3D"color: rgb(0, 0, 0); font=
-family: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2; font-size=
: medium;">It is advisable to come up with separate keywords for identifers=
, expressions and code blocks&nbsp;(or come up with a mechanism that limits=
 the allowable kinds of parameters, similar concepts).&nbsp;</span></div></=
div><div><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: =
2; text-align: -webkit-auto; widows: 2; font-size: medium;"><br></span></di=
v><div><div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans=
: 2; text-align: -webkit-auto; widows: 2; font-size: medium;"><b>The second=
 extension - templates can be not only classes and functions.</b></div><div=
 style=3D"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; text-align:=
 -webkit-auto; widows: 2; font-size: medium;"><br></div><div style=3D"color=
: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; text-align: -webkit-auto; =
widows: 2; font-size: medium;">It is obvious that we can implement&nbsp;the=
 enum templates and typedef templates.&nbsp;</div></div></div><div style=3D=
"color: rgb(0, 0, 0); font-family: Tahoma; orphans: 2; text-align: -webkit-=
auto; widows: 2; font-size: medium;"><br></div><div style=3D"orphans: 2; te=
xt-align: -webkit-auto; widows: 2;"><div style=3D"color: rgb(0, 0, 0); font=
-family: Tahoma; font-size: medium;"><div class=3D"prettyprint" style=3D"bo=
rder: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color=
: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> N</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">enum</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> E </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>&nbsp; E1 </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"> N</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; E=
2<br></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">template</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> <br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">typedef</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: #606;" class=3D"styled-by-prett=
ify">MyClass</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&amp;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nbsp; </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">My</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=D0=A1</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Ref</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span></div></code></div><div sty=
le=3D"text-align: -webkit-auto;"><br></div></div><div style=3D"text-align: =
-webkit-auto;"><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font=
-size: medium;"><div style=3D"text-align: -webkit-auto;">Furthermore, I sug=
gest interesting extension - Template code blocks. But first, we should con=
sider the concept of "inline code blocks".&nbsp;This is a separate proposal=
..</div><div style=3D"text-align: -webkit-auto;"><br></div><div style=3D"tex=
t-align: -webkit-auto;"><b>Inline code blocks</b></div><div style=3D"text-a=
lign: -webkit-auto;">The code block is named declarative construct includin=
g an arbitrary code. It is like lexical macro from C/C++ preprocessor, but =
deeply integrated into the language; as we remember, the preprocessor is no=
t related to the language: it ignores the scope rules and namespaces, and e=
ven keywords of C++ - we can write "#define true false" and&nbsp;it compile=
s! In fact, preprocessor is dangerous thing.&nbsp;</div><div style=3D"text-=
align: -webkit-auto;"><br></div><div style=3D"text-align: -webkit-auto;">In=
stead, I propose to introduce a declarative code blocks with the possibilit=
y of substitution in any place of the program.&nbsp;We can use an existing =
keyword "inline" or use another keyword.</div></div><div style=3D"color: rg=
b(0, 0, 0); font-family: Tahoma; font-size: medium; text-align: -webkit-aut=
o;"><br></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-=
size: medium; text-align: -webkit-auto;"><div><div class=3D"prettyprint" st=
yle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgro=
und-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
 declare block, like struct or class; </span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">MyBlock</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>&nb=
sp; foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; ba=
z</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"styled-by-prettify"><br><br></span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">// some code</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">MyBlock</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"sty=
led-by-prettify">// substitution of AST 'MyBlock' into main AST</span></div=
></code></div><div style=3D"text-align: -webkit-auto;"><br></div></div></di=
v><div style=3D"text-align: -webkit-auto;"><div><div style=3D"color: rgb(0,=
 0, 0); font-family: Tahoma; font-size: medium; text-align: -webkit-auto;">=
These blocks differ from the functions that they not called. They substitut=
ed as inline-functions directly into code.&nbsp;It is assumed that such uni=
ts must be used instead of Macros. Unlike inline functions, it is simply AS=
T fragments.&nbsp;I am faced with the necessity of such constructions&nbsp;=
in embedded programming.&nbsp;Braces allow to do without the dreaded "\" in=
 multiline macros.</div><div style=3D"color: rgb(0, 0, 0); font-family: Tah=
oma; font-size: medium; text-align: -webkit-auto;"><br></div><div style=3D"=
color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium; text-align: -w=
ebkit-auto;"><b>Template code blocks</b></div><div style=3D"color: rgb(0, 0=
, 0); font-family: Tahoma; font-size: medium; text-align: -webkit-auto;">Of=
 course, these blocks can be templates.&nbsp;</div></div><div style=3D"colo=
r: rgb(0, 0, 0); font-family: Tahoma; font-size: medium; text-align: -webki=
t-auto;"><br></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; =
font-size: medium; text-align: -webkit-auto;"><div><div class=3D"prettyprin=
t" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; ba=
ckground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> N</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">inline</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">MyBlock</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; foo</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">for</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> i</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> i</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">n</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> i<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">++)</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; =
bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; baz=
</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"styled-by-prettify"><br><br></span><span style=3D"co=
lor: #800;" class=3D"styled-by-prettify">// some code</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #606;" class=3D"styled-by-prettify">MyBlock</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">10</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&gt;;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">// substitution of AST 'MyBlock' into main AST</span></div></code></d=
iv><div style=3D"text-align: -webkit-auto;"><div><br></div></div></div></di=
v></div></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-=
size: medium; text-align: -webkit-auto;"><div><span style=3D"text-align: -w=
ebkit-auto;">These examples are simple, but I have no doubt that there is p=
lenty of real-world applications of these features.&nbsp;Boost library allo=
ws you to do amazing things, but its code is very complex and non-obvious.&=
nbsp;This feature is quite simple, but with great potential.&nbsp;</span></=
div><div><span style=3D"text-align: -webkit-auto;"><br></span></div></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&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_5251_634682432.1421184395352--
------=_Part_5250_967025104.1421184395352--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Tue, 13 Jan 2015 16:53:36 -0500
Raw View
On Tue, Jan 13, 2015 at 4:26 PM, Yuriy Smirnov <neoprogramming@gmail.com> w=
rote:
> The second extension - templates can be not only classes and functions.
>
> It is obvious that we can implement the enum templates and typedef
> templates.
>
> template<int N>
> enum E {
>   E1 =3D N,
>   E2
> };
>

What about "union template"?

> template<typename T>
> typedef const MyClass<T>&   My=D0=A1Ref;
>

We already have this, alias template, with `using` keyword.

--=20
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd

--=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: gmisocpp@gmail.com
Date: Tue, 13 Jan 2015 14:17:31 -0800 (PST)
Raw View
------=_Part_48_1469858599.1421187451407
Content-Type: multipart/alternative;
 boundary="----=_Part_49_1409081952.1421187451408"

------=_Part_49_1409081952.1421187451408
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


I haven't used the boost dependency library just seen snippets of it now=20
and then. But does this proposal completely replace stuff like the boost DI=
=20
library?
My first thoughts were way smaller, like would this allow me to do=20
little things like logging with a file and line number without actually=20
having to specify the file and line number or using a macro. But now I=20
think of that, I don't see how __LINE__ could work in such templates as=20
this proposal offers to be useful for this purpose.

Anyway, I'm keen to see what other people make of this proposal and how it=
=20
relates to things like the mixins proposal I once saw which I don't know=20
what happened with it.

On Wednesday, January 14, 2015 at 10:26:35 AM UTC+13, Yuriy Smirnov wrote:

> Currently, C++ template is a function or class/struct/union (starting wit=
h=20
> C++14 is also constant, https://isocpp.org/files/papers/N3651.pdf), and=
=20
> template parameters can be types or integer constants. I propose to exten=
d=20
> the set of language constructs that can be templates and template=20
> parameters.
>
> Template is a compile-time construct. We can say that the passing of a=20
> parameter (type or integer constant) to template, you actually do not pas=
s=20
> the type and not a constant, but a fragment of the syntax tree (AST).=20
> Similarly, the code of template is aslo AST fragment with "placeholders",=
=20
> which are are replaced by actual template arguments.
>
> Therefore, I propose to expand the possibilities of templates, bringing=
=20
> them to the possibilities of syntactic macros. To this end, I propose to=
=20
> introduce a few extra features.
>
> 1. allow to pass as template arguments any valid AST nodes, not only the=
=20
> types and integer constants. In particular, the template parameter can be=
:
>
>    - constant strings;=20
>    - floating-point numbers;=20
>    - syntactically correct C++ identifiers
>    - syntactically correct expressions
>    - syntactically correct blocks of code
>   =20
>
> 2. introduce template parameterization not only for the of classes and=20
> functions, but also for some other language constructs.
>
>    - typedefs
>    - enums
>    - named blocks of code (*see below)
>   =20
> Consider the proposal in more detail.
>
> *The first extension -  allow to pass any correct AST as template=20
> arguments. *
> Passing of string and floating-point literals is obvious and arranged as=
=20
> well as the passing of integer literals. String, character and=20
> floating-point literals are no worse than integer literals; and there is =
no=20
> reason to prohibit to pass them into the templates.
>
> template<double d, const char*s>=20
> void foo() { }
>
> foo<3.14159, "Hello World"> ();
>
>
> A more interesting case is the passing of names, expressions and code=20
> blocks. In fact, this is more general case. We must introduce keyword or=
=20
> keywords (similar "typename") for describing arbitrary AST fragment in=20
> template parameter list. For common case, we can use an existing word=20
> "inline":
>
> template<inline Expr>
> void Foo()
> {
>    while(need_execute_loop())
>      Expr;
> }
>
> int i, x, y;
> Foo<{ if(i>0) x++; else bar(y); } >();
>
> It is advisable to come up with separate keywords for identifers,=20
> expressions and code blocks (or come up with a mechanism that limits the=
=20
> allowable kinds of parameters, similar concepts).=20
>
> *The second extension - templates can be not only classes and functions.*
>
> It is obvious that we can implement the enum templates and typedef=20
> templates.=20
>
> template<int N>
> enum E {
>   E1 =3D N,
>   E2
> };
>
> template<typename T>=20
> typedef const MyClass<T>&   My=D0=A1Ref;
>
> Furthermore, I suggest interesting extension - Template code blocks. But=
=20
> first, we should consider the concept of "inline code blocks". This is a=
=20
> separate proposal.
>
> *Inline code blocks*
> The code block is named declarative construct including an arbitrary code=
..=20
> It is like lexical macro from C/C++ preprocessor, but deeply integrated=
=20
> into the language; as we remember, the preprocessor is not related to the=
=20
> language: it ignores the scope rules and namespaces, and even keywords of=
=20
> C++ - we can write "#define true false" and it compiles! In fact,=20
> preprocessor is dangerous thing.=20
>
> Instead, I propose to introduce a declarative code blocks with the=20
> possibility of substitution in any place of the program. We can use an=20
> existing keyword "inline" or use another keyword.
>
> // declare block, like struct or class;=20
> inline MyBlock
> {
>   foo();
>   bar();
>   baz();
> }
>
> // some code
> MyBlock; // substitution of AST 'MyBlock' into main AST
>
> These blocks differ from the functions that they not called. They=20
> substituted as inline-functions directly into code. It is assumed that su=
ch=20
> units must be used instead of Macros. Unlike inline functions, it is simp=
ly=20
> AST fragments. I am faced with the necessity of such constructions in=20
> embedded programming. Braces allow to do without the dreaded "\" in=20
> multiline macros.
>
> *Template code blocks*
> Of course, these blocks can be templates.=20
>
> template<int N>
> inline MyBlock
> {
>   foo();
>   for(int i=3D0; i<n; i++)
>     bar();
>   baz();
> }
>
> // some code
> MyBlock<10>; // substitution of AST 'MyBlock' into main AST
>
> These examples are simple, but I have no doubt that there is plenty of=20
> real-world applications of these features. Boost library allows you to do=
=20
> amazing things, but its code is very complex and non-obvious. This featur=
e=20
> is quite simple, but with great potential.=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_49_1409081952.1421187451408
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br></div><div>I haven't used the boost dependency li=
brary just seen snippets of it now and then. But does this&nbsp;proposal&nb=
sp;completely replace stuff like the boost DI library?</div><div>My first t=
houghts were way smaller, like would this allow me&nbsp;to&nbsp;do little&n=
bsp;things like logging with a file and line number without actually having=
 to specify the file and line number or using a macro. But now I think of t=
hat, I don't see how&nbsp;__LINE__&nbsp;could work in such templates as thi=
s proposal offers to be useful&nbsp;for this purpose.</div><div><br></div><=
div>Anyway, I'm keen to see what other people make of this&nbsp;proposal an=
d how it relates to things&nbsp;like the mixins proposal I once saw&nbsp;wh=
ich I don't know what happened with it.</div><div><br>On Wednesday, January=
 14, 2015 at 10:26:35 AM UTC+13, Yuriy Smirnov wrote:</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bo=
rder-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-st=
yle: solid;"><div dir=3D"ltr"><span><font color=3D"#000000" face=3D"Tahoma"=
 size=3D"3">Currently, C++ template is a function or class/struct/union (st=
arting with C++14 is also constant,&nbsp;<a onmousedown=3D"this.href=3D'htt=
ps://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN36=
51.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';ret=
urn true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%=
2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN3651.pdf\46sa\75D\46sntz\0751\46usg\75A=
FQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';return true;" href=3D"https://isocpp.org=
/files/papers/N3651.pdf" target=3D"_blank">https://isocpp.org/<wbr>files/pa=
pers/N3651.pdf</a>), and template&nbsp;parameters can be types or integer c=
onstants.&nbsp;I propose to extend the set of language constructs that can =
be templates and template parameters.</font></span><div style=3D"color: rgb=
(0, 0, 0); font-family: Tahoma; font-size: medium;"><br></div><div style=3D=
"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">Template is =
a compile-time construct. We can say that the passing of a parameter (type =
or integer constant) to template, you actually do not pass the type and not=
 a constant, but a fragment of the syntax tree (AST). Similarly, the code o=
f template is aslo AST fragment with "placeholders", which are&nbsp;are rep=
laced&nbsp;by actual template arguments.</div><div style=3D"color: rgb(0, 0=
, 0); font-family: Tahoma; font-size: medium;"><br></div><div style=3D"colo=
r: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">Therefore, I prop=
ose to expand the possibilities of templates, bringing them to the possibil=
ities of syntactic macros.&nbsp;To this end, I propose to introduce a few e=
xtra features.</div><div><br><div style=3D"color: rgb(0, 0, 0); font-family=
: Tahoma; font-size: medium;">1. allow to pass as template arguments any va=
lid AST nodes, not only the types and integer constants. In particular, the=
 template parameter can be:</div><div><ul><li><span style=3D"color: rgb(0, =
0, 0); font-family: Tahoma; font-size: medium;">constant strings;&nbsp;</sp=
an><br></li><li><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; fo=
nt-size: medium;">floating-point numbers;&nbsp;</span><br></li><li><span st=
yle=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">syntac=
tically&nbsp;correct C++ identifiers</span><br></li><li><span style=3D"colo=
r: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">syntactically cor=
rect expressions</span><br></li><li><span style=3D"color: rgb(0, 0, 0); fon=
t-family: Tahoma; font-size: medium;">syntactically correct&nbsp;blocks of =
code</span><br></li></ul></div></div><div style=3D"color: rgb(0, 0, 0); fon=
t-family: Tahoma; font-size: medium;"><br></div><div style=3D"color: rgb(0,=
 0, 0); font-family: Tahoma; font-size: medium;">2.&nbsp;introduce template=
&nbsp;parameterization&nbsp;not only for the of classes and functions, but =
also for some other language constructs.</div><div><ul><li><span style=3D"c=
olor: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">typedefs</span=
><br></li><li><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font=
-size: medium;">enums</span><br></li><li><span style=3D"color: rgb(0, 0, 0)=
; font-family: Tahoma; font-size: medium;">named blocks of code (*see below=
)</span><br></li></ul></div><div style=3D"color: rgb(0, 0, 0); font-family:=
 Tahoma; font-size: medium;"><span>Consider the proposal in more detail.</s=
pan><br></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-=
size: medium;"><span><br></span></div><div><div style=3D"color: rgb(0, 0, 0=
); font-family: Tahoma; font-size: medium;"><div><b>The first extension -&n=
bsp;&nbsp;allow to pass any correct AST&nbsp;as template arguments.&nbsp;</=
b></div><div>Passing of string and floating-point literals is&nbsp;obvious =
and arranged as well as the passing of integer literals.&nbsp;String, chara=
cter and floating-point literals are no worse than integer literals; and th=
ere is no reason to prohibit to pass them into the templates.</div></div><d=
iv><br></div><div style=3D"border: 1px solid rgb(187, 187, 187); border-ima=
ge: none; -ms-word-wrap: break-word; background-color: rgb(250, 250, 250);"=
><code><div><span style=3D"color: rgb(0, 0, 136);">template</span><span sty=
le=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, =
136);">double</span><span style=3D"color: rgb(0, 0, 0);"> d</span><span sty=
le=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(0, 0, 0);=
"> </span><span style=3D"color: rgb(0, 0, 136);">const</span><span style=3D=
"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 136);">char<=
/span><span style=3D"color: rgb(102, 102, 0);">*</span><span style=3D"color=
: rgb(0, 0, 0);">s</span><span style=3D"color: rgb(102, 102, 0);">&gt;</spa=
n><span style=3D"color: rgb(0, 0, 0);"> <br></span><span style=3D"color: rg=
b(0, 0, 136);">void</span><span style=3D"color: rgb(0, 0, 0);"> foo</span><=
span style=3D"color: rgb(102, 102, 0);">()</span><span style=3D"color: rgb(=
0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">{</span><span s=
tyle=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0=
);">}</span><span style=3D"color: rgb(0, 0, 0);"><br><br>foo</span><span st=
yle=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 10=
2, 102);">3.14159</span><span style=3D"color: rgb(102, 102, 0);">,</span><s=
pan style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 136=
, 0);">"Hello World"</span><span style=3D"color: rgb(102, 102, 0);">&gt;</s=
pan><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(=
102, 102, 0);">();</span><span style=3D"color: rgb(0, 0, 0);"><br><br></spa=
n></div></code></div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma=
; font-size: medium;"><br><div><span>A more interesting case is the passing=
 of names, expressions and code blocks.&nbsp;In fact, this is more general =
case. We must introduce keyword or keywords (similar "typename") for descri=
bing arbitrary AST fragment in template parameter list.&nbsp;For common cas=
e, we can use an existing word "inline":</span></div><div><span><br></span>=
</div><div><div><div style=3D"border: 1px solid rgb(187, 187, 187); border-=
image: none; -ms-word-wrap: break-word; background-color: rgb(250, 250, 250=
);"><code><div><span style=3D"color: rgb(0, 0, 136);">template</span><span =
style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, =
0, 136);">inline</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(102, 0, 102);">Expr</span><span style=3D"color: rgb(102,=
 102, 0);">&gt;</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span=
 style=3D"color: rgb(0, 0, 136);">void</span><span style=3D"color: rgb(0, 0=
, 0);"> </span><span style=3D"color: rgb(102, 0, 102);">Foo</span><span sty=
le=3D"color: rgb(102, 102, 0);">()</span><span style=3D"color: rgb(0, 0, 0)=
;"><br></span><span style=3D"color: rgb(102, 102, 0);">{</span><span style=
=3D"color: rgb(0, 0, 0);"><br>&nbsp; &nbsp;</span><span style=3D"color: rgb=
(0, 0, 136);">while</span><span style=3D"color: rgb(102, 102, 0);">(</span>=
<span style=3D"color: rgb(0, 0, 0);">need_execute_loop</span><span style=3D=
"color: rgb(102, 102, 0);">())</span><span style=3D"color: rgb(0, 0, 0);"><=
br>&nbsp; &nbsp; &nbsp;</span><span style=3D"color: rgb(102, 0, 102);">Expr=
</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"colo=
r: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(102, 102, 0);">}</sp=
an><span style=3D"color: rgb(0, 0, 0);"><br><br></span><span style=3D"color=
: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, 0, 0);"> i</span>=
<span style=3D"color: rgb(102, 102, 0);">,</span><span style=3D"color: rgb(=
0, 0, 0);"> x</span><span style=3D"color: rgb(102, 102, 0);">,</span><span =
style=3D"color: rgb(0, 0, 0);"> y</span><span style=3D"color: rgb(102, 102,=
 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=
=3D"color: rgb(102, 0, 102);">Foo</span><span style=3D"color: rgb(102, 102,=
 0);">&lt;{</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(0, 0, 136);">if</span><span style=3D"color: rgb(102, 102, 0)=
;">(</span><span style=3D"color: rgb(0, 0, 0);">i</span><span style=3D"colo=
r: rgb(102, 102, 0);">&gt;</span><span style=3D"color: rgb(0, 102, 102);">0=
</span><span style=3D"color: rgb(102, 102, 0);">)</span><span style=3D"colo=
r: rgb(0, 0, 0);"> x</span><span style=3D"color: rgb(102, 102, 0);">++;</sp=
an><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0=
, 0, 136);">else</span><span style=3D"color: rgb(0, 0, 0);"> bar</span><spa=
n style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0=
, 0);">y</span><span style=3D"color: rgb(102, 102, 0);">);</span><span styl=
e=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);"=
>}</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color:=
 rgb(102, 102, 0);">&gt;();</span></div></code></div><div><br></div></div><=
/div></div><div><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; fo=
nt-size: medium;">It is advisable to come up with separate keywords for ide=
ntifers, expressions and code blocks&nbsp;(or come up with a mechanism that=
 limits the allowable kinds of parameters, similar concepts).&nbsp;</span><=
/div></div><div><span style=3D"color: rgb(0, 0, 0); font-family: Tahoma; fo=
nt-size: medium;"><br></span></div><div><div><div style=3D"color: rgb(0, 0,=
 0); font-family: Tahoma; font-size: medium;"><b>The second extension - tem=
plates can be not only classes and functions.</b></div><div style=3D"color:=
 rgb(0, 0, 0); font-family: Tahoma; font-size: medium;"><br></div><div styl=
e=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;">It is ob=
vious that we can implement&nbsp;the enum templates and typedef templates.&=
nbsp;</div></div></div><div style=3D"color: rgb(0, 0, 0); font-family: Taho=
ma; font-size: medium;"><br></div><div><div style=3D"color: rgb(0, 0, 0); f=
ont-family: Tahoma; font-size: medium;"><div style=3D"border: 1px solid rgb=
(187, 187, 187); border-image: none; -ms-word-wrap: break-word; background-=
color: rgb(250, 250, 250);"><code><div><span style=3D"color: rgb(0, 0, 136)=
;">template</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span=
 style=3D"color: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, 0,=
 0);"> N</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span st=
yle=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136=
);">enum</span><span style=3D"color: rgb(0, 0, 0);"> E </span><span style=
=3D"color: rgb(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);">=
<br>&nbsp; E1 </span><span style=3D"color: rgb(102, 102, 0);">=3D</span><sp=
an style=3D"color: rgb(0, 0, 0);"> N</span><span style=3D"color: rgb(102, 1=
02, 0);">,</span><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; E2<br></sp=
an><span style=3D"color: rgb(102, 102, 0);">};</span><span style=3D"color: =
rgb(0, 0, 0);"><br><br></span><span style=3D"color: rgb(0, 0, 136);">templa=
te</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D=
"color: rgb(0, 0, 136);">typename</span><span style=3D"color: rgb(0, 0, 0);=
"> T</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span style=
=3D"color: rgb(0, 0, 0);"> <br></span><span style=3D"color: rgb(0, 0, 136);=
">typedef</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D=
"color: rgb(0, 0, 136);">const</span><span style=3D"color: rgb(0, 0, 0);"> =
</span><span style=3D"color: rgb(102, 0, 102);">MyClass</span><span style=
=3D"color: rgb(102, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 0, 0)=
;">T</span><span style=3D"color: rgb(102, 102, 0);">&gt;&amp;</span><span s=
tyle=3D"color: rgb(0, 0, 0);"> &nbsp; </span><span style=3D"color: rgb(102,=
 0, 102);">My</span><span style=3D"color: rgb(102, 102, 0);">=D0=A1</span><=
span style=3D"color: rgb(102, 0, 102);">Ref</span><span style=3D"color: rgb=
(102, 102, 0);">;</span></div></code></div><div><br></div></div><div><div s=
tyle=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;"><div>=
Furthermore, I suggest interesting extension - Template code blocks. But fi=
rst, we should consider the concept of "inline code blocks".&nbsp;This is a=
 separate proposal.</div><div><br></div><div><b>Inline code blocks</b></div=
><div>The code block is named declarative construct including an arbitrary =
code. It is like lexical macro from C/C++ preprocessor, but deeply integrat=
ed into the language; as we remember, the preprocessor is not related to th=
e language: it ignores the scope rules and namespaces, and even keywords of=
 C++ - we can write "#define true false" and&nbsp;it compiles! In fact, pre=
processor is dangerous thing.&nbsp;</div><div><br></div><div>Instead, I pro=
pose to introduce a declarative code blocks with the possibility of substit=
ution in any place of the program.&nbsp;We can use an existing keyword "inl=
ine" or use another keyword.</div></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Tahoma; font-size: medium;"><br></div><div style=3D"color: rgb=
(0, 0, 0); font-family: Tahoma; font-size: medium;"><div><div style=3D"bord=
er: 1px solid rgb(187, 187, 187); border-image: none; -ms-word-wrap: break-=
word; background-color: rgb(250, 250, 250);"><code><div><span style=3D"colo=
r: rgb(136, 0, 0);">// declare block, like struct or class; </span><span st=
yle=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136=
);">inline</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(102, 0, 102);">MyBlock</span><span style=3D"color: rgb(0, 0,=
 0);"><br></span><span style=3D"color: rgb(102, 102, 0);">{</span><span sty=
le=3D"color: rgb(0, 0, 0);"><br>&nbsp; foo</span><span style=3D"color: rgb(=
102, 102, 0);">();</span><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; ba=
r</span><span style=3D"color: rgb(102, 102, 0);">();</span><span style=3D"c=
olor: rgb(0, 0, 0);"><br>&nbsp; baz</span><span style=3D"color: rgb(102, 10=
2, 0);">();</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span sty=
le=3D"color: rgb(102, 102, 0);">}</span><span style=3D"color: rgb(0, 0, 0);=
"><br><br></span><span style=3D"color: rgb(136, 0, 0);">// some code</span>=
<span style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(1=
02, 0, 102);">MyBlock</span><span style=3D"color: rgb(102, 102, 0);">;</spa=
n><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(13=
6, 0, 0);">// substitution of AST 'MyBlock' into main AST</span></div></cod=
e></div><div><br></div></div></div><div><div><div style=3D"color: rgb(0, 0,=
 0); font-family: Tahoma; font-size: medium;">These blocks differ from the =
functions that they not called. They substituted as inline-functions direct=
ly into code.&nbsp;It is assumed that such units must be used instead of Ma=
cros. Unlike inline functions, it is simply AST fragments.&nbsp;I am faced =
with the necessity of such constructions&nbsp;in embedded programming.&nbsp=
;Braces allow to do without the dreaded "\" in multiline macros.</div><div =
style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: medium;"><br>=
</div><div style=3D"color: rgb(0, 0, 0); font-family: Tahoma; font-size: me=
dium;"><b>Template code blocks</b></div><div style=3D"color: rgb(0, 0, 0); =
font-family: Tahoma; font-size: medium;">Of course, these blocks can be tem=
plates.&nbsp;</div></div><div style=3D"color: rgb(0, 0, 0); font-family: Ta=
homa; font-size: medium;"><br></div><div style=3D"color: rgb(0, 0, 0); font=
-family: Tahoma; font-size: medium;"><div><div style=3D"border: 1px solid r=
gb(187, 187, 187); border-image: none; -ms-word-wrap: break-word; backgroun=
d-color: rgb(250, 250, 250);"><code><div><span style=3D"color: rgb(0, 0, 13=
6);">template</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><sp=
an style=3D"color: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, =
0, 0);"> N</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span =
style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 1=
36);">inline</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=
=3D"color: rgb(102, 0, 102);">MyBlock</span><span style=3D"color: rgb(0, 0,=
 0);"><br></span><span style=3D"color: rgb(102, 102, 0);">{</span><span sty=
le=3D"color: rgb(0, 0, 0);"><br>&nbsp; foo</span><span style=3D"color: rgb(=
102, 102, 0);">();</span><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; </=
span><span style=3D"color: rgb(0, 0, 136);">for</span><span style=3D"color:=
 rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 136);">int</spa=
n><span style=3D"color: rgb(0, 0, 0);"> i</span><span style=3D"color: rgb(1=
02, 102, 0);">=3D</span><span style=3D"color: rgb(0, 102, 102);">0</span><s=
pan style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0,=
 0, 0);"> i</span><span style=3D"color: rgb(102, 102, 0);">&lt;</span><span=
 style=3D"color: rgb(0, 0, 0);">n</span><span style=3D"color: rgb(102, 102,=
 0);">;</span><span style=3D"color: rgb(0, 0, 0);"> i</span><span style=3D"=
color: rgb(102, 102, 0);">++)</span><span style=3D"color: rgb(0, 0, 0);"><b=
r>&nbsp; &nbsp; bar</span><span style=3D"color: rgb(102, 102, 0);">();</spa=
n><span style=3D"color: rgb(0, 0, 0);"><br>&nbsp; baz</span><span style=3D"=
color: rgb(102, 102, 0);">();</span><span style=3D"color: rgb(0, 0, 0);"><b=
r></span><span style=3D"color: rgb(102, 102, 0);">}</span><span style=3D"co=
lor: rgb(0, 0, 0);"><br><br></span><span style=3D"color: rgb(136, 0, 0);">/=
/ some code</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span sty=
le=3D"color: rgb(102, 0, 102);">MyBlock</span><span style=3D"color: rgb(102=
, 102, 0);">&lt;</span><span style=3D"color: rgb(0, 102, 102);">10</span><s=
pan style=3D"color: rgb(102, 102, 0);">&gt;;</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(136, 0, 0);">// substitution=
 of AST 'MyBlock' into main AST</span></div></code></div><div><div><br></di=
v></div></div></div></div></div><div style=3D"color: rgb(0, 0, 0); font-fam=
ily: Tahoma; font-size: medium;"><div><span>These examples are simple, but =
I have no doubt that there is plenty of real-world applications of these fe=
atures.&nbsp;Boost library allows you to do amazing things, but its code is=
 very complex and non-obvious.&nbsp;This feature is quite simple, but with =
great potential.&nbsp;</span></div><div><span><br></span></div></div></div>=
</div></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 />

------=_Part_49_1409081952.1421187451408--
------=_Part_48_1469858599.1421187451407--

.


Author: Yuriy Smirnov <neoprogramming@gmail.com>
Date: Tue, 13 Jan 2015 23:20:56 -0800 (PST)
Raw View
------=_Part_5188_580852742.1421220056837
Content-Type: multipart/alternative;
 boundary="----=_Part_5189_2078859179.1421220056837"

------=_Part_5189_2078859179.1421220056837
Content-Type: text/plain; charset=UTF-8


>
> What about "union template"?
>
>
Union templates already have (msvc 2010, 2013, gcc 4.8.2, I checked it)


--

---
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_5189_2078859179.1421220056837
Content-Type: text/html; charset=UTF-8

<div dir="ltr"><blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">What about "union template"?
<br>
<br></blockquote><div><br></div><div>Union templates already have (msvc 2010, 2013, gcc 4.8.2, I checked it)</div><div>&nbsp;<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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_5189_2078859179.1421220056837--
------=_Part_5188_580852742.1421220056837--

.


Author: masse.nicolas@gmail.com
Date: Wed, 14 Jan 2015 03:29:34 -0800 (PST)
Raw View
------=_Part_2532_859313369.1421234974510
Content-Type: multipart/alternative;
 boundary="----=_Part_2533_652266708.1421234974510"

------=_Part_2533_652266708.1421234974510
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Did you had a look at N4147 ?

Le mardi 13 janvier 2015 22:26:35 UTC+1, Yuriy Smirnov a =C3=A9crit :
>
> Currently, C++ template is a function or class/struct/union (starting wit=
h=20
> C++14 is also constant, https://isocpp.org/files/papers/N3651.pdf), and=
=20
> template parameters can be types or integer constants. I propose to exten=
d=20
> the set of language constructs that can be templates and template=20
> parameters.
>
> Template is a compile-time construct. We can say that the passing of a=20
> parameter (type or integer constant) to template, you actually do not pas=
s=20
> the type and not a constant, but a fragment of the syntax tree (AST).=20
> Similarly, the code of template is aslo AST fragment with "placeholders",=
=20
> which are are replaced by actual template arguments.
>
> Therefore, I propose to expand the possibilities of templates, bringing=
=20
> them to the possibilities of syntactic macros. To this end, I propose to=
=20
> introduce a few extra features.
>
> 1. allow to pass as template arguments any valid AST nodes, not only the=
=20
> types and integer constants. In particular, the template parameter can be=
:
>
>    - constant strings;=20
>    - floating-point numbers;=20
>    - syntactically correct C++ identifiers
>    - syntactically correct expressions
>    - syntactically correct blocks of code
>   =20
>
> 2. introduce template parameterization not only for the of classes and=20
> functions, but also for some other language constructs.
>
>    - typedefs
>    - enums
>    - named blocks of code (*see below)
>   =20
> Consider the proposal in more detail.
>
> *The first extension -  allow to pass any correct AST as template=20
> arguments. *
> Passing of string and floating-point literals is obvious and arranged as=
=20
> well as the passing of integer literals. String, character and=20
> floating-point literals are no worse than integer literals; and there is =
no=20
> reason to prohibit to pass them into the templates.
>
> template<double d, const char*s>=20
> void foo() { }
>
> foo<3.14159, "Hello World"> ();
>
>
> A more interesting case is the passing of names, expressions and code=20
> blocks. In fact, this is more general case. We must introduce keyword or=
=20
> keywords (similar "typename") for describing arbitrary AST fragment in=20
> template parameter list. For common case, we can use an existing word=20
> "inline":
>
> template<inline Expr>
> void Foo()
> {
>    while(need_execute_loop())
>      Expr;
> }
>
> int i, x, y;
> Foo<{ if(i>0) x++; else bar(y); } >();
>
> It is advisable to come up with separate keywords for identifers,=20
> expressions and code blocks (or come up with a mechanism that limits the=
=20
> allowable kinds of parameters, similar concepts).=20
>
> *The second extension - templates can be not only classes and functions.*
>
> It is obvious that we can implement the enum templates and typedef=20
> templates.=20
>
> template<int N>
> enum E {
>   E1 =3D N,
>   E2
> };
>
> template<typename T>=20
> typedef const MyClass<T>&   My=D0=A1Ref;
>
> Furthermore, I suggest interesting extension - Template code blocks. But=
=20
> first, we should consider the concept of "inline code blocks". This is a=
=20
> separate proposal.
>
> *Inline code blocks*
> The code block is named declarative construct including an arbitrary code=
..=20
> It is like lexical macro from C/C++ preprocessor, but deeply integrated=
=20
> into the language; as we remember, the preprocessor is not related to the=
=20
> language: it ignores the scope rules and namespaces, and even keywords of=
=20
> C++ - we can write "#define true false" and it compiles! In fact,=20
> preprocessor is dangerous thing.=20
>
> Instead, I propose to introduce a declarative code blocks with the=20
> possibility of substitution in any place of the program. We can use an=20
> existing keyword "inline" or use another keyword.
>
> // declare block, like struct or class;=20
> inline MyBlock
> {
>   foo();
>   bar();
>   baz();
> }
>
> // some code
> MyBlock; // substitution of AST 'MyBlock' into main AST
>
> These blocks differ from the functions that they not called. They=20
> substituted as inline-functions directly into code. It is assumed that su=
ch=20
> units must be used instead of Macros. Unlike inline functions, it is simp=
ly=20
> AST fragments. I am faced with the necessity of such constructions in=20
> embedded programming. Braces allow to do without the dreaded "\" in=20
> multiline macros.
>
> *Template code blocks*
> Of course, these blocks can be templates.=20
>
> template<int N>
> inline MyBlock
> {
>   foo();
>   for(int i=3D0; i<n; i++)
>     bar();
>   baz();
> }
>
> // some code
> MyBlock<10>; // substitution of AST 'MyBlock' into main AST
>
> These examples are simple, but I have no doubt that there is plenty of=20
> real-world applications of these features. Boost library allows you to do=
=20
> amazing things, but its code is very complex and non-obvious. This featur=
e=20
> is quite simple, but with great potential.=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_2533_652266708.1421234974510
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Did you had a look at N4147 ?<br><br>Le mardi 13 janvier 2=
015 22:26:35 UTC+1, Yuriy Smirnov a =C3=A9crit&nbsp;:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;"><div dir=3D"ltr"><span style=3D"text-align:-webkit-a=
uto"><font color=3D"#000000" face=3D"Tahoma" size=3D"3">Currently, C++ temp=
late is a function or class/struct/union (starting with C++14 is also const=
ant,&nbsp;<a href=3D"https://isocpp.org/files/papers/N3651.pdf" target=3D"_=
blank" onmousedown=3D"this.href=3D'https://www.google.com/url?q\75https%3A%=
2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN3651.pdf\46sa\75D\46sntz\0751\46usg\75A=
FQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';return true;" onclick=3D"this.href=3D'ht=
tps://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN3=
651.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';re=
turn true;">https://isocpp.org/<wbr>files/papers/N3651.pdf</a>), and templa=
te&nbsp;parameters can be types or integer constants.&nbsp;I propose to ext=
end the set of language constructs that can be templates and template param=
eters.</font></span><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-=
align:-webkit-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,=
0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium">Template is=
 a compile-time construct. We can say that the passing of a parameter (type=
 or integer constant) to template, you actually do not pass the type and no=
t a constant, but a fragment of the syntax tree (AST). Similarly, the code =
of template is aslo AST fragment with "placeholders", which are&nbsp;are re=
placed&nbsp;by actual template arguments.</div><div style=3D"color:rgb(0,0,=
0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><br></div><=
div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;fo=
nt-size:medium">Therefore, I propose to expand the possibilities of templat=
es, bringing them to the possibilities of syntactic macros.&nbsp;To this en=
d, I propose to introduce a few extra features.</div><div style=3D"text-ali=
gn:-webkit-auto"><br><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font=
-size:medium">1. allow to pass as template arguments any valid AST nodes, n=
ot only the types and integer constants. In particular, the template parame=
ter can be:</div><div><ul><li><span style=3D"color:rgb(0,0,0);font-family:T=
ahoma;font-size:medium;text-align:-webkit-auto">constant strings;&nbsp;</sp=
an><br></li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-siz=
e:medium;text-align:-webkit-auto">floating-point numbers;&nbsp;</span><br><=
/li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium=
;text-align:-webkit-auto">syntactically&nbsp;correct C++ identifiers</span>=
<br></li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:m=
edium;text-align:-webkit-auto">syntactically correct expressions</span><br>=
</li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:mediu=
m;text-align:-webkit-auto">syntactically correct&nbsp;blocks of code</span>=
<br></li></ul></div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma=
;text-align:-webkit-auto;font-size:medium"><br></div><div style=3D"color:rg=
b(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium">2.&nb=
sp;introduce template&nbsp;parameterization&nbsp;not only for the of classe=
s and functions, but also for some other language constructs.</div><div sty=
le=3D"text-align:-webkit-auto"><ul><li><span style=3D"color:rgb(0,0,0);font=
-family:Tahoma;font-size:medium;text-align:-webkit-auto">typedefs</span><br=
></li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medi=
um;text-align:-webkit-auto">enums</span><br></li><li><span style=3D"color:r=
gb(0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto">name=
d blocks of code (*see below)</span><br></li></ul></div><div style=3D"color=
:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><s=
pan style=3D"text-align:-webkit-auto">Consider the proposal in more detail.=
</span><br></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-ali=
gn:-webkit-auto;font-size:medium"><span style=3D"text-align:-webkit-auto"><=
br></span></div><div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font=
-size:medium"><div style=3D"text-align:-webkit-auto"><b>The first extension=
 -&nbsp;&nbsp;allow to pass any correct AST&nbsp;as template arguments.&nbs=
p;</b></div><div style=3D"text-align:-webkit-auto">Passing of string and fl=
oating-point literals is&nbsp;obvious and arranged as well as the passing o=
f integer literals.&nbsp;String, character and floating-point literals are =
no worse than integer literals; and there is no reason to prohibit to pass =
them into the templates.</div></div><div><br></div><div style=3D"border:1px=
 solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,2=
50)"><code><div><span style=3D"color:#008">template</span><span style=3D"co=
lor:#660">&lt;</span><span style=3D"color:#008">double</span><span style=3D=
"color:#000"> d</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">const</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#008">char</span><span style=3D"color:=
#660">*</span><span style=3D"color:#000">s</span><span style=3D"color:#660"=
>&gt;</span><span style=3D"color:#000"> <br></span><span style=3D"color:#00=
8">void</span><span style=3D"color:#000"> foo</span><span style=3D"color:#6=
60">()</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</sp=
an><span style=3D"color:#000"><br><br>foo</span><span style=3D"color:#660">=
&lt;</span><span style=3D"color:#066">3.14159</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
Hello World"</span><span style=3D"color:#660">&gt;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">();</span><span style=3D"color:=
#000"><br><br></span></div></code></div><div style=3D"color:rgb(0,0,0);font=
-family:Tahoma;text-align:-webkit-auto;font-size:medium"><br><div><span sty=
le=3D"text-align:-webkit-auto">A more interesting case is the passing of na=
mes, expressions and code blocks.&nbsp;In fact, this is more general case. =
We must introduce keyword or keywords (similar "typename") for describing a=
rbitrary AST fragment in template parameter list.&nbsp;For common case, we =
can use an existing word "inline":</span></div><div><span style=3D"text-ali=
gn:-webkit-auto"><br></span></div><div><div><div style=3D"border:1px solid =
rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><c=
ode><div><span style=3D"color:#008">template</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#008">inline</span><span style=3D"color:=
#000"> </span><span style=3D"color:#606">Expr</span><span style=3D"color:#6=
60">&gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#=
008">void</span><span style=3D"color:#000"> </span><span style=3D"color:#60=
6">Foo</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>&nbsp; &nbsp;</span><span style=3D"color:#008">while</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">need_execute_loop</span>=
<span style=3D"color:#660">())</span><span style=3D"color:#000"><br>&nbsp; =
&nbsp; &nbsp;</span><span style=3D"color:#606">Expr</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"><br><br></span><span style=3D"co=
lor:#008">int</span><span style=3D"color:#000"> i</span><span style=3D"colo=
r:#660">,</span><span style=3D"color:#000"> x</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> y</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"><br></span><span style=3D"color:#606">Fo=
o</span><span style=3D"color:#660">&lt;{</span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">if</span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#000">i</span><span style=3D"color:#660">&gt;</span=
><span style=3D"color:#066">0</span><span style=3D"color:#660">)</span><spa=
n style=3D"color:#000"> x</span><span style=3D"color:#660">++;</span><span =
style=3D"color:#000"> </span><span style=3D"color:#008">else</span><span st=
yle=3D"color:#000"> bar</span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#000">y</span><span style=3D"color:#660">);</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">&gt;();</span></div></code></div=
><div style=3D"text-align:-webkit-auto"><br></div></div></div></div><div><s=
pan style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;fo=
nt-size:medium">It is advisable to come up with separate keywords for ident=
ifers, expressions and code blocks&nbsp;(or come up with a mechanism that l=
imits the allowable kinds of parameters, similar concepts).&nbsp;</span></d=
iv></div><div><span style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align=
:-webkit-auto;font-size:medium"><br></span></div><div><div><div style=3D"co=
lor:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium"=
><b>The second extension - templates can be not only classes and functions.=
</b></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-web=
kit-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);font-fa=
mily:Tahoma;text-align:-webkit-auto;font-size:medium">It is obvious that we=
 can implement&nbsp;the enum templates and typedef templates.&nbsp;</div></=
div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-web=
kit-auto;font-size:medium"><br></div><div style=3D"text-align:-webkit-auto"=
><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><div s=
tyle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-c=
olor:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</span=
><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">int</span=
><span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</span>=
<span style=3D"color:#000"><br></span><span style=3D"color:#008">enum</span=
><span style=3D"color:#000"> E </span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"><br>&nbsp; E1 </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> N</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"><br>&nbsp; E2<br></span><span style=3D"col=
or:#660">};</span><span style=3D"color:#000"><br><br></span><span style=3D"=
color:#008">template</span><span style=3D"color:#660">&lt;</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> T</span><span s=
tyle=3D"color:#660">&gt;</span><span style=3D"color:#000"> <br></span><span=
 style=3D"color:#008">typedef</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">const</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#606">MyClass</span><span style=3D"color:#660">&lt;</span><=
span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;&amp;</spa=
n><span style=3D"color:#000"> &nbsp; </span><span style=3D"color:#606">My</=
span><span style=3D"color:#660">=D0=A1</span><span style=3D"color:#606">Ref=
</span><span style=3D"color:#660">;</span></div></code></div><div style=3D"=
text-align:-webkit-auto"><br></div></div><div style=3D"text-align:-webkit-a=
uto"><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><d=
iv style=3D"text-align:-webkit-auto">Furthermore, I suggest interesting ext=
ension - Template code blocks. But first, we should consider the concept of=
 "inline code blocks".&nbsp;This is a separate proposal.</div><div style=3D=
"text-align:-webkit-auto"><br></div><div style=3D"text-align:-webkit-auto">=
<b>Inline code blocks</b></div><div style=3D"text-align:-webkit-auto">The c=
ode block is named declarative construct including an arbitrary code. It is=
 like lexical macro from C/C++ preprocessor, but deeply integrated into the=
 language; as we remember, the preprocessor is not related to the language:=
 it ignores the scope rules and namespaces, and even keywords of C++ - we c=
an write "#define true false" and&nbsp;it compiles! In fact, preprocessor i=
s dangerous thing.&nbsp;</div><div style=3D"text-align:-webkit-auto"><br></=
div><div style=3D"text-align:-webkit-auto">Instead, I propose to introduce =
a declarative code blocks with the possibility of substitution in any place=
 of the program.&nbsp;We can use an existing keyword "inline" or use anothe=
r keyword.</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;fon=
t-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,=
0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><div=
 style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background=
-color:rgb(250,250,250)"><code><div><span style=3D"color:#800">// declare b=
lock, like struct or class; </span><span style=3D"color:#000"><br></span><s=
pan style=3D"color:#008">inline</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#606">MyBlock</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; =
foo</span><span style=3D"color:#660">();</span><span style=3D"color:#000"><=
br>&nbsp; bar</span><span style=3D"color:#660">();</span><span style=3D"col=
or:#000"><br>&nbsp; baz</span><span style=3D"color:#660">();</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span styl=
e=3D"color:#000"><br><br></span><span style=3D"color:#800">// some code</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#606">MyBlock=
</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#800">// substitution of AST 'MyBlock' into main AST=
</span></div></code></div><div style=3D"text-align:-webkit-auto"><br></div>=
</div></div><div style=3D"text-align:-webkit-auto"><div><div style=3D"color=
:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto">Th=
ese blocks differ from the functions that they not called. They substituted=
 as inline-functions directly into code.&nbsp;It is assumed that such units=
 must be used instead of Macros. Unlike inline functions, it is simply AST =
fragments.&nbsp;I am faced with the necessity of such constructions&nbsp;in=
 embedded programming.&nbsp;Braces allow to do without the dreaded "\" in m=
ultiline macros.</div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;fon=
t-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,=
0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><b>Templa=
te code blocks</b></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;f=
ont-size:medium;text-align:-webkit-auto">Of course, these blocks can be tem=
plates.&nbsp;</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;=
font-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb=
(0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><=
div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgro=
und-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">template<=
/span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">int<=
/span><span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</=
span><span style=3D"color:#000"><br></span><span style=3D"color:#008">inlin=
e</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyBlo=
ck</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>&nbsp; foo</span><span style=3D"color=
:#660">();</span><span style=3D"color:#000"><br>&nbsp; </span><span style=
=3D"color:#008">for</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">int</span><span style=3D"color:#000"> i</span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#066">0</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"> i</span><span style=3D"color:#6=
60">&lt;</span><span style=3D"color:#000">n</span><span style=3D"color:#660=
">;</span><span style=3D"color:#000"> i</span><span style=3D"color:#660">++=
)</span><span style=3D"color:#000"><br>&nbsp; &nbsp; bar</span><span style=
=3D"color:#660">();</span><span style=3D"color:#000"><br>&nbsp; baz</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><br></span=
><span style=3D"color:#800">// some code</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#606">MyBlock</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#066">10</span><span style=3D"color:#660=
">&gt;;</span><span style=3D"color:#000"> </span><span style=3D"color:#800"=
>// substitution of AST 'MyBlock' into main AST</span></div></code></div><d=
iv style=3D"text-align:-webkit-auto"><div><br></div></div></div></div></div=
></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;t=
ext-align:-webkit-auto"><div><span style=3D"text-align:-webkit-auto">These =
examples are simple, but I have no doubt that there is plenty of real-world=
 applications of these features.&nbsp;Boost library allows you to do amazin=
g things, but its code is very complex and non-obvious.&nbsp;This feature i=
s quite simple, but with great potential.&nbsp;</span></div><div><span styl=
e=3D"text-align:-webkit-auto"><br></span></div></div></div></div></blockquo=
te></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_2533_652266708.1421234974510--
------=_Part_2532_859313369.1421234974510--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 14 Jan 2015 10:14:04 -0500
Raw View
On Wed, Jan 14, 2015 at 2:20 AM, Yuriy Smirnov <neoprogramming@gmail.com> wrote:
>> What about "union template"?
>>
>
> Union templates already have (msvc 2010, 2013, gcc 4.8.2, I checked it)

Ah, I'm sorry, it's in standard long long time ago,
because union is also a class.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://bit.ly/blog4bsd

--

---
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: snk_kid <korcan.hussein@googlemail.com>
Date: Wed, 14 Jan 2015 08:48:31 -0800 (PST)
Raw View
------=_Part_252_163988762.1421254111079
Content-Type: multipart/alternative;
 boundary="----=_Part_253_937603833.1421254111079"

------=_Part_253_937603833.1421254111079
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Extending/modifying templates for this is really bad idea, a much better=20
idea would be to support this with via constexpr functions and few new=20
language additions as some of us as have been discussing before:

https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposa=
ls/MblNbx7xc94

Please lets stop making templates even more complicated than they already=
=20
are just for the sake of meta-programming. Templates were never designed=20
for meta-programming and it completely shows, they are severally limited=20
compared to proper meta-programming support, the meta-language is different=
=20
from the object language which makes them hard to use & maintain by the 99%=
..

I believe constexpr functions are the best place to extend/add proper=20
meta-programming facilitates to C++ and the meta-language and object=20
language are the same which is much better for the average C++ for=20
readability/maintainability.

On Tuesday, January 13, 2015 at 9:26:35 PM UTC, Yuriy Smirnov wrote:
>
> Currently, C++ template is a function or class/struct/union (starting wit=
h=20
> C++14 is also constant, https://isocpp.org/files/papers/N3651.pdf), and=
=20
> template parameters can be types or integer constants. I propose to exten=
d=20
> the set of language constructs that can be templates and template=20
> parameters.
>
> Template is a compile-time construct. We can say that the passing of a=20
> parameter (type or integer constant) to template, you actually do not pas=
s=20
> the type and not a constant, but a fragment of the syntax tree (AST).=20
> Similarly, the code of template is aslo AST fragment with "placeholders",=
=20
> which are are replaced by actual template arguments.
>
> Therefore, I propose to expand the possibilities of templates, bringing=
=20
> them to the possibilities of syntactic macros. To this end, I propose to=
=20
> introduce a few extra features.
>
> 1. allow to pass as template arguments any valid AST nodes, not only the=
=20
> types and integer constants. In particular, the template parameter can be=
:
>
>    - constant strings;=20
>    - floating-point numbers;=20
>    - syntactically correct C++ identifiers
>    - syntactically correct expressions
>    - syntactically correct blocks of code
>   =20
>
> 2. introduce template parameterization not only for the of classes and=20
> functions, but also for some other language constructs.
>
>    - typedefs
>    - enums
>    - named blocks of code (*see below)
>   =20
> Consider the proposal in more detail.
>
> *The first extension -  allow to pass any correct AST as template=20
> arguments. *
> Passing of string and floating-point literals is obvious and arranged as=
=20
> well as the passing of integer literals. String, character and=20
> floating-point literals are no worse than integer literals; and there is =
no=20
> reason to prohibit to pass them into the templates.
>
> template<double d, const char*s>=20
> void foo() { }
>
> foo<3.14159, "Hello World"> ();
>
>
> A more interesting case is the passing of names, expressions and code=20
> blocks. In fact, this is more general case. We must introduce keyword or=
=20
> keywords (similar "typename") for describing arbitrary AST fragment in=20
> template parameter list. For common case, we can use an existing word=20
> "inline":
>
> template<inline Expr>
> void Foo()
> {
>    while(need_execute_loop())
>      Expr;
> }
>
> int i, x, y;
> Foo<{ if(i>0) x++; else bar(y); } >();
>
> It is advisable to come up with separate keywords for identifers,=20
> expressions and code blocks (or come up with a mechanism that limits the=
=20
> allowable kinds of parameters, similar concepts).=20
>
> *The second extension - templates can be not only classes and functions.*
>
> It is obvious that we can implement the enum templates and typedef=20
> templates.=20
>
> template<int N>
> enum E {
>   E1 =3D N,
>   E2
> };
>
> template<typename T>=20
> typedef const MyClass<T>&   My=D0=A1Ref;
>
> Furthermore, I suggest interesting extension - Template code blocks. But=
=20
> first, we should consider the concept of "inline code blocks". This is a=
=20
> separate proposal.
>
> *Inline code blocks*
> The code block is named declarative construct including an arbitrary code=
..=20
> It is like lexical macro from C/C++ preprocessor, but deeply integrated=
=20
> into the language; as we remember, the preprocessor is not related to the=
=20
> language: it ignores the scope rules and namespaces, and even keywords of=
=20
> C++ - we can write "#define true false" and it compiles! In fact,=20
> preprocessor is dangerous thing.=20
>
> Instead, I propose to introduce a declarative code blocks with the=20
> possibility of substitution in any place of the program. We can use an=20
> existing keyword "inline" or use another keyword.
>
> // declare block, like struct or class;=20
> inline MyBlock
> {
>   foo();
>   bar();
>   baz();
> }
>
> // some code
> MyBlock; // substitution of AST 'MyBlock' into main AST
>
> These blocks differ from the functions that they not called. They=20
> substituted as inline-functions directly into code. It is assumed that su=
ch=20
> units must be used instead of Macros. Unlike inline functions, it is simp=
ly=20
> AST fragments. I am faced with the necessity of such constructions in=20
> embedded programming. Braces allow to do without the dreaded "\" in=20
> multiline macros.
>
> *Template code blocks*
> Of course, these blocks can be templates.=20
>
> template<int N>
> inline MyBlock
> {
>   foo();
>   for(int i=3D0; i<n; i++)
>     bar();
>   baz();
> }
>
> // some code
> MyBlock<10>; // substitution of AST 'MyBlock' into main AST
>
> These examples are simple, but I have no doubt that there is plenty of=20
> real-world applications of these features. Boost library allows you to do=
=20
> amazing things, but its code is very complex and non-obvious. This featur=
e=20
> is quite simple, but with great potential.=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_253_937603833.1421254111079
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Extending/modifying templates for this is really bad idea,=
 a much better idea would be to support this with via constexpr functions a=
nd few new language additions as some of us as have been discussing before:=
<br><br>https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std=
-proposals/MblNbx7xc94<br><br>Please lets stop making templates even more c=
omplicated than they already are just for the sake of meta-programming. Tem=
plates were never designed for meta-programming and it completely shows, th=
ey are severally limited compared to proper meta-programming support, the m=
eta-language is different from the object language which makes them hard to=
 use &amp; maintain by the 99%.<br><br>I believe constexpr functions are th=
e best place to extend/add proper meta-programming facilitates to C++ and t=
he meta-language and object language are the same which is much better for =
the average C++ for readability/maintainability.<br><br>On Tuesday, January=
 13, 2015 at 9:26:35 PM UTC, Yuriy Smirnov wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><div dir=3D"ltr"><span style=3D"text-align:-webkit-auto"=
><font face=3D"Tahoma" color=3D"#000000" size=3D"3">Currently, C++ template=
 is a function or class/struct/union (starting with C++14 is also constant,=
&nbsp;<a href=3D"https://isocpp.org/files/papers/N3651.pdf" target=3D"_blan=
k" onmousedown=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2=
Fisocpp.org%2Ffiles%2Fpapers%2FN3651.pdf\46sa\75D\46sntz\0751\46usg\75AFQjC=
NEPq23vkrlAKv5mrQPSMMAzV0HOYA';return true;" onclick=3D"this.href=3D'https:=
//www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN3651.=
pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';return=
 true;">https://isocpp.org/<wbr>files/papers/N3651.pdf</a>), and template&n=
bsp;parameters can be types or integer constants.&nbsp;I propose to extend =
the set of language constructs that can be templates and template parameter=
s.</font></span><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-alig=
n:-webkit-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);f=
ont-family:Tahoma;text-align:-webkit-auto;font-size:medium">Template is a c=
ompile-time construct. We can say that the passing of a parameter (type or =
integer constant) to template, you actually do not pass the type and not a =
constant, but a fragment of the syntax tree (AST). Similarly, the code of t=
emplate is aslo AST fragment with "placeholders", which are&nbsp;are replac=
ed&nbsp;by actual template arguments.</div><div style=3D"color:rgb(0,0,0);f=
ont-family:Tahoma;text-align:-webkit-auto;font-size:medium"><br></div><div =
style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-s=
ize:medium">Therefore, I propose to expand the possibilities of templates, =
bringing them to the possibilities of syntactic macros.&nbsp;To this end, I=
 propose to introduce a few extra features.</div><div style=3D"text-align:-=
webkit-auto"><br><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-siz=
e:medium">1. allow to pass as template arguments any valid AST nodes, not o=
nly the types and integer constants. In particular, the template parameter =
can be:</div><div><ul><li><span style=3D"color:rgb(0,0,0);font-family:Tahom=
a;font-size:medium;text-align:-webkit-auto">constant strings;&nbsp;</span><=
br></li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:me=
dium;text-align:-webkit-auto">floating-point numbers;&nbsp;</span><br></li>=
<li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;tex=
t-align:-webkit-auto">syntactically&nbsp;correct C++ identifiers</span><br>=
</li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:mediu=
m;text-align:-webkit-auto">syntactically correct expressions</span><br></li=
><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;te=
xt-align:-webkit-auto">syntactically correct&nbsp;blocks of code</span><br>=
</li></ul></div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;tex=
t-align:-webkit-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,=
0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium">2.&nbsp;i=
ntroduce template&nbsp;parameterization&nbsp;not only for the of classes an=
d functions, but also for some other language constructs.</div><div style=
=3D"text-align:-webkit-auto"><ul><li><span style=3D"color:rgb(0,0,0);font-f=
amily:Tahoma;font-size:medium;text-align:-webkit-auto">typedefs</span><br><=
/li><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium=
;text-align:-webkit-auto">enums</span><br></li><li><span style=3D"color:rgb=
(0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto">named =
blocks of code (*see below)</span><br></li></ul></div><div style=3D"color:r=
gb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><spa=
n style=3D"text-align:-webkit-auto">Consider the proposal in more detail.</=
span><br></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align=
:-webkit-auto;font-size:medium"><span style=3D"text-align:-webkit-auto"><br=
></span></div><div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-s=
ize:medium"><div style=3D"text-align:-webkit-auto"><b>The first extension -=
&nbsp;&nbsp;allow to pass any correct AST&nbsp;as template arguments.&nbsp;=
</b></div><div style=3D"text-align:-webkit-auto">Passing of string and floa=
ting-point literals is&nbsp;obvious and arranged as well as the passing of =
integer literals.&nbsp;String, character and floating-point literals are no=
 worse than integer literals; and there is no reason to prohibit to pass th=
em into the templates.</div></div><div><br></div><div style=3D"border:1px s=
olid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250=
)"><code><div><span style=3D"color:#008">template</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#008">double</span><span style=3D"c=
olor:#000"> d</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">const</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">char</span><span style=3D"color:#6=
60">*</span><span style=3D"color:#000">s</span><span style=3D"color:#660">&=
gt;</span><span style=3D"color:#000"> <br></span><span style=3D"color:#008"=
>void</span><span style=3D"color:#000"> foo</span><span style=3D"color:#660=
">()</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</span=
><span style=3D"color:#000"><br><br>foo</span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#066">3.14159</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"He=
llo World"</span><span style=3D"color:#660">&gt;</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">();</span><span style=3D"color:#0=
00"><br><br></span></div></code></div><div style=3D"color:rgb(0,0,0);font-f=
amily:Tahoma;text-align:-webkit-auto;font-size:medium"><br><div><span style=
=3D"text-align:-webkit-auto">A more interesting case is the passing of name=
s, expressions and code blocks.&nbsp;In fact, this is more general case. We=
 must introduce keyword or keywords (similar "typename") for describing arb=
itrary AST fragment in template parameter list.&nbsp;For common case, we ca=
n use an existing word "inline":</span></div><div><span style=3D"text-align=
:-webkit-auto"><br></span></div><div><div><div style=3D"border:1px solid rg=
b(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><cod=
e><div><span style=3D"color:#008">template</span><span style=3D"color:#660"=
>&lt;</span><span style=3D"color:#008">inline</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">Expr</span><span style=3D"color:#660=
">&gt;</span><span style=3D"color:#000"><br></span><span style=3D"color:#00=
8">void</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Foo</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=
>&nbsp; &nbsp;</span><span style=3D"color:#008">while</span><span style=3D"=
color:#660">(</span><span style=3D"color:#000">need_execute_loop</span><spa=
n style=3D"color:#660">())</span><span style=3D"color:#000"><br>&nbsp; &nbs=
p; &nbsp;</span><span style=3D"color:#606">Expr</span><span style=3D"color:=
#660">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br><br></span><span style=3D"color:=
#008">int</span><span style=3D"color:#000"> i</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> y</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#606">Foo</s=
pan><span style=3D"color:#660">&lt;{</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">if</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">i</span><span style=3D"color:#660">&gt;</span><sp=
an style=3D"color:#066">0</span><span style=3D"color:#660">)</span><span st=
yle=3D"color:#000"> x</span><span style=3D"color:#660">++;</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">else</span><span style=
=3D"color:#000"> bar</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">y</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">}</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">&gt;();</span></div></code></div>=
<div style=3D"text-align:-webkit-auto"><br></div></div></div></div><div><sp=
an style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;fon=
t-size:medium">It is advisable to come up with separate keywords for identi=
fers, expressions and code blocks&nbsp;(or come up with a mechanism that li=
mits the allowable kinds of parameters, similar concepts).&nbsp;</span></di=
v></div><div><span style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:=
-webkit-auto;font-size:medium"><br></span></div><div><div><div style=3D"col=
or:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium">=
<b>The second extension - templates can be not only classes and functions.<=
/b></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webk=
it-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);font-fam=
ily:Tahoma;text-align:-webkit-auto;font-size:medium">It is obvious that we =
can implement&nbsp;the enum templates and typedef templates.&nbsp;</div></d=
iv></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webk=
it-auto;font-size:medium"><br></div><div style=3D"text-align:-webkit-auto">=
<div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><div st=
yle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-co=
lor:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</span>=
<span style=3D"color:#660">&lt;</span><span style=3D"color:#008">int</span>=
<span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">enum</span>=
<span style=3D"color:#000"> E </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>&nbsp; E1 </span><span style=3D"color:#660">=3D=
</span><span style=3D"color:#000"> N</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"><br>&nbsp; E2<br></span><span style=3D"color:=
#660">};</span><span style=3D"color:#000"><br><br></span><span style=3D"col=
or:#008">template</span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> T</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"> <br></span><span =
style=3D"color:#008">typedef</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#008">const</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">MyClass</span><span style=3D"color:#660">&lt;</span><s=
pan style=3D"color:#000">T</span><span style=3D"color:#660">&gt;&amp;</span=
><span style=3D"color:#000"> &nbsp; </span><span style=3D"color:#606">My</s=
pan><span style=3D"color:#660">=D0=A1</span><span style=3D"color:#606">Ref<=
/span><span style=3D"color:#660">;</span></div></code></div><div style=3D"t=
ext-align:-webkit-auto"><br></div></div><div style=3D"text-align:-webkit-au=
to"><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><di=
v style=3D"text-align:-webkit-auto">Furthermore, I suggest interesting exte=
nsion - Template code blocks. But first, we should consider the concept of =
"inline code blocks".&nbsp;This is a separate proposal.</div><div style=3D"=
text-align:-webkit-auto"><br></div><div style=3D"text-align:-webkit-auto"><=
b>Inline code blocks</b></div><div style=3D"text-align:-webkit-auto">The co=
de block is named declarative construct including an arbitrary code. It is =
like lexical macro from C/C++ preprocessor, but deeply integrated into the =
language; as we remember, the preprocessor is not related to the language: =
it ignores the scope rules and namespaces, and even keywords of C++ - we ca=
n write "#define true false" and&nbsp;it compiles! In fact, preprocessor is=
 dangerous thing.&nbsp;</div><div style=3D"text-align:-webkit-auto"><br></d=
iv><div style=3D"text-align:-webkit-auto">Instead, I propose to introduce a=
 declarative code blocks with the possibility of substitution in any place =
of the program.&nbsp;We can use an existing keyword "inline" or use another=
 keyword.</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font=
-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,0=
,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><div =
style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-=
color:rgb(250,250,250)"><code><div><span style=3D"color:#800">// declare bl=
ock, like struct or class; </span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#008">inline</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#606">MyBlock</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; f=
oo</span><span style=3D"color:#660">();</span><span style=3D"color:#000"><b=
r>&nbsp; bar</span><span style=3D"color:#660">();</span><span style=3D"colo=
r:#000"><br>&nbsp; baz</span><span style=3D"color:#660">();</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br><br></span><span style=3D"color:#800">// some code</spa=
n><span style=3D"color:#000"><br></span><span style=3D"color:#606">MyBlock<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span=
><span style=3D"color:#800">// substitution of AST 'MyBlock' into main AST<=
/span></div></code></div><div style=3D"text-align:-webkit-auto"><br></div><=
/div></div><div style=3D"text-align:-webkit-auto"><div><div style=3D"color:=
rgb(0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto">The=
se blocks differ from the functions that they not called. They substituted =
as inline-functions directly into code.&nbsp;It is assumed that such units =
must be used instead of Macros. Unlike inline functions, it is simply AST f=
ragments.&nbsp;I am faced with the necessity of such constructions&nbsp;in =
embedded programming.&nbsp;Braces allow to do without the dreaded "\" in mu=
ltiline macros.</div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font=
-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,0=
,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><b>Templat=
e code blocks</b></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;fo=
nt-size:medium;text-align:-webkit-auto">Of course, these blocks can be temp=
lates.&nbsp;</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;f=
ont-size:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(=
0,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><d=
iv style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgrou=
nd-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</=
span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">int</=
span><span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#008">inline=
</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyBloc=
k</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>&nbsp; foo</span><span style=3D"color:=
#660">();</span><span style=3D"color:#000"><br>&nbsp; </span><span style=3D=
"color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#008">int</span><span style=3D"color:#000"> i</span><span style=3D"colo=
r:#660">=3D</span><span style=3D"color:#066">0</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"> i</span><span style=3D"color:#660"=
>&lt;</span><span style=3D"color:#000">n</span><span style=3D"color:#660">;=
</span><span style=3D"color:#000"> i</span><span style=3D"color:#660">++)</=
span><span style=3D"color:#000"><br>&nbsp; &nbsp; bar</span><span style=3D"=
color:#660">();</span><span style=3D"color:#000"><br>&nbsp; baz</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><br></span><sp=
an style=3D"color:#800">// some code</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#606">MyBlock</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#066">10</span><span style=3D"color:#660">&g=
t;;</span><span style=3D"color:#000"> </span><span style=3D"color:#800">// =
substitution of AST 'MyBlock' into main AST</span></div></code></div><div s=
tyle=3D"text-align:-webkit-auto"><div><br></div></div></div></div></div></d=
iv><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-=
align:-webkit-auto"><div><span style=3D"text-align:-webkit-auto">These exam=
ples are simple, but I have no doubt that there is plenty of real-world app=
lications of these features.&nbsp;Boost library allows you to do amazing th=
ings, but its code is very complex and non-obvious.&nbsp;This feature is qu=
ite simple, but with great potential.&nbsp;</span></div><div><span style=3D=
"text-align:-webkit-auto"><br></span></div></div></div></div></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 />

------=_Part_253_937603833.1421254111079--
------=_Part_252_163988762.1421254111079--

.


Author: snk_kid <korcan.hussein@googlemail.com>
Date: Wed, 14 Jan 2015 08:56:01 -0800 (PST)
Raw View
------=_Part_189_573090590.1421254561898
Content-Type: multipart/alternative;
 boundary="----=_Part_190_469389335.1421254561898"

------=_Part_190_469389335.1421254561898
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

There's another advantage of focusing efforts on constexprs over templates=
=20
that I forgot to mention, it may lead to a reflection library that could be=
=20
used at both compile-time and run-time with pretty much the same C++ code=
=20
in a very natural way (as in without hacky template metaprogramming=20
solutions that can't be used for run-time reflection/introspection),=20
support user-defined C++ attributes, maybe extend them further in the=20
future them to support syntax extensions.

On Tuesday, January 13, 2015 at 9:26:35 PM UTC, Yuriy Smirnov wrote:
>
> Currently, C++ template is a function or class/struct/union (starting wit=
h=20
> C++14 is also constant, https://isocpp.org/files/papers/N3651.pdf), and=
=20
> template parameters can be types or integer constants. I propose to exten=
d=20
> the set of language constructs that can be templates and template=20
> parameters.
>
> Template is a compile-time construct. We can say that the passing of a=20
> parameter (type or integer constant) to template, you actually do not pas=
s=20
> the type and not a constant, but a fragment of the syntax tree (AST).=20
> Similarly, the code of template is aslo AST fragment with "placeholders",=
=20
> which are are replaced by actual template arguments.
>
> Therefore, I propose to expand the possibilities of templates, bringing=
=20
> them to the possibilities of syntactic macros. To this end, I propose to=
=20
> introduce a few extra features.
>
> 1. allow to pass as template arguments any valid AST nodes, not only the=
=20
> types and integer constants. In particular, the template parameter can be=
:
>
>    - constant strings;=20
>    - floating-point numbers;=20
>    - syntactically correct C++ identifiers
>    - syntactically correct expressions
>    - syntactically correct blocks of code
>   =20
>
> 2. introduce template parameterization not only for the of classes and=20
> functions, but also for some other language constructs.
>
>    - typedefs
>    - enums
>    - named blocks of code (*see below)
>   =20
> Consider the proposal in more detail.
>
> *The first extension -  allow to pass any correct AST as template=20
> arguments. *
> Passing of string and floating-point literals is obvious and arranged as=
=20
> well as the passing of integer literals. String, character and=20
> floating-point literals are no worse than integer literals; and there is =
no=20
> reason to prohibit to pass them into the templates.
>
> template<double d, const char*s>=20
> void foo() { }
>
> foo<3.14159, "Hello World"> ();
>
>
> A more interesting case is the passing of names, expressions and code=20
> blocks. In fact, this is more general case. We must introduce keyword or=
=20
> keywords (similar "typename") for describing arbitrary AST fragment in=20
> template parameter list. For common case, we can use an existing word=20
> "inline":
>
> template<inline Expr>
> void Foo()
> {
>    while(need_execute_loop())
>      Expr;
> }
>
> int i, x, y;
> Foo<{ if(i>0) x++; else bar(y); } >();
>
> It is advisable to come up with separate keywords for identifers,=20
> expressions and code blocks (or come up with a mechanism that limits the=
=20
> allowable kinds of parameters, similar concepts).=20
>
> *The second extension - templates can be not only classes and functions.*
>
> It is obvious that we can implement the enum templates and typedef=20
> templates.=20
>
> template<int N>
> enum E {
>   E1 =3D N,
>   E2
> };
>
> template<typename T>=20
> typedef const MyClass<T>&   My=D0=A1Ref;
>
> Furthermore, I suggest interesting extension - Template code blocks. But=
=20
> first, we should consider the concept of "inline code blocks". This is a=
=20
> separate proposal.
>
> *Inline code blocks*
> The code block is named declarative construct including an arbitrary code=
..=20
> It is like lexical macro from C/C++ preprocessor, but deeply integrated=
=20
> into the language; as we remember, the preprocessor is not related to the=
=20
> language: it ignores the scope rules and namespaces, and even keywords of=
=20
> C++ - we can write "#define true false" and it compiles! In fact,=20
> preprocessor is dangerous thing.=20
>
> Instead, I propose to introduce a declarative code blocks with the=20
> possibility of substitution in any place of the program. We can use an=20
> existing keyword "inline" or use another keyword.
>
> // declare block, like struct or class;=20
> inline MyBlock
> {
>   foo();
>   bar();
>   baz();
> }
>
> // some code
> MyBlock; // substitution of AST 'MyBlock' into main AST
>
> These blocks differ from the functions that they not called. They=20
> substituted as inline-functions directly into code. It is assumed that su=
ch=20
> units must be used instead of Macros. Unlike inline functions, it is simp=
ly=20
> AST fragments. I am faced with the necessity of such constructions in=20
> embedded programming. Braces allow to do without the dreaded "\" in=20
> multiline macros.
>
> *Template code blocks*
> Of course, these blocks can be templates.=20
>
> template<int N>
> inline MyBlock
> {
>   foo();
>   for(int i=3D0; i<n; i++)
>     bar();
>   baz();
> }
>
> // some code
> MyBlock<10>; // substitution of AST 'MyBlock' into main AST
>
> These examples are simple, but I have no doubt that there is plenty of=20
> real-world applications of these features. Boost library allows you to do=
=20
> amazing things, but its code is very complex and non-obvious. This featur=
e=20
> is quite simple, but with great potential.=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_190_469389335.1421254561898
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There's another advantage of focusing efforts on constexpr=
s over templates that I forgot to mention, it may lead to a reflection libr=
ary that could be used at both compile-time and run-time with pretty much t=
he same C++ code in a very natural way (as in without hacky template metapr=
ogramming solutions that can't be used for run-time reflection/introspectio=
n), support user-defined C++ attributes, maybe extend them further in the f=
uture them to support syntax extensions.<br><br>On Tuesday, January 13, 201=
5 at 9:26:35 PM UTC, Yuriy Smirnov wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><span style=3D"text-align:-webkit-auto"><font f=
ace=3D"Tahoma" color=3D"#000000" size=3D"3">Currently, C++ template is a fu=
nction or class/struct/union (starting with C++14 is also constant,&nbsp;<a=
 href=3D"https://isocpp.org/files/papers/N3651.pdf" target=3D"_blank" onmou=
sedown=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fisocpp.=
org%2Ffiles%2Fpapers%2FN3651.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNEPq23vk=
rlAKv5mrQPSMMAzV0HOYA';return true;" onclick=3D"this.href=3D'https://www.go=
ogle.com/url?q\75https%3A%2F%2Fisocpp.org%2Ffiles%2Fpapers%2FN3651.pdf\46sa=
\75D\46sntz\0751\46usg\75AFQjCNEPq23vkrlAKv5mrQPSMMAzV0HOYA';return true;">=
https://isocpp.org/<wbr>files/papers/N3651.pdf</a>), and template&nbsp;para=
meters can be types or integer constants.&nbsp;I propose to extend the set =
of language constructs that can be templates and template parameters.</font=
></span><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webki=
t-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);font-fami=
ly:Tahoma;text-align:-webkit-auto;font-size:medium">Template is a compile-t=
ime construct. We can say that the passing of a parameter (type or integer =
constant) to template, you actually do not pass the type and not a constant=
, but a fragment of the syntax tree (AST). Similarly, the code of template =
is aslo AST fragment with "placeholders", which are&nbsp;are replaced&nbsp;=
by actual template arguments.</div><div style=3D"color:rgb(0,0,0);font-fami=
ly:Tahoma;text-align:-webkit-auto;font-size:medium"><br></div><div style=3D=
"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medi=
um">Therefore, I propose to expand the possibilities of templates, bringing=
 them to the possibilities of syntactic macros.&nbsp;To this end, I propose=
 to introduce a few extra features.</div><div style=3D"text-align:-webkit-a=
uto"><br><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium=
">1. allow to pass as template arguments any valid AST nodes, not only the =
types and integer constants. In particular, the template parameter can be:<=
/div><div><ul><li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-s=
ize:medium;text-align:-webkit-auto">constant strings;&nbsp;</span><br></li>=
<li><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;tex=
t-align:-webkit-auto">floating-point numbers;&nbsp;</span><br></li><li><spa=
n style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-align:=
-webkit-auto">syntactically&nbsp;correct C++ identifiers</span><br></li><li=
><span style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-a=
lign:-webkit-auto">syntactically correct expressions</span><br></li><li><sp=
an style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-align=
:-webkit-auto">syntactically correct&nbsp;blocks of code</span><br></li></u=
l></div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:=
-webkit-auto;font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);fon=
t-family:Tahoma;text-align:-webkit-auto;font-size:medium">2.&nbsp;introduce=
 template&nbsp;parameterization&nbsp;not only for the of classes and functi=
ons, but also for some other language constructs.</div><div style=3D"text-a=
lign:-webkit-auto"><ul><li><span style=3D"color:rgb(0,0,0);font-family:Taho=
ma;font-size:medium;text-align:-webkit-auto">typedefs</span><br></li><li><s=
pan style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-alig=
n:-webkit-auto">enums</span><br></li><li><span style=3D"color:rgb(0,0,0);fo=
nt-family:Tahoma;font-size:medium;text-align:-webkit-auto">named blocks of =
code (*see below)</span><br></li></ul></div><div style=3D"color:rgb(0,0,0);=
font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><span style=3D=
"text-align:-webkit-auto">Consider the proposal in more detail.</span><br><=
/div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-a=
uto;font-size:medium"><span style=3D"text-align:-webkit-auto"><br></span></=
div><div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium=
"><div style=3D"text-align:-webkit-auto"><b>The first extension -&nbsp;&nbs=
p;allow to pass any correct AST&nbsp;as template arguments.&nbsp;</b></div>=
<div style=3D"text-align:-webkit-auto">Passing of string and floating-point=
 literals is&nbsp;obvious and arranged as well as the passing of integer li=
terals.&nbsp;String, character and floating-point literals are no worse tha=
n integer literals; and there is no reason to prohibit to pass them into th=
e templates.</div></div><div><br></div><div style=3D"border:1px solid rgb(1=
87,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><=
div><span style=3D"color:#008">template</span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#008">double</span><span style=3D"color:#000"=
> d</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">const</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#008">char</span><span style=3D"color:#660">*</spa=
n><span style=3D"color:#000">s</span><span style=3D"color:#660">&gt;</span>=
<span style=3D"color:#000"> <br></span><span style=3D"color:#008">void</spa=
n><span style=3D"color:#000"> foo</span><span style=3D"color:#660">()</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">}</span><span sty=
le=3D"color:#000"><br><br>foo</span><span style=3D"color:#660">&lt;</span><=
span style=3D"color:#066">3.14159</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"Hello World"=
</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">();</span><span style=3D"color:#000"><br><b=
r></span></div></code></div><div style=3D"color:rgb(0,0,0);font-family:Taho=
ma;text-align:-webkit-auto;font-size:medium"><br><div><span style=3D"text-a=
lign:-webkit-auto">A more interesting case is the passing of names, express=
ions and code blocks.&nbsp;In fact, this is more general case. We must intr=
oduce keyword or keywords (similar "typename") for describing arbitrary AST=
 fragment in template parameter list.&nbsp;For common case, we can use an e=
xisting word "inline":</span></div><div><span style=3D"text-align:-webkit-a=
uto"><br></span></div><div><div><div style=3D"border:1px solid rgb(187,187,=
187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><sp=
an style=3D"color:#008">template</span><span style=3D"color:#660">&lt;</spa=
n><span style=3D"color:#008">inline</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">Expr</span><span style=3D"color:#660">&gt;</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#008">void</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#606">Foo</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>&nbsp; &n=
bsp;</span><span style=3D"color:#008">while</span><span style=3D"color:#660=
">(</span><span style=3D"color:#000">need_execute_loop</span><span style=3D=
"color:#660">())</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp;<=
/span><span style=3D"color:#606">Expr</span><span style=3D"color:#660">;</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"><br><br></span><span style=3D"color:#008">int<=
/span><span style=3D"color:#000"> i</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> x</span><span style=3D"color:#660">,</span><s=
pan style=3D"color:#000"> y</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#606">Foo</span><span =
style=3D"color:#660">&lt;{</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">if</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">i</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">)</span><span style=3D"c=
olor:#000"> x</span><span style=3D"color:#660">++;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">else</span><span style=3D"color=
:#000"> bar</span><span style=3D"color:#660">(</span><span style=3D"color:#=
000">y</span><span style=3D"color:#660">);</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">&gt;();</span></div></code></div><div style=
=3D"text-align:-webkit-auto"><br></div></div></div></div><div><span style=
=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:m=
edium">It is advisable to come up with separate keywords for identifers, ex=
pressions and code blocks&nbsp;(or come up with a mechanism that limits the=
 allowable kinds of parameters, similar concepts).&nbsp;</span></div></div>=
<div><span style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-=
auto;font-size:medium"><br></span></div><div><div><div style=3D"color:rgb(0=
,0,0);font-family:Tahoma;text-align:-webkit-auto;font-size:medium"><b>The s=
econd extension - templates can be not only classes and functions.</b></div=
><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;=
font-size:medium"><br></div><div style=3D"color:rgb(0,0,0);font-family:Taho=
ma;text-align:-webkit-auto;font-size:medium">It is obvious that we can impl=
ement&nbsp;the enum templates and typedef templates.&nbsp;</div></div></div=
><div style=3D"color:rgb(0,0,0);font-family:Tahoma;text-align:-webkit-auto;=
font-size:medium"><br></div><div style=3D"text-align:-webkit-auto"><div sty=
le=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><div style=3D"b=
order:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(=
250,250,250)"><code><div><span style=3D"color:#008">template</span><span st=
yle=3D"color:#660">&lt;</span><span style=3D"color:#008">int</span><span st=
yle=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#008">enum</span><span st=
yle=3D"color:#000"> E </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>&nbsp; E1 </span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> N</span><span style=3D"color:#660">,</span><span=
 style=3D"color:#000"><br>&nbsp; E2<br></span><span style=3D"color:#660">};=
</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#008"=
>template</span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#008">typename</span><span style=3D"color:#000"> T</span><span style=3D"col=
or:#660">&gt;</span><span style=3D"color:#000"> <br></span><span style=3D"c=
olor:#008">typedef</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">const</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">MyClass</span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#000">T</span><span style=3D"color:#660">&gt;&amp;</span><span st=
yle=3D"color:#000"> &nbsp; </span><span style=3D"color:#606">My</span><span=
 style=3D"color:#660">=D0=A1</span><span style=3D"color:#606">Ref</span><sp=
an style=3D"color:#660">;</span></div></code></div><div style=3D"text-align=
:-webkit-auto"><br></div></div><div style=3D"text-align:-webkit-auto"><div =
style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium"><div style=
=3D"text-align:-webkit-auto">Furthermore, I suggest interesting extension -=
 Template code blocks. But first, we should consider the concept of "inline=
 code blocks".&nbsp;This is a separate proposal.</div><div style=3D"text-al=
ign:-webkit-auto"><br></div><div style=3D"text-align:-webkit-auto"><b>Inlin=
e code blocks</b></div><div style=3D"text-align:-webkit-auto">The code bloc=
k is named declarative construct including an arbitrary code. It is like le=
xical macro from C/C++ preprocessor, but deeply integrated into the languag=
e; as we remember, the preprocessor is not related to the language: it igno=
res the scope rules and namespaces, and even keywords of C++ - we can write=
 "#define true false" and&nbsp;it compiles! In fact, preprocessor is danger=
ous thing.&nbsp;</div><div style=3D"text-align:-webkit-auto"><br></div><div=
 style=3D"text-align:-webkit-auto">Instead, I propose to introduce a declar=
ative code blocks with the possibility of substitution in any place of the =
program.&nbsp;We can use an existing keyword "inline" or use another keywor=
d.</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:m=
edium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,0,0);fon=
t-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><div style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code><div><span style=3D"color:#800">// declare block, =
like struct or class; </span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#008">inline</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#606">MyBlock</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; foo</s=
pan><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>&nb=
sp; bar</span><span style=3D"color:#660">();</span><span style=3D"color:#00=
0"><br>&nbsp; baz</span><span style=3D"color:#660">();</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#660">}</span><span style=3D"c=
olor:#000"><br><br></span><span style=3D"color:#800">// some code</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#606">MyBlock</span=
><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#800">// substitution of AST 'MyBlock' into main AST</span=
></div></code></div><div style=3D"text-align:-webkit-auto"><br></div></div>=
</div><div style=3D"text-align:-webkit-auto"><div><div style=3D"color:rgb(0=
,0,0);font-family:Tahoma;font-size:medium;text-align:-webkit-auto">These bl=
ocks differ from the functions that they not called. They substituted as in=
line-functions directly into code.&nbsp;It is assumed that such units must =
be used instead of Macros. Unlike inline functions, it is simply AST fragme=
nts.&nbsp;I am faced with the necessity of such constructions&nbsp;in embed=
ded programming.&nbsp;Braces allow to do without the dreaded "\" in multili=
ne macros.</div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size=
:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,0,0);f=
ont-family:Tahoma;font-size:medium;text-align:-webkit-auto"><b>Template cod=
e blocks</b></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-si=
ze:medium;text-align:-webkit-auto">Of course, these blocks can be templates=
..&nbsp;</div></div><div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-s=
ize:medium;text-align:-webkit-auto"><br></div><div style=3D"color:rgb(0,0,0=
);font-family:Tahoma;font-size:medium;text-align:-webkit-auto"><div><div st=
yle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-co=
lor:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</span>=
<span style=3D"color:#660">&lt;</span><span style=3D"color:#008">int</span>=
<span style=3D"color:#000"> N</span><span style=3D"color:#660">&gt;</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#008">inline</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">MyBlock</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br>&nbsp; foo</span><span style=3D"color:#660"=
>();</span><span style=3D"color:#000"><br>&nbsp; </span><span style=3D"colo=
r:#008">for</span><span style=3D"color:#660">(</span><span style=3D"color:#=
008">int</span><span style=3D"color:#000"> i</span><span style=3D"color:#66=
0">=3D</span><span style=3D"color:#066">0</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"> i</span><span style=3D"color:#660">&lt;=
</span><span style=3D"color:#000">n</span><span style=3D"color:#660">;</spa=
n><span style=3D"color:#000"> i</span><span style=3D"color:#660">++)</span>=
<span style=3D"color:#000"><br>&nbsp; &nbsp; bar</span><span style=3D"color=
:#660">();</span><span style=3D"color:#000"><br>&nbsp; baz</span><span styl=
e=3D"color:#660">();</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span st=
yle=3D"color:#800">// some code</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#606">MyBlock</span><span style=3D"color:#660">&lt;</=
span><span style=3D"color:#066">10</span><span style=3D"color:#660">&gt;;</=
span><span style=3D"color:#000"> </span><span style=3D"color:#800">// subst=
itution of AST 'MyBlock' into main AST</span></div></code></div><div style=
=3D"text-align:-webkit-auto"><div><br></div></div></div></div></div></div><=
div style=3D"color:rgb(0,0,0);font-family:Tahoma;font-size:medium;text-alig=
n:-webkit-auto"><div><span style=3D"text-align:-webkit-auto">These examples=
 are simple, but I have no doubt that there is plenty of real-world applica=
tions of these features.&nbsp;Boost library allows you to do amazing things=
, but its code is very complex and non-obvious.&nbsp;This feature is quite =
simple, but with great potential.&nbsp;</span></div><div><span style=3D"tex=
t-align:-webkit-auto"><br></span></div></div></div></div></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 />

------=_Part_190_469389335.1421254561898--
------=_Part_189_573090590.1421254561898--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 14 Jan 2015 19:54:49 +0100
Raw View
Le 14/01/15 17:48, snk_kid a =C3=A9crit :
> Extending/modifying templates for this is really bad idea, a much=20
> better idea would be to support this with via constexpr functions and=20
> few new language additions as some of us as have been discussing before:
>
> https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-propo=
sals/MblNbx7xc94
>
> Please lets stop making templates even more complicated than they=20
> already are just for the sake of meta-programming. Templates were=20
> never designed for meta-programming and it completely shows, they are=20
> severally limited compared to proper meta-programming support, the=20
> meta-language is different from the object language which makes them=20
> hard to use & maintain by the 99%.
>
> I believe constexpr functions are the best place to extend/add proper=20
> meta-programming facilitates to C++ and the meta-language and object=20
> language are the same which is much better for the average C++ for=20
> readability/maintainability.

Maybe you are right, but I don't see why you want someone else stops=20
proposing things that you are locking for.  The form is not so=20
important. What is important is the feature and as you said "the hardest=20
and biggest part of adding this is not the language additions part but=20
actually standardizing a library for the abstract-syntax tree".

Good luck to both,
Vicente


--=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: NeoCode <neoprogramming@gmail.com>
Date: Wed, 7 Oct 2015 05:49:55 -0700 (PDT)
Raw View
------=_Part_4052_109579173.1444222195171
Content-Type: multipart/alternative;
 boundary="----=_Part_4053_425393494.1444222195180"

------=_Part_4053_425393494.1444222195180
Content-Type: text/plain; charset=UTF-8

Let's get back to this topic.

My proposal is not about metaprogamming in the sense of "compile-time code
execution" (like constexpr functions).* It is more relevant to the original
application of templates - writing generic code.*
I can create template function or class, parameterized by an integer. Why I
can't create template function or class, parameterized by an float or
string? This is illogical. Floats and strings are the same compile-time
constants as integers. Now programmers use various hacks to transfer floats
and strings into function templates... it's bad.

I proposed to generalize this conception to an arbitrary blocks of code.
Why? Arbitrary correct block of code is generalization of "compile-time
object". It's may be type, integer constant, floating-point constant,
character or string; all of this is special cases of "syntax subtree".
Correct block of code is common case of "syntax subtree". It's may be
expression, statement block, part of class declaration, part of enum
declaration, declaration of variables or constants and so on. We get a
simple and intuitive way to construct arbitrary code (as opposed to the
modern C++ template metaprogramming). Also, this proposal allows us almost
completely abandon the preprocessor macros. In fact, *it is safe and
follows the rules of scope analogue of preprocessor macros*.

My proposal does not contradict the generalization of "constexpr", and
solve other problems.

--

---
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_4053_425393494.1444222195180
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Let&#39;s get back to this topic.<div><br></div><div>My pr=
oposal is not about metaprogamming in the sense of &quot;compile-time code =
execution&quot; (like constexpr functions).<b> It is more relevant to the o=
riginal application of templates - writing generic code.</b>=C2=A0</div><di=
v>I can create template function or class,=C2=A0parameterized by an integer=
.. Why I can&#39;t create template function or class,=C2=A0parameterized by =
an float or string? This is illogical. Floats and strings are the same comp=
ile-time constants as integers. Now programmers use various hacks to transf=
er floats and strings into function templates... it&#39;s bad.</div><div><b=
r></div><div>I proposed to generalize this conception to an arbitrary block=
s of code. Why? Arbitrary correct block of code is generalization of &quot;=
compile-time object&quot;. It&#39;s may be type, integer constant, floating=
-point constant, character or string; all of this is=C2=A0special cases of =
&quot;syntax subtree&quot;. Correct block of code is common case of=C2=A0&q=
uot;syntax subtree&quot;. It&#39;s may be expression, statement block, part=
 of class declaration, part of enum declaration, declaration of variables o=
r constants and so on.=C2=A0We get a simple and intuitive way to construct =
arbitrary code (as opposed to the modern C++ template metaprogramming). Als=
o, this proposal allows us=C2=A0almost completely abandon the preprocessor =
macros. In fact, <b>it is safe and follows the rules of scope analogue of p=
reprocessor macros</b>.</div><div><br></div><div>My proposal does not contr=
adict the generalization of &quot;constexpr&quot;,=C2=A0and solve other pro=
blems.=C2=A0<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&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_4053_425393494.1444222195180--
------=_Part_4052_109579173.1444222195171--

.


Author: inkwizytoryankes@gmail.com
Date: Wed, 7 Oct 2015 08:45:34 -0700 (PDT)
Raw View
------=_Part_581_1031519868.1444232735048
Content-Type: multipart/alternative;
 boundary="----=_Part_582_1792046648.1444232735049"

------=_Part_582_1792046648.1444232735049
Content-Type: text/plain; charset=UTF-8



On Wednesday, October 7, 2015 at 2:49:55 PM UTC+2, NeoCode wrote:
>
> Let's get back to this topic.
>
> My proposal is not about metaprogamming in the sense of "compile-time code
> execution" (like constexpr functions).* It is more relevant to the
> original application of templates - writing generic code.*
> I can create template function or class, parameterized by an integer. Why
> I can't create template function or class, parameterized by an float or
> string? This is illogical. Floats and strings are the same compile-time
> constants as integers. Now programmers use various hacks to transfer floats
> and strings into function templates... it's bad.
>
> I proposed to generalize this conception to an arbitrary blocks of code.
> Why? Arbitrary correct block of code is generalization of "compile-time
> object". It's may be type, integer constant, floating-point constant,
> character or string; all of this is special cases of "syntax subtree".
> Correct block of code is common case of "syntax subtree". It's may be
> expression, statement block, part of class declaration, part of enum
> declaration, declaration of variables or constants and so on. We get a
> simple and intuitive way to construct arbitrary code (as opposed to the
> modern C++ template metaprogramming). Also, this proposal allows us almost
> completely abandon the preprocessor macros. In fact, *it is safe and
> follows the rules of scope analogue of preprocessor macros*.
>
> My proposal does not contradict the generalization of "constexpr", and
> solve other problems.
>

Your first extension is already impossible (or very hard to do). Consider
simple example:
template<double x> void foo();
template<const char* s> void bar();

foo<5.0 * 0.2>();
foo<1.0>(); //same function as previous one?
foo<0.999999999999999999999999999999999999999999999999>(); //again?
foo<5.0f * 0.2f>();

//one translation unit
bar<"A">();
//another translation unit
bar<"A">(); //different function because address is different
Whole template and type system rely on equality, if you add things that are
hard do compare whole system will fall.

--

---
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_582_1792046648.1444232735049
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><br>On Wednesday, October 7, 2015 at 2:49:55 PM UTC+2, NeoCode wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Let&#39;s get b=
ack to this topic.<div><br></div><div>My proposal is not about metaprogammi=
ng in the sense of &quot;compile-time code execution&quot; (like constexpr =
functions).<b> It is more relevant to the original application of templates=
 - writing generic code.</b>=C2=A0</div><div>I can create template function=
 or class,=C2=A0parameterized by an integer. Why I can&#39;t create templat=
e function or class,=C2=A0parameterized by an float or string? This is illo=
gical. Floats and strings are the same compile-time constants as integers. =
Now programmers use various hacks to transfer floats and strings into funct=
ion templates... it&#39;s bad.</div><div><br></div><div>I proposed to gener=
alize this conception to an arbitrary blocks of code. Why? Arbitrary correc=
t block of code is generalization of &quot;compile-time object&quot;. It&#3=
9;s may be type, integer constant, floating-point constant, character or st=
ring; all of this is=C2=A0special cases of &quot;syntax subtree&quot;. Corr=
ect block of code is common case of=C2=A0&quot;syntax subtree&quot;. It&#39=
;s may be expression, statement block, part of class declaration, part of e=
num declaration, declaration of variables or constants and so on.=C2=A0We g=
et a simple and intuitive way to construct arbitrary code (as opposed to th=
e modern C++ template metaprogramming). Also, this proposal allows us=C2=A0=
almost completely abandon the preprocessor macros. In fact, <b>it is safe a=
nd follows the rules of scope analogue of preprocessor macros</b>.</div><di=
v><br></div><div>My proposal does not contradict the generalization of &quo=
t;constexpr&quot;,=C2=A0and solve other problems.=C2=A0<br></div></div></bl=
ockquote><div><br>Your first extension is already impossible (or very hard =
to do). Consider simple example:<br><div class=3D"prettyprint" style=3D"bac=
kground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border=
-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">double</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> x</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><spa=
n 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: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">char</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> bar</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br><br>foo</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">5.0</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">0.=
2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>foo</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n style=3D"color: #066;" class=3D"styled-by-prettify">1.0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">//same function as previous one?</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>foo</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">0.9999999999999999999999999=
99999999999999999999999</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&gt;();</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify"=
>//again?</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
code class=3D"prettyprint"><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>foo</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span><span style=3D"color: #066;" class=3D"styled-by-prettify"=
>5.0f</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><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: #066;" class=3D"styled-by-prettify">0.2f</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&gt;();</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span></code><br></span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">//one translation unit</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>bar</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span st=
yle=3D"color: #080;" class=3D"styled-by-prettify">&quot;A&quot;</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">//another translation unit</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>bar</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span s=
tyle=3D"color: #080;" class=3D"styled-by-prettify">&quot;A&quot;</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">//different function because addr=
ess is different</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span></div></code></div>Whole template and type system rely on =
equality, if you add things that are hard do compare whole system will fall=
..<br><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&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_582_1792046648.1444232735049--
------=_Part_581_1031519868.1444232735048--

.


Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Thu, 8 Oct 2015 09:49:35 +0200
Raw View
On Wed, Oct 07, 2015 at 08:45:34AM -0700, inkwizytoryankes@gmail.com wrote:
>
>
> On Wednesday, October 7, 2015 at 2:49:55 PM UTC+2, NeoCode wrote:
> >
> > Let's get back to this topic.
> >
> > My proposal is not about metaprogamming in the sense of "compile-time code
> > execution" (like constexpr functions).* It is more relevant to the
> > original application of templates - writing generic code.*
> > I can create template function or class, parameterized by an integer. Why
> > I can't create template function or class, parameterized by an float or
> > string? This is illogical. Floats and strings are the same compile-time
> > constants as integers. Now programmers use various hacks to transfer floats
> > and strings into function templates... it's bad.
> >
> > I proposed to generalize this conception to an arbitrary blocks of code.
> > Why? Arbitrary correct block of code is generalization of "compile-time
> > object". It's may be type, integer constant, floating-point constant,
> > character or string; all of this is special cases of "syntax subtree".
> > Correct block of code is common case of "syntax subtree". It's may be
> > expression, statement block, part of class declaration, part of enum
> > declaration, declaration of variables or constants and so on. We get a
> > simple and intuitive way to construct arbitrary code (as opposed to the
> > modern C++ template metaprogramming). Also, this proposal allows us almost
> > completely abandon the preprocessor macros. In fact, *it is safe and
> > follows the rules of scope analogue of preprocessor macros*.
> >
> > My proposal does not contradict the generalization of "constexpr", and
> > solve other problems.
> >
>
> Your first extension is already impossible (or very hard to do). Consider
> simple example:
> template<double x> void foo();
> template<const char* s> void bar();
>
> foo<5.0 * 0.2>();
> foo<1.0>(); //same function as previous one?
> foo<0.999999999999999999999999999999999999999999999999>(); //again?
> foo<5.0f * 0.2f>();
>
> //one translation unit
> bar<"A">();
> //another translation unit
> bar<"A">(); //different function because address is different
> Whole template and type system rely on equality, if you add things that are
> hard do compare whole system will fall.

The problem with C arrays as template arguments is that the compiler converts
them to pointers at the drop of a hat.

What if array operations are allowed on T[] template arguments but the
conversion of them to pointers doesn't happen in template evaluation scope?

/MF

--

---
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: inkwizytoryankes@gmail.com
Date: Thu, 8 Oct 2015 05:33:27 -0700 (PDT)
Raw View
------=_Part_329_1255164899.1444307607937
Content-Type: multipart/alternative;
 boundary="----=_Part_330_341498115.1444307607937"

------=_Part_330_341498115.1444307607937
Content-Type: text/plain; charset=UTF-8



On Thursday, October 8, 2015 at 9:49:39 AM UTC+2, Magnus Fromreide wrote:
>
> On Wed, Oct 07, 2015 at 08:45:34AM -0700, inkwizyt...@gmail.com
> <javascript:> wrote:
> >
> >
> > On Wednesday, October 7, 2015 at 2:49:55 PM UTC+2, NeoCode wrote:
> > >
> > > Let's get back to this topic.
> > >
> > > My proposal is not about metaprogamming in the sense of "compile-time
> code
> > > execution" (like constexpr functions).* It is more relevant to the
> > > original application of templates - writing generic code.*
> > > I can create template function or class, parameterized by an integer.
> Why
> > > I can't create template function or class, parameterized by an float
> or
> > > string? This is illogical. Floats and strings are the same
> compile-time
> > > constants as integers. Now programmers use various hacks to transfer
> floats
> > > and strings into function templates... it's bad.
> > >
> > > I proposed to generalize this conception to an arbitrary blocks of
> code.
> > > Why? Arbitrary correct block of code is generalization of
> "compile-time
> > > object". It's may be type, integer constant, floating-point constant,
> > > character or string; all of this is special cases of "syntax subtree".
> > > Correct block of code is common case of "syntax subtree". It's may be
> > > expression, statement block, part of class declaration, part of enum
> > > declaration, declaration of variables or constants and so on. We get a
> > > simple and intuitive way to construct arbitrary code (as opposed to
> the
> > > modern C++ template metaprogramming). Also, this proposal allows us
> almost
> > > completely abandon the preprocessor macros. In fact, *it is safe and
> > > follows the rules of scope analogue of preprocessor macros*.
> > >
> > > My proposal does not contradict the generalization of "constexpr", and
> > > solve other problems.
> > >
> >
> > Your first extension is already impossible (or very hard to do).
> Consider
> > simple example:
> > template<double x> void foo();
> > template<const char* s> void bar();
> >
> > foo<5.0 * 0.2>();
> > foo<1.0>(); //same function as previous one?
> > foo<0.999999999999999999999999999999999999999999999999>(); //again?
> > foo<5.0f * 0.2f>();
> >
> > //one translation unit
> > bar<"A">();
> > //another translation unit
> > bar<"A">(); //different function because address is different
> > Whole template and type system rely on equality, if you add things that
> are
> > hard do compare whole system will fall.
>
> The problem with C arrays as template arguments is that the compiler
> converts
> them to pointers at the drop of a hat.
>
> What if array operations are allowed on T[] template arguments but the
> conversion of them to pointers doesn't happen in template evaluation
> scope?
>
> /MF
>

This would fix that problem but I still doubt that committee will allow
this. We were very close to having some thing like that with UDL:
decltype("test"_test) === some_type<char, 't', 'e', 's', 't'>
This work as extension in gcc ( http://goo.gl/zHpMRf ), but in standard is
not allowed (it only work with numbers).
I don't remember exactly why it was not included.


--

---
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_330_341498115.1444307607937
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<br><br>On Thursday, October 8, 2015 at 9:49:39 AM UTC+2, Magnus Fromreide =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Wed, Oct 07, 2015 at =
08:45:34AM -0700, <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"sSjNbHarDAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;ja=
vascript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;r=
eturn true;">inkwizyt...@gmail.com</a> wrote:
<br>&gt;=20
<br>&gt;=20
<br>&gt; On Wednesday, October 7, 2015 at 2:49:55 PM UTC+2, NeoCode wrote:
<br>&gt; &gt;
<br>&gt; &gt; Let&#39;s get back to this topic.
<br>&gt; &gt;
<br>&gt; &gt; My proposal is not about metaprogamming in the sense of &quot=
;compile-time code=20
<br>&gt; &gt; execution&quot; (like constexpr functions).* It is more relev=
ant to the=20
<br>&gt; &gt; original application of templates - writing generic code.*=20
<br>&gt; &gt; I can create template function or class, parameterized by an =
integer. Why=20
<br>&gt; &gt; I can&#39;t create template function or class, parameterized =
by an float or=20
<br>&gt; &gt; string? This is illogical. Floats and strings are the same co=
mpile-time=20
<br>&gt; &gt; constants as integers. Now programmers use various hacks to t=
ransfer floats=20
<br>&gt; &gt; and strings into function templates... it&#39;s bad.
<br>&gt; &gt;
<br>&gt; &gt; I proposed to generalize this conception to an arbitrary bloc=
ks of code.=20
<br>&gt; &gt; Why? Arbitrary correct block of code is generalization of &qu=
ot;compile-time=20
<br>&gt; &gt; object&quot;. It&#39;s may be type, integer constant, floatin=
g-point constant,=20
<br>&gt; &gt; character or string; all of this is special cases of &quot;sy=
ntax subtree&quot;.=20
<br>&gt; &gt; Correct block of code is common case of &quot;syntax subtree&=
quot;. It&#39;s may be=20
<br>&gt; &gt; expression, statement block, part of class declaration, part =
of enum=20
<br>&gt; &gt; declaration, declaration of variables or constants and so on.=
 We get a=20
<br>&gt; &gt; simple and intuitive way to construct arbitrary code (as oppo=
sed to the=20
<br>&gt; &gt; modern C++ template metaprogramming). Also, this proposal all=
ows us almost=20
<br>&gt; &gt; completely abandon the preprocessor macros. In fact, *it is s=
afe and=20
<br>&gt; &gt; follows the rules of scope analogue of preprocessor macros*.
<br>&gt; &gt;
<br>&gt; &gt; My proposal does not contradict the generalization of &quot;c=
onstexpr&quot;, and=20
<br>&gt; &gt; solve other problems.=20
<br>&gt; &gt;
<br>&gt;=20
<br>&gt; Your first extension is already impossible (or very hard to do). C=
onsider=20
<br>&gt; simple example:
<br>&gt; template&lt;double x&gt; void foo();
<br>&gt; template&lt;const char* s&gt; void bar();
<br>&gt;=20
<br>&gt; foo&lt;5.0 * 0.2&gt;();
<br>&gt; foo&lt;1.0&gt;(); //same function as previous one?
<br>&gt; foo&lt;0.<wbr>999999999999999999999999999999<wbr>99999999999999999=
9&gt;(); //again?
<br>&gt; foo&lt;5.0f * 0.2f&gt;();
<br>&gt;=20
<br>&gt; //one translation unit
<br>&gt; bar&lt;&quot;A&quot;&gt;();
<br>&gt; //another translation unit
<br>&gt; bar&lt;&quot;A&quot;&gt;(); //different function because address i=
s different
<br>&gt; Whole template and type system rely on equality, if you add things=
 that are=20
<br>&gt; hard do compare whole system will fall.
<br>
<br>The problem with C arrays as template arguments is that the compiler co=
nverts
<br>them to pointers at the drop of a hat.
<br>
<br>What if array operations are allowed on T[] template arguments but the
<br>conversion of them to pointers doesn&#39;t happen in template evaluatio=
n scope?
<br>
<br>/MF
<br></blockquote><div><br>This would fix that problem but I still doubt tha=
t committee will allow this. We were very close to having some thing like t=
hat with UDL:<br><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">decltype</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&quot;=
test&quot;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
_test</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> some_type</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">char</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: #080;" class=
=3D"styled-by-prettify">&#39;t&#39;</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify">&#39;e&#39;</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&#39;s&#39=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #080;" class=3D"styled-by-prettify">&#39;t&#39;</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div>Th=
is work as extension in gcc ( http://goo.gl/zHpMRf ), but in standard is no=
t allowed (it only work with numbers).<br>I don&#39;t remember exactly why =
it was not included.<br><br><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&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_330_341498115.1444307607937--
------=_Part_329_1255164899.1444307607937--

.