Topic: Template expressions
Author: =?UTF-8?Q?Andr=C3=A9?= <andre.francisco@tryhype.co>
Date: Sun, 7 Feb 2016 15:16:43 -0800 (PST)
Raw View
------=_Part_734_73860117.1454887003838
Content-Type: multipart/alternative;
boundary="----=_Part_735_980782034.1454887003839"
------=_Part_735_980782034.1454887003839
Content-Type: text/plain; charset=UTF-8
Hello,
The term expression template
<https://en.wikipedia.org/wiki/Expression_templates> has been coined to
mean the use of templates for computations at compile time, but that's not
to be confused with *template expressions*, the topic I'm bringing to
discussion. As these two terms can be confused, I've also considered *inline
template expressions* as an alternative.
The idea comes from scoping exceptions, although it can be relaxed to mean
other stuff. Lets start by analysing this code:
class custom_exception
: public std::exception
{ /* whatever */ };
class Foo
{
public:
void foo()
{
throw custom_exception();
}
};
This is pretty standard, not fancy at all. A paradigm that I use often and borrowed
from python's django
<https://docs.djangoproject.com/es/1.9/ref/models/instances/#django.db.models.Model.DoesNotExist> is
to inline the exception in the class definition, like this:
class Foo
{
public:
class custom_exception : public std::exception { /* ... */ }
void foo()
{
throw custom_exception();
}
};
Why does this help? For starters it helps preventing the pollution of the
namespace where the exception is being defined. Instead, the exception is
referred to as Foo::custom_exception, which allows to have
Bar::custom_exception (the same name) meaning something different.
Secondly, it allows to catch exceptions with respect to the class they are
inserted in, such as the following:
try {
/* Code that might throw */
}
catch (Foo::custom_exception & ex) {}
catch (Bar::custom_exception & ex) {}
These two exceptions may or may not be related. If they are, a common base
class can also be used for a "catch all in category" approach. This also
works with templates:
template <class T>
class Foo
{
public:
class custom_exception : public std::exception { /* ... */ }
};
Each Foo template instantiation also results in a different instance of
custom exception, so this is possible:
try {
/* Code that might throw */
}
catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int
instances of Foo */ }
catch (Foo<float>::custom_exception & ex) { /* Handle exceptions for float
instances of Foo */ }
This is useful, but it's not possible to follow the same "catch all in
category" approach, which would catch all exceptions of type
Foo<T>::custom_exception, regardless of T. Again, this could be solved by
making them share the same base class, declared outside the class
definition, probably in some namespace (say, ::std). This obviously defeats
the purpose of not polluting the namespace. This is why I though of
something like this:
try {
/* Code that might throw */
}
catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int
instances of Foo */ }
catch (template <class T> Foo<T>::custom_exception & ex) { /* Handle
exceptions for all other instances of Foo */ }
I believe this could be trivially implemented by the compiler: when a
template expression of this kind is found it generates a base class for all
instances of Foo<T>::custom_exception and replaces the catch expression
with the base class. This does not pollute the namespace and allows
defining something like this in a trivial manner, instead of going through
the hassle of having to define a custom base class.
To be honest, I haven't given much though to how this would be useful in
other situations, but maybe you guys can help with that. Does something
like this exist? Do you think it could be useful?
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_735_980782034.1454887003839
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello,<div><br></div><div>The term=C2=A0<a href=3D"https:/=
/en.wikipedia.org/wiki/Expression_templates">expression template</a>=C2=A0h=
as been coined to mean the use of templates for computations at compile tim=
e, but that's not to be confused with <i>template expressions</i>, the =
topic I'm bringing to discussion. As these two terms can be confused, I=
've also considered <i>inline template expressions</i>=C2=A0as an alter=
native.</div><div><br></div><div>The idea comes from scoping exceptions, al=
though it can be relaxed to mean other stuff. Lets start by analysing this =
code:</div><div><br></div><div><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">class</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> custom_exception <br>=
=C2=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">public</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">exception <br></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: #800;" =
class=3D"styled-by-prettify">/* whatever */</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">=
Foo</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">throw</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> custom_exception</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">};</span></div></code></div><br>This is pretty s=
tandard, not fancy at all. A paradigm that I use often and <a href=3D"https=
://docs.djangoproject.com/es/1.9/ref/models/instances/#django.db.models.Mod=
el.DoesNotExist">borrowed from python's django</a>=C2=A0is to inline th=
e exception in the class definition, like this:</div><div><br></div><div><d=
iv class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); wor=
d-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><font color=3D"#660066"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">class</span><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: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">public</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> custom_exception </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">public<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">exception </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">/* ... */</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br>=C2=A0 =C2=A0 </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"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">throw</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> custom_exception</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </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"st=
yled-by-prettify">};</span></font></div></code></div><br>Why does this help=
? For starters it helps preventing the pollution of the namespace where the=
exception is being defined. Instead, the exception is referred to as Foo::=
custom_exception, which allows to have Bar::custom_exception (the same name=
) meaning something different. Secondly, it allows to catch exceptions with=
respect to the class they are inserted in, such as the following:</div><di=
v><br></div><div><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">try</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">/* Code that might throw */</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;" c=
lass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">catch</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">Foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><font color=3D"#000000"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">custom_exception </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> ex</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: #660;" class=3D"styled-by-prettify">{}</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">catch</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: #606;" =
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"styl=
ed-by-prettify">custom_exception </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> ex</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{}</sp=
an></font></div></code></div><br>These two exceptions may or may not be rel=
ated. If they are, a common base class can also be used for a "catch a=
ll in category" approach. This also works with templates:</div><div><b=
r></div><div><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"col=
or: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
lass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</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></span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">public</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> custom_exception </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">public</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">ex=
ception </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: #800;" class=3D"styled-by-prettify">/* ... */</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">};</span></div></code></div><br>Each Foo te=
mplate instantiation also results in a different instance of custom excepti=
on, so this is possible:</div><div><br></div><div><div class=3D"prettyprint=
" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; bac=
kground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><font color=3D"#660066"><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">try</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-p=
rettify">/* Code that might throw */</span><span style=3D"color: #000;" cla=
ss=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"color: #008;" class=3D"styled-by-p=
rettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><spa=
n style=3D"color: #080;" class=3D"styled-by-prettify"><int></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">custom_exception </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> ex</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">/* Handle exceptions for int instances of Foo */</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;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">catch</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify"><float&=
gt;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">custom_exceptio=
n </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> ex</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">/* Handle exceptions for float instances of Foo */</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span></font></div></c=
ode></div><br>This is useful, but it's not possible to follow the same =
"catch all in category" approach, which would catch all exception=
s of type Foo<T>::custom_exception, regardless of T. Again, this coul=
d be solved by making them share the same base class, declared outside the =
class definition, probably in some namespace (say, ::std). This obviously d=
efeats the purpose of not polluting the namespace. This is why I though of =
something like this:</div><div><br></div><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"><font color=3D"#660066"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">try</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">/* Code that might throw */</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">catch</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: #606;" class=3D"styled-by-prettify">Foo</span><span =
style=3D"color: #080;" class=3D"styled-by-prettify"><int></span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">custom_exception </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> ex</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">/* Handle exceptions for int instances of Foo */</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;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">catch</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">class</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">></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>custom_exception </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> ex</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">/* Handle exceptions for all other insta=
nces of Foo */</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></f=
ont></div></code></div><div><br></div><div>I believe this could be triviall=
y implemented by the compiler: when a template expression of this kind is f=
ound it generates a base class for all instances of Foo<T>::custom_ex=
ception and replaces the catch expression with the base class. This does no=
t pollute the namespace and allows defining something like this in a trivia=
l manner, instead of going through the hassle of having to define a custom =
base class.</div><div><br></div>To be honest, I haven't given much thou=
gh to how this would be useful in other situations, but maybe you guys can =
help with that. Does something like this exist? Do you think it could be us=
eful?<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_735_980782034.1454887003839--
------=_Part_734_73860117.1454887003838--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Sun, 07 Feb 2016 18:24:33 -0500
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
255, 255); line-height: initial;"> =
<div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">> <span style=3D"line-height: initial;">when a template=
expression of this kind is found it generates a base class for all instanc=
es of Foo<T>::custom_exception and replaces the catch expression with=
the base class.</span><span style=3D"line-height: initial;"> </span><=
/div><div style=3D"width: 100%; font-size: initial; font-family: Calibri, '=
Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: in=
itial; background-color: rgb(255, 255, 255);"><span style=3D"line-height: i=
nitial;"><br></span></div><div style=3D"width: 100%; font-size: initial; fo=
nt-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73,=
125); text-align: initial; background-color: rgb(255, 255, 255);"><span st=
yle=3D"line-height: initial;">OK that's not going to work. You can't sudden=
ly decide that some class now has a base class, which wasn't mentioned in t=
he class definition. </span></div><div style=3D"width: 100%; font-size=
: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color=
: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 25=
5);"><span style=3D"line-height: initial;"><br></span></div><div style=3D"w=
idth: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-ser=
if, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-co=
lor: rgb(255, 255, 255);"><span style=3D"line-height: initial;">If you had =
said that the compiler would generate some magic catch clause=E2=80=8E(s) t=
hat match any instances of the template, then maybe. </span></div><div=
style=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro=
', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; ba=
ckground-color: rgb(255, 255, 255);"><span style=3D"line-height: initial;">=
<br></span></div><div style=3D"width: 100%; font-size: initial; font-family=
: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); te=
xt-align: initial; background-color: rgb(255, 255, 255);"><span style=3D"li=
ne-height: initial;">The general concept that you are looking for, I think,=
is 'pattern matching'. You want to catch anything that matches the pattern=
.. </span></div><div style=3D"width: 100%; font-size: initial; font-fam=
ily: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125);=
text-align: initial; background-color: rgb(255, 255, 255);"><span style=3D=
"line-height: initial;"><br></span></div><div style=3D"width: 100%; font-si=
ze: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; col=
or: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, =
255);"><span style=3D"line-height: initial;">You could imagine also wanting=
something similar in switch case statements. And in fact there are proposa=
ls along that line, including one by Stroustrup. </span></div><div sty=
le=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', s=
ans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backgr=
ound-color: rgb(255, 255, 255);"><span style=3D"line-height: initial;"><br>=
</span></div><div style=3D"width: 100%; font-size: initial; font-family: Ca=
libri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-a=
lign: initial; background-color: rgb(255, 255, 255);"><span style=3D"line-h=
eight: initial;"><br></span></div><div style=3D"width: 100%; font-size: ini=
tial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb=
(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">=
<br></div> =
<div st=
yle=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', =
sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backg=
round-color: rgb(255, 255, 255);"><br style=3D"display:initial"></div> =
=
=
<div style=3D"font-size: initial; f=
ont-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73=
, 125); text-align: initial; background-color: rgb(255, 255, 255);">Sent&nb=
sp;from my BlackBerry portable Babbage Device</div=
> =
=
<table width=3D"100%" style=3D"background-colo=
r:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" style=3D"font-si=
ze: initial; text-align: initial; background-color: rgb(255, 255, 255);"> =
<div style=3D"border-style: solid none none; borde=
r-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0i=
n; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt;"> <=
div><b>From: </b>Andr=C3=A9</div><div><b>Sent: </b>Sunday, February 7, 2016=
6:16 PM</div><div><b>To: </b>ISO C++ Standard - Future Proposals</div><div=
><b>Reply To: </b>std-proposals@isocpp.org</div><div><b>Subject: </b>[std-p=
roposals] Template expressions</div></div></td></tr></tbody></table><div st=
yle=3D"border-style: solid none none; border-top-color: rgb(186, 188, 209);=
border-top-width: 1pt; font-size: initial; text-align: initial; background=
-color: rgb(255, 255, 255);"></div><br><div id=3D"_originalContent" style=
=3D""><div dir=3D"ltr">Hello,<div><br></div><div>The term <a href=3D"h=
ttps://en.wikipedia.org/wiki/Expression_templates">expression template</a>&=
nbsp;has been coined to mean the use of templates for computations at compi=
le time, but that's not to be confused with <i>template expressions</i>, th=
e topic I'm bringing to discussion. As these two terms can be confused, I'v=
e also considered <i>inline template expressions</i> as an alternative=
..</div><div><br></div><div>The idea comes from scoping exceptions, although=
it can be relaxed to mean other stuff. Lets start by analysing this code:<=
/div><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1px so=
lid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 2=
50, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span =
style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> custom_exception <br> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">public</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">exception <br></span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">/* whatever */</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-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-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</=
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 styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">public</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"col=
or: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">throw</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> custom_exception</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">};</span></div></code></div><br>This is pretty standard=
, not fancy at all. A paradigm that I use often and <a href=3D"https://docs=
..djangoproject.com/es/1.9/ref/models/instances/#django.db.models.Model.Does=
NotExist">borrowed from python's django</a> is to inline the exception=
in the class definition, like this:</div><div><br></div><div><div class=3D=
"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: bre=
ak-word; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"=
><div class=3D"subprettyprint"><font color=3D"#660066"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Foo</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">publ=
ic</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br> &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">class=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> custom_ex=
ception </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: #008;" class=3D"styled-by-prettify">public</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">exception </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: #800;" class=3D=
"styled-by-prettify">/* ... */</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br> </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; </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; </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">throw</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> custom_exception</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> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">};</span></font></div></code></div><br>Why does this help? For starters i=
t helps preventing the pollution of the namespace where the exception is be=
ing defined. Instead, the exception is referred to as Foo::custom_exception=
, which allows to have Bar::custom_exception (the same name) meaning someth=
ing different. Secondly, it allows to catch exceptions with respect to the =
class they are inserted in, such as the following:</div><div><br></div><div=
><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">try</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> </span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">/* Code that might throw */</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">catch</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" 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><font co=
lor=3D"#000000"><span style=3D"color: #000;" class=3D"styled-by-prettify">c=
ustom_exception </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> ex</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">catch</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: #606;" class=3D"style=
d-by-prettify">Bar</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
custom_exception </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> ex</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">{}</span></font></div><=
/code></div><br>These two exceptions may or may not be related. If they are=
, a common base class can also be used for a "catch all in category" approa=
ch. This also works with templates:</div><div><br></div><div><div class=3D"=
prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: brea=
k-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: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">clas=
s</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #000;" cla=
ss=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></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">public</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-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
custom_exception </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">public</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">exception </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: #800;" =
class=3D"styled-by-prettify">/* ... */</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">};</span></div></code></div><br>Each Foo template instantiation also re=
sults in a different instance of custom exception, so this is possible:</di=
v><div><br></div><div><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"><font col=
or=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prettify">tr=
y</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">/* Code that might t=
hrow */</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><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #080;" clas=
s=3D"styled-by-prettify"><int></span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">custom_exception </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> ex</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #800;" class=3D"styled-by-prettify">/* Handle exceptions fo=
r int instances of Foo */</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #008;" class=3D"styled-by-prettify">catch</sp=
an><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: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: =
#080;" class=3D"styled-by-prettify"><float></span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">custom_exception </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> ex</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </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: #800;" class=3D"styled-by-prettify">/* Handle =
exceptions for float instances of Foo */</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">}</span></font></div></code></div><br>This is useful, =
but it's not possible to follow the same "catch all in category" approach, =
which would catch all exceptions of type Foo<T>::custom_exception, re=
gardless of T. Again, this could be solved by making them share the same ba=
se class, declared outside the class definition, probably in some namespace=
(say, ::std). This obviously defeats the purpose of not polluting the name=
space. This is why I though of something like this:</div><div><br></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"><font color=3D"#660066"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">try</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br> </span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">/* Code that might throw */</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"color: =
#008;" class=3D"styled-by-prettify">catch</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: #606;" class=3D"style=
d-by-prettify">Foo</span><span style=3D"color: #080;" class=3D"styled-by-pr=
ettify"><int></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>custom_exception </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> ex</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
800;" class=3D"styled-by-prettify">/* Handle exceptions for int instances o=
f Foo */</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">catch</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">>::</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">custom_exception </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> ex</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: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #800;" class=3D"styled-by-prettify">/* Handle e=
xceptions for all other instances of Foo */</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span></font></div></code></div><div><br></div><div>I b=
elieve this could be trivially implemented by the compiler: when a template=
expression of this kind is found it generates a base class for all instanc=
es of Foo<T>::custom_exception and replaces the catch expression with=
the base class. This does not pollute the namespace and allows defining so=
mething like this in a trivial manner, instead of going through the hassle =
of having to define a custom base class.</div><div><br></div>To be honest, =
I haven't given much though to how this would be useful in other situations=
, but maybe you guys can help with that. Does something like this exist? Do=
you think it could be useful?<br></div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br>
<br><!--end of _originalContent --></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
.
Author: =?UTF-8?Q?Andr=C3=A9?= <andre.francisco@tryhype.co>
Date: Sun, 7 Feb 2016 15:30:26 -0800 (PST)
Raw View
------=_Part_674_782831514.1454887826478
Content-Type: multipart/alternative;
boundary="----=_Part_675_1320280309.1454887826479"
------=_Part_675_1320280309.1454887826479
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I guess you are right. I though of situations in which the template class=
=20
would be specialized and the exception definition would not even exist, or=
=20
would exist with a different base class, for instance. These do complicate=
=20
the issue, but pattern matching is definitely worth considering. Anyway, I=
=20
don't think that the problem would be to provide an implementation, that=20
doesn't seem hard, if given some though, even though I might be wrong.=20
Still, does the idea still seam worth pursuing? Could you please provide=20
more details on those other proposals you mentioned?
Thanks!
domingo, 7 de Fevereiro de 2016 =C3=A0s 23:24:38 UTC, Tony V E escreveu:
>
> > when a template expression of this kind is found it generates a base=20
> class for all instances of Foo<T>::custom_exception and replaces the catc=
h=20
> expression with the base class.=20
>
> OK that's not going to work. You can't suddenly decide that some class no=
w=20
> has a base class, which wasn't mentioned in the class definition.=20
>
> If you had said that the compiler would generate some magic catch=20
> clause=E2=80=8E(s) that match any instances of the template, then maybe.=
=20
>
> The general concept that you are looking for, I think, is 'pattern=20
> matching'. You want to catch anything that matches the pattern.=20
>
> You could imagine also wanting something similar in switch case=20
> statements. And in fact there are proposals along that line, including on=
e=20
> by Stroustrup.=20
>
>
>
>
> Sent from my BlackBerry portable Babbage Device
> *From: *Andr=C3=A9
> *Sent: *Sunday, February 7, 2016 6:16 PM
> *To: *ISO C++ Standard - Future Proposals
> *Reply To: *std-pr...@isocpp.org <javascript:>
> *Subject: *[std-proposals] Template expressions
>
> Hello,
>
> The term expression template=20
> <https://en.wikipedia.org/wiki/Expression_templates> has been coined to=
=20
> mean the use of templates for computations at compile time, but that's no=
t=20
> to be confused with *template expressions*, the topic I'm bringing to=20
> discussion. As these two terms can be confused, I've also considered *inl=
ine=20
> template expressions* as an alternative.
>
> The idea comes from scoping exceptions, although it can be relaxed to mea=
n=20
> other stuff. Lets start by analysing this code:
>
> class custom_exception=20
> : public std::exception=20
> { /* whatever */ };
>
> class Foo
> {
> public:
>
> void foo()
> {
> throw custom_exception();
> }
> };
>
> This is pretty standard, not fancy at all. A paradigm that I use often an=
d borrowed=20
> from python's django=20
> <https://docs.djangoproject.com/es/1.9/ref/models/instances/#django.db.mo=
dels.Model.DoesNotExist> is=20
> to inline the exception in the class definition, like this:
>
> class Foo
> {
> public:
>
> class custom_exception : public std::exception { /* ... */ }
>
> void foo()
> {
> throw custom_exception();
> }
> };
>
> Why does this help? For starters it helps preventing the pollution of the=
=20
> namespace where the exception is being defined. Instead, the exception is=
=20
> referred to as Foo::custom_exception, which allows to have=20
> Bar::custom_exception (the same name) meaning something different.=20
> Secondly, it allows to catch exceptions with respect to the class they ar=
e=20
> inserted in, such as the following:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo::custom_exception & ex) {}
> catch (Bar::custom_exception & ex) {}
>
> These two exceptions may or may not be related. If they are, a common bas=
e=20
> class can also be used for a "catch all in category" approach. This also=
=20
> works with templates:
>
> template <class T>
> class Foo
> {
> public:
>
> class custom_exception : public std::exception { /* ... */ }
> };
>
> Each Foo template instantiation also results in a different instance of=
=20
> custom exception, so this is possible:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int=20
> instances of Foo */ }
> catch (Foo<float>::custom_exception & ex) { /* Handle exceptions for=20
> float instances of Foo */ }
>
> This is useful, but it's not possible to follow the same "catch all in=20
> category" approach, which would catch all exceptions of type=20
> Foo<T>::custom_exception, regardless of T. Again, this could be solved by=
=20
> making them share the same base class, declared outside the class=20
> definition, probably in some namespace (say, ::std). This obviously defea=
ts=20
> the purpose of not polluting the namespace. This is why I though of=20
> something like this:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int=20
> instances of Foo */ }
> catch (template <class T> Foo<T>::custom_exception & ex) { /* Handle=20
> exceptions for all other instances of Foo */ }
>
> I believe this could be trivially implemented by the compiler: when a=20
> template expression of this kind is found it generates a base class for a=
ll=20
> instances of Foo<T>::custom_exception and replaces the catch expression=
=20
> with the base class. This does not pollute the namespace and allows=20
> defining something like this in a trivial manner, instead of going throug=
h=20
> the hassle of having to define a custom base class.
>
> To be honest, I haven't given much though to how this would be useful in=
=20
> other situations, but maybe you guys can help with that. Does something=
=20
> like this exist? Do you think it could be useful?
>
> --=20
>
> ---=20
> You received this message because you are subscribed to the Google Groups=
=20
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
=20
> email to std-proposal...@isocpp.org <javascript:>.
> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
> Visit this group at=20
> https://groups.google.com/a/isocpp.org/group/std-proposals/.
>
>
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_675_1320280309.1454887826479
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I guess you are right. I though of situations in which the=
template class would be specialized and the exception definition would not=
even exist, or would exist with a different base class, for instance. Thes=
e do complicate the issue, but pattern matching is definitely worth conside=
ring. Anyway, I don't think that the problem would be to provide an imp=
lementation, that doesn't seem hard, if given some though, even though =
I might be wrong. Still, does the idea still seam worth pursuing? Could you=
please provide more details on those other proposals you mentioned?<div><b=
r></div><div>Thanks!<br><br>domingo, 7 de Fevereiro de 2016 =C3=A0s 23:24:3=
8 UTC, Tony V E escreveu:<blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
lang=3D"en-US" style=3D"background-color:rgb(255,255,255);line-height:initi=
al"> =
<div style=3D"width:100%;font-size:initial;font-family:Calib=
ri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-alig=
n:initial;background-color:rgb(255,255,255)">>=C2=A0<span style=3D"line-=
height:initial">when a template expression of this kind is found it generat=
es a base class for all instances of Foo<T>::custom_exception and rep=
laces the catch expression with the base class.</span><span style=3D"line-h=
eight:initial">=C2=A0</span></div><div style=3D"width:100%;font-size:initia=
l;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(3=
1,73,125);text-align:initial;background-color:rgb(255,255,255)"><span style=
=3D"line-height:initial"><br></span></div><div style=3D"width:100%;font-siz=
e:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;col=
or:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><sp=
an style=3D"line-height:initial">OK that's not going to work. You can&#=
39;t suddenly decide that some class now has a base class, which wasn't=
mentioned in the class definition.=C2=A0</span></div><div style=3D"width:1=
00%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sa=
ns-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,2=
55,255)"><span style=3D"line-height:initial"><br></span></div><div style=3D=
"width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-=
serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:r=
gb(255,255,255)"><span style=3D"line-height:initial">If you had said that t=
he compiler would generate some magic catch clause=E2=80=8E(s) that match a=
ny instances of the template, then maybe.=C2=A0</span></div><div style=3D"w=
idth:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-se=
rif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb=
(255,255,255)"><span style=3D"line-height:initial"><br></span></div><div st=
yle=3D"width:100%;font-size:initial;font-family:Calibri,'Slate Pro'=
,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-c=
olor:rgb(255,255,255)"><span style=3D"line-height:initial">The general conc=
ept that you are looking for, I think, is 'pattern matching'. You w=
ant to catch anything that matches the pattern.=C2=A0</span></div><div styl=
e=3D"width:100%;font-size:initial;font-family:Calibri,'Slate Pro',s=
ans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-col=
or:rgb(255,255,255)"><span style=3D"line-height:initial"><br></span></div><=
div style=3D"width:100%;font-size:initial;font-family:Calibri,'Slate Pr=
o',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backgr=
ound-color:rgb(255,255,255)"><span style=3D"line-height:initial">You could =
imagine also wanting something similar in switch case statements. And in fa=
ct there are proposals along that line, including one by Stroustrup.=C2=A0<=
/span></div><div style=3D"width:100%;font-size:initial;font-family:Calibri,=
'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:i=
nitial;background-color:rgb(255,255,255)"><span style=3D"line-height:initia=
l"><br></span></div><div style=3D"width:100%;font-size:initial;font-family:=
Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);text=
-align:initial;background-color:rgb(255,255,255)"><span style=3D"line-heigh=
t:initial"><br></span></div><div style=3D"width:100%;font-size:initial;font=
-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,1=
25);text-align:initial;background-color:rgb(255,255,255)"><br></div> =
=
<div style=3D"width:100%=
;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-=
serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,=
255)"><br style=3D"display:initial"></div> =
=
=
<div style=3D"font-size:initial;font-family:Calibri,'Slate =
Pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;back=
ground-color:rgb(255,255,255)">Sent=C2=A0from=C2=A0my=C2=A0BlackBerry=C2=A0=
<wbr>portable=C2=A0Babbage=C2=A0Device</div> =
=
<ta=
ble width=3D"100%" style=3D"background-color:white;border-spacing:0px"> <tb=
ody><tr><td colspan=3D"2" style=3D"font-size:initial;text-align:initial;bac=
kground-color:rgb(255,255,255)"> <div style=3D"bo=
rder-style:solid none none;border-top-color:rgb(181,196,223);border-top-wid=
th:1pt;padding:3pt 0in 0in;font-family:Tahoma,'BB Alpha Sans','=
Slate Pro';font-size:10pt"> <div><b>From: </b>Andr=C3=A9</div><div><b>=
Sent: </b>Sunday, February 7, 2016 6:16 PM</div><div><b>To: </b>ISO C++ Sta=
ndard - Future Proposals</div><div><b>Reply To: </b><a href=3D"javascript:"=
target=3D"_blank" gdf-obfuscated-mailto=3D"xAOsIHueHQAJ" rel=3D"nofollow" =
onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"t=
his.href=3D'javascript:';return true;">std-pr...@isocpp.org</a></di=
v><div><b>Subject: </b>[std-proposals] Template expressions</div></div></td=
></tr></tbody></table><div style=3D"border-style:solid none none;border-top=
-color:rgb(186,188,209);border-top-width:1pt;font-size:initial;text-align:i=
nitial;background-color:rgb(255,255,255)"></div><br><div><div dir=3D"ltr">H=
ello,<div><br></div><div>The term=C2=A0<a href=3D"https://en.wikipedia.org/=
wiki/Expression_templates" target=3D"_blank" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fen.wikipe=
dia.org%2Fwiki%2FExpression_templates\46sa\75D\46sntz\0751\46usg\75AFQjCNEZ=
UiMNB6cFVK26BIDr4Woup3QdTA';return true;" onclick=3D"this.href=3D'h=
ttps://www.google.com/url?q\75https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FExpre=
ssion_templates\46sa\75D\46sntz\0751\46usg\75AFQjCNEZUiMNB6cFVK26BIDr4Woup3=
QdTA';return true;">expression template</a>=C2=A0has been coined to mea=
n the use of templates for computations at compile time, but that's not=
to be confused with <i>template expressions</i>, the topic I'm bringin=
g to discussion. As these two terms can be confused, I've also consider=
ed <i>inline template expressions</i>=C2=A0as an alternative.</div><div><br=
></div><div>The idea comes from scoping exceptions, although it can be rela=
xed to mean other stuff. Lets start by analysing this code:</div><div><br><=
/div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code><div><span style=3D"color:#008=
">class</span><span style=3D"color:#000"> custom_exception <br>=C2=A0 =C2=
=A0</span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">public</span><span style=3D"color:#000"> st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">exce=
ption <br></span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#800">/* whatever */</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">};</span><span style=3D"colo=
r:#000"><br><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Foo</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#008">public</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0</s=
pan><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"><br>=C2=
=A0 =C2=A0</span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">throw</span>=
<span style=3D"color:#000"> custom_exception</span><span style=3D"color:#66=
0">();</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">};</span></div></code></div><br>This is pretty standard, no=
t fancy at all. A paradigm that I use often and <a href=3D"https://docs.dja=
ngoproject.com/es/1.9/ref/models/instances/#django.db.models.Model.DoesNotE=
xist" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'ht=
tps://www.google.com/url?q\75https%3A%2F%2Fdocs.djangoproject.com%2Fes%2F1.=
9%2Fref%2Fmodels%2Finstances%2F%23django.db.models.Model.DoesNotExist\46sa\=
75D\46sntz\0751\46usg\75AFQjCNH9srWjeRThDcht9nkYwGhNnrRYjA';return true=
;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2=
Fdocs.djangoproject.com%2Fes%2F1.9%2Fref%2Fmodels%2Finstances%2F%23django.d=
b.models.Model.DoesNotExist\46sa\75D\46sntz\0751\46usg\75AFQjCNH9srWjeRThDc=
ht9nkYwGhNnrRYjA';return true;">borrowed from python's django</a>=
=C2=A0is to inline the exception in the class definition, like this:</div><=
div><br></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wra=
p:break-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#=
660066"><span style=3D"color:#008">class</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Foo</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></=
span><span style=3D"color:#008">public</span><span style=3D"color:#660">:</=
span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#008">class</span><span style=3D"color:#000"> custom_exception </spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">public</span><span style=3D"color:#000"> std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">exception </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#800">/* ... */</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">void</span><span style=3D"c=
olor:#000"> foo</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span=
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"=
color:#008">throw</span><span style=3D"color:#000"> custom_exception</span>=
<span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
><br></span><span style=3D"color:#660">};</span></font></div></code></div><=
br>Why does this help? For starters it helps preventing the pollution of th=
e namespace where the exception is being defined. Instead, the exception is=
referred to as Foo::custom_exception, which allows to have Bar::custom_exc=
eption (the same name) meaning something different. Secondly, it allows to =
catch exceptions with respect to the class they are inserted in, such as th=
e following:</div><div><br></div><div><div style=3D"border:1px solid rgb(18=
7,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><d=
iv><span style=3D"color:#008">try</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0</span><span style=3D"color:#800">/* Code that might throw */</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br><br></span><span style=3D"color:#008">catch</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#606">Foo</span><span style=3D"color:#660">::</span><fon=
t color=3D"#000000"><span style=3D"color:#000">custom_exception </span><spa=
n style=3D"color:#660">&</span><span style=3D"color:#000"> ex</span><sp=
an style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">{}</span><span style=3D"color:#000"><br></span><span sty=
le=3D"color:#008">catch</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#606">Bar</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">custom_exception </span=
><span style=3D"color:#660">&</span><span style=3D"color:#000"> ex</spa=
n><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">{}</span></font></div></code></div><br>These two ex=
ceptions may or may not be related. If they are, a common base class can al=
so be used for a "catch all in category" approach. This also work=
s with templates:</div><div><br></div><div><div style=3D"border:1px solid r=
gb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><co=
de><div><span style=3D"color:#008">template</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660"><</span><span style=3D"color:#008">=
class</span><span style=3D"color:#000"> T</span><span style=3D"color:#660">=
></span><span style=3D"color:#000"><br></span><span style=3D"color:#008"=
>class</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
Foo</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">pu=
blic</span><span style=3D"color:#660">:</span><span style=3D"color:#000"><b=
r><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">class</span><span sty=
le=3D"color:#000"> custom_exception </span><span style=3D"color:#660">:</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">public</sp=
an><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#000">exception </span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#800">/* ... =
*/</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</sp=
an></div></code></div><br>Each Foo template instantiation also results in a=
different instance of custom exception, so this is possible:</div><div><br=
></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#660066"=
><span style=3D"color:#008">try</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0</span><span style=3D"color:#800">/* Code that might throw */</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span =
style=3D"color:#000"><br><br></span><span style=3D"color:#008">catch</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span=
style=3D"color:#606">Foo</span><span style=3D"color:#080"><int></spa=
n><span style=3D"color:#660">::</span><span style=3D"color:#000">custom_exc=
eption </span><span style=3D"color:#660">&</span><span style=3D"color:#=
000"> ex</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:#800">/* Handle exceptions for int instances of F=
oo */</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">cat=
ch</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#606">Foo</span><span style=3D"color:#080"><flo=
at></span><span style=3D"color:#660">::</span><span style=3D"color:#000"=
>custom_exception </span><span style=3D"color:#660">&</span><span style=
=3D"color:#000"> ex</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:#800">/* Handle exceptions for float i=
nstances of Foo */</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">}</span></font></div></code></div><br>This is useful, but it=
9;s not possible to follow the same "catch all in category" appro=
ach, which would catch all exceptions of type Foo<T>::custom_exceptio=
n, regardless of T. Again, this could be solved by making them share the sa=
me base class, declared outside the class definition, probably in some name=
space (say, ::std). This obviously defeats the purpose of not polluting the=
namespace. This is why I though of something like this:</div><div><br></di=
v><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word=
;background-color:rgb(250,250,250)"><code><div><font color=3D"#660066"><spa=
n style=3D"color:#008">try</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</s=
pan><span style=3D"color:#800">/* Code that might throw */</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br><br></span><span style=3D"color:#008">catch</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#606">Foo</span><span style=3D"color:#080"><int></span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">custom_exceptio=
n </span><span style=3D"color:#660">&</span><span style=3D"color:#000">=
ex</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:#800">/* Handle exceptions for int instances of Foo */=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"><br></span><span style=3D"color:#008">catch</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><=
span style=3D"color:#008">template</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660"><</span><span style=3D"color:#008">class</sp=
an><span style=3D"color:#000"> T</span><span style=3D"color:#660">></spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">Foo</span><=
span style=3D"color:#660"><</span><span style=3D"color:#000">T</span><sp=
an style=3D"color:#660">>::</span><span style=3D"color:#000">custom_exce=
ption </span><span style=3D"color:#660">&</span><span style=3D"color:#0=
00"> ex</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:#800">/* Handle exceptions for all other instances=
of Foo */</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br></span></font></div></code></div=
><div><br></div><div>I believe this could be trivially implemented by the c=
ompiler: when a template expression of this kind is found it generates a ba=
se class for all instances of Foo<T>::custom_exception and replaces t=
he catch expression with the base class. This does not pollute the namespac=
e and allows defining something like this in a trivial manner, instead of g=
oing through the hassle of having to define a custom base class.</div><div>=
<br></div>To be honest, I haven't given much though to how this would b=
e useful in other situations, but maybe you guys can help with that. Does s=
omething like this exist? Do you think it could be useful?<br></div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
xAOsIHueHQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"xAOsIHueHQAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.hre=
f=3D'https://groups.google.com/a/isocpp.org/group/std-proposals/';r=
eturn true;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp=
..org/group/std-proposals/';return true;">https://groups.google.com/a/<w=
br>isocpp.org/group/std-<wbr>proposals/</a>.<br>
<br></div></div>
</blockquote></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_675_1320280309.1454887826479--
------=_Part_674_782831514.1454887826478--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Sun, 07 Feb 2016 20:06:59 -0500
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
255, 255); line-height: initial;"> =
<div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">For pattern matching, Bjarne's latest proposal isn't published =
yet, But you can check out a library-based version <span style=3D"colo=
r: rgb(0, 102, 33); font-family: arial, sans-serif; font-size: 14px; line-h=
eight: 16px; white-space: nowrap;">www.stroustrup.com/</span><b style=3D"co=
lor: rgb(0, 102, 33); font-family: arial, sans-serif; font-size: 14px; line=
-height: 16px; white-space: nowrap;">OpenPattern</b><span style=3D"color: r=
gb(0, 102, 33); font-family: arial, sans-serif; font-size: 14px; line-heigh=
t: 16px; white-space: nowrap;">Matching.pdf</span></div><div><span style=3D=
"color: rgb(0, 102, 33); font-family: arial, sans-serif; font-size: 14px; l=
ine-height: 16px; white-space: nowrap;"><br></span><div style=3D"font-size:=
initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color:=
rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255=
);">David Sankel is also working on a proposal, check out his blog: davidsa=
nkel.com </div><div style=3D"font-size: initial; font-family: Calibri,=
'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: =
initial; background-color: rgb(255, 255, 255);"><br></div><div style=3D"fon=
t-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif;=
color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 2=
55, 255);">Sent from my BlackBerry portable Babbag=
e Device</div> <div style=3D"dis=
play:none"></div><div style=3D"font-size: initial; text-align: initial; bac=
kground-color: rgb(255, 255, 255);"><table width=3D"100%" style=3D"backgrou=
nd-color:white; border-spacing:0px;"> =
<tbody><tr><td></td><td id=3D"_separatorInternal" rowspan=3D"2" style=
=3D"text-align: center; font-size: initial; background-color: rgb(255, 255,=
255);"> =
<span id=3D"_bb10TempSeparatorText" style=3D"backg=
round-color:white; color:#0073BC;font-size:smaller;font-family:"Slate =
Pro""> Original Message </span> </td></tr> =
=
<t=
r> <td colspan=3D"2"><div style=3D"border:none;border-top:solid #0073BC 1.0=
pt;"></div> =
</td></tr></tbody></table></div> =
=
<table width=3D"100%" style=3D"ba=
ckground-color:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" sty=
le=3D"font-size: initial; text-align: initial; background-color: rgb(255, 2=
55, 255);"> <div style=3D"font-size: smaller;font=
-family:"Tahoma","BB Alpha Sans","Slate Pro",=
sans-serif,"sans-serif";"> <div><b>From: </b>Andr=C3=A9</div><di=
v><b>Sent: </b>Sunday, February 7, 2016 6:30 PM</div><div><b>To: </b>ISO C+=
+ Standard - Future Proposals</div><div><b>Reply To: </b>std-proposals@isoc=
pp.org</div><div><b>Subject: </b>Re: [std-proposals] Template expressions</=
div></div></td></tr></tbody></table><div style=3D"border-style: solid none =
none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-siz=
e: initial; text-align: initial; background-color: rgb(255, 255, 255);"></d=
iv><br><div id=3D"_originalContent" style=3D""><div dir=3D"ltr">I guess you=
are right. I though of situations in which the template class would be spe=
cialized and the exception definition would not even exist, or would exist =
with a different base class, for instance. These do complicate the issue, b=
ut pattern matching is definitely worth considering. Anyway, I don't think =
that the problem would be to provide an implementation, that doesn't seem h=
ard, if given some though, even though I might be wrong. Still, does the id=
ea still seam worth pursuing? Could you please provide more details on thos=
e other proposals you mentioned?<div><br></div><div>Thanks!<br><br>domingo,=
7 de Fevereiro de 2016 =C3=A0s 23:24:38 UTC, Tony V E escreveu:<blockquote=
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1=
px #ccc solid;padding-left: 1ex;"><div lang=3D"en-US" style=3D"background-c=
olor:rgb(255,255,255);line-height:initial"> =
<div style=3D"width:1=
00%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif=
;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"=
>> <span style=3D"line-height:initial">when a template expression o=
f this kind is found it generates a base class for all instances of Foo<=
T>::custom_exception and replaces the catch expression with the base cla=
ss.</span><span style=3D"line-height:initial"> </span></div><div style=
=3D"width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif=
,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(25=
5,255,255)"><span style=3D"line-height:initial"><br></span></div><div style=
=3D"width:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif=
,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(25=
5,255,255)"><span style=3D"line-height:initial">OK that's not going to work=
.. You can't suddenly decide that some class now has a base class, which was=
n't mentioned in the class definition. </span></div><div style=3D"widt=
h:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-se=
rif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,25=
5)"><span style=3D"line-height:initial"><br></span></div><div style=3D"widt=
h:100%;font-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-se=
rif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,25=
5)"><span style=3D"line-height:initial">If you had said that the compiler w=
ould generate some magic catch clause=E2=80=8E(s) that match any instances =
of the template, then maybe. </span></div><div style=3D"width:100%;fon=
t-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:=
rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><span =
style=3D"line-height:initial"><br></span></div><div style=3D"width:100%;fon=
t-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:=
rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><span =
style=3D"line-height:initial">The general concept that you are looking for,=
I think, is 'pattern matching'. You want to catch anything that matches th=
e pattern. </span></div><div style=3D"width:100%;font-size:initial;fon=
t-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);tex=
t-align:initial;background-color:rgb(255,255,255)"><span style=3D"line-heig=
ht:initial"><br></span></div><div style=3D"width:100%;font-size:initial;fon=
t-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125);tex=
t-align:initial;background-color:rgb(255,255,255)"><span style=3D"line-heig=
ht:initial">You could imagine also wanting something similar in switch case=
statements. And in fact there are proposals along that line, including one=
by Stroustrup. </span></div><div style=3D"width:100%;font-size:initia=
l;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125=
);text-align:initial;background-color:rgb(255,255,255)"><span style=3D"line=
-height:initial"><br></span></div><div style=3D"width:100%;font-size:initia=
l;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125=
);text-align:initial;background-color:rgb(255,255,255)"><span style=3D"line=
-height:initial"><br></span></div><div style=3D"width:100%;font-size:initia=
l;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;color:rgb(31,73,125=
);text-align:initial;background-color:rgb(255,255,255)"><br></div> =
=
<div style=3D"width:100%;f=
ont-size:initial;font-family:Calibri,'Slate Pro',sans-serif,sans-serif;colo=
r:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br =
style=3D"display:initial"></div> =
=
=
<div style=3D"font-size:initial;font-family:Calibri,'Slate Pro',sans-seri=
f,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(2=
55,255,255)">Sent from my BlackBerry <wbr>portable =
;Babbage Device</div> =
=
<table width=3D"100%"=
style=3D"background-color:white;border-spacing:0px"> <tbody><tr><td colspa=
n=3D"2" style=3D"font-size:initial;text-align:initial;background-color:rgb(=
255,255,255)"> <div style=3D"border-style:solid n=
one none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt=
0in 0in;font-family:Tahoma,'BB Alpha Sans','Slate Pro';font-size:10pt"> <=
div><b>From: </b>Andr=C3=A9</div><div><b>Sent: </b>Sunday, February 7, 2016=
6:16 PM</div><div><b>To: </b>ISO C++ Standard - Future Proposals</div><div=
><b>Reply To: </b><a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"xAOsIHueHQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javasc=
ript:';return true;" onclick=3D"this.href=3D'javascript:';return true;">std=
-pr...@isocpp.org</a></div><div><b>Subject: </b>[std-proposals] Template ex=
pressions</div></div></td></tr></tbody></table><div style=3D"border-style:s=
olid none none;border-top-color:rgb(186,188,209);border-top-width:1pt;font-=
size:initial;text-align:initial;background-color:rgb(255,255,255)"></div><b=
r><div><div dir=3D"ltr">Hello,<div><br></div><div>The term <a href=3D"=
https://en.wikipedia.org/wiki/Expression_templates" target=3D"_blank" rel=
=3D"nofollow" onmousedown=3D"this.href=3D'https://www.google.com/url?q\75ht=
tps%3A%2F%2Fen.wikipedia.org%2Fwiki%2FExpression_templates\46sa\75D\46sntz\=
0751\46usg\75AFQjCNEZUiMNB6cFVK26BIDr4Woup3QdTA';return true;" onclick=3D"t=
his.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fen.wikipedia.org%2=
Fwiki%2FExpression_templates\46sa\75D\46sntz\0751\46usg\75AFQjCNEZUiMNB6cFV=
K26BIDr4Woup3QdTA';return true;">expression template</a> has been coin=
ed to mean the use of templates for computations at compile time, but that'=
s not to be confused with <i>template expressions</i>, the topic I'm bringi=
ng to discussion. As these two terms can be confused, I've also considered =
<i>inline template expressions</i> as an alternative.</div><div><br></=
div><div>The idea comes from scoping exceptions, although it can be relaxed=
to mean other stuff. Lets start by analysing this code:</div><div><br></di=
v><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:#008">c=
lass</span><span style=3D"color:#000"> custom_exception <br> </=
span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#008">public</span><span style=3D"color:#000"> std</sp=
an><span style=3D"color:#660">::</span><span style=3D"color:#000">exception=
<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000"> =
</span><span style=3D"color:#800">/* whatever */</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">};</span><span style=3D"color:#00=
0"><br><br></span><span style=3D"color:#008">class</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#606">Foo</span><span style=3D"color:=
#000"><br></span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"><br></span><span style=3D"color:#008">public</span><span style=3D"color=
:#660">:</span><span style=3D"color:#000"><br><br> </span><span=
style=3D"color:#008">void</span><span style=3D"color:#000"> foo</span><spa=
n 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; </span><span style=3D"color:#008">throw</span><span sty=
le=3D"color:#000"> custom_exception</span><span style=3D"color:#660">();</s=
pan><span style=3D"color:#000"><br> </span><span style=3D"color=
:#660">}</span><span style=3D"color:#000"><br></span><span style=3D"color:#=
660">};</span></div></code></div><br>This is pretty standard, not fancy at =
all. A paradigm that I use often and <a href=3D"https://docs.djangoproject.=
com/es/1.9/ref/models/instances/#django.db.models.Model.DoesNotExist" targe=
t=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'https://www.googl=
e.com/url?q\75https%3A%2F%2Fdocs.djangoproject.com%2Fes%2F1.9%2Fref%2Fmodel=
s%2Finstances%2F%23django.db.models.Model.DoesNotExist\46sa\75D\46sntz\0751=
\46usg\75AFQjCNH9srWjeRThDcht9nkYwGhNnrRYjA';return true;" onclick=3D"this.=
href=3D'https://www.google.com/url?q\75https%3A%2F%2Fdocs.djangoproject.com=
%2Fes%2F1.9%2Fref%2Fmodels%2Finstances%2F%23django.db.models.Model.DoesNotE=
xist\46sa\75D\46sntz\0751\46usg\75AFQjCNH9srWjeRThDcht9nkYwGhNnrRYjA';retur=
n true;">borrowed from python's django</a> is to inline the exception =
in the class definition, like this:</div><div><br></div><div><div style=3D"=
border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb=
(250,250,250)"><code><div><font color=3D"#660066"><span style=3D"color:#008=
">class</span><span style=3D"color:#000"> </span><span style=3D"color:#606"=
>Foo</span><span style=3D"color:#000"><br></span><span style=3D"color:#660"=
>{</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">p=
ublic</span><span style=3D"color:#660">:</span><span style=3D"color:#000"><=
br><br> </span><span style=3D"color:#008">class</span><span st=
yle=3D"color:#000"> custom_exception </span><span style=3D"color:#660">:</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#008">public</s=
pan><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">exception </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"> </span><span style=3D"color:#800">/* ...=
*/</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</=
span><span style=3D"color:#000"><br><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"><br> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br> =
</span><span style=3D"color:#008">throw</span><span sty=
le=3D"color:#000"> custom_exception</span><span style=3D"color:#660">();</s=
pan><span style=3D"color:#000"><br> </span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"><br></span><span style=3D"color:=
#660">};</span></font></div></code></div><br>Why does this help? For starte=
rs it helps preventing the pollution of the namespace where the exception i=
s being defined. Instead, the exception is referred to as Foo::custom_excep=
tion, which allows to have Bar::custom_exception (the same name) meaning so=
mething different. Secondly, it allows to catch exceptions with respect to =
the class they are inserted in, such as the following:</div><div><br></div>=
<div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;b=
ackground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">try=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br> </span><span style=3D"color:#=
800">/* Code that might throw */</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></s=
pan><span style=3D"color:#008">catch</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#606">Foo</span>=
<span style=3D"color:#660">::</span><font color=3D"#000000"><span style=3D"=
color:#000">custom_exception </span><span style=3D"color:#660">&</span>=
<span style=3D"color:#000"> ex</span><span style=3D"color:#660">)</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">{}</span><span s=
tyle=3D"color:#000"><br></span><span style=3D"color:#008">catch</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span styl=
e=3D"color:#606">Bar</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">custom_exception </span><span style=3D"color:#660">&</s=
pan><span style=3D"color:#000"> ex</span><span style=3D"color:#660">)</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">{}</span></f=
ont></div></code></div><br>These two exceptions may or may not be related. =
If they are, a common base class can also be used for a "catch all in categ=
ory" approach. This also works with templates:</div><div><br></div><div><di=
v style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgroun=
d-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">template</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#008">class</span><span style=3D"color:#000"> T</spa=
n><span style=3D"color:#660">></span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#008">class</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">Foo</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#008">public</span><span style=3D"color:#660">:</span>=
<span style=3D"color:#000"><br><br> </span><span style=3D"colo=
r:#008">class</span><span style=3D"color:#000"> custom_exception </span><sp=
an style=3D"color:#660">:</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#008">public</span><span style=3D"color:#000"> std</span><span=
style=3D"color:#660">::</span><span style=3D"color:#000">exception </span>=
<span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span=
style=3D"color:#800">/* ... */</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">}</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">};</span></div></code></div><br>Each Foo template in=
stantiation also results in a different instance of custom exception, so th=
is is possible:</div><div><br></div><div><div style=3D"border:1px solid rgb=
(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code=
><div><font color=3D"#660066"><span style=3D"color:#008">try</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#800">/* Code =
that might throw */</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span sty=
le=3D"color:#008">catch</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#606">Foo</span><span style=
=3D"color:#080"><int></span><span style=3D"color:#660">::</span><span=
style=3D"color:#000">custom_exception </span><span style=3D"color:#660">&a=
mp;</span><span style=3D"color:#000"> ex</span><span style=3D"color:#660">)=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#800">/* Handle e=
xceptions for int instances of Foo */</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">}</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#008">catch</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">(</span><span style=3D"color:#606">Foo</span><s=
pan style=3D"color:#080"><float></span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">custom_exception </span><span style=3D"col=
or:#660">&</span><span style=3D"color:#000"> ex</span><span style=3D"co=
lor:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"> </span><span style=3D"color:#800">=
/* Handle exceptions for float instances of Foo */</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">}</span></font></div></code></d=
iv><br>This is useful, but it's not possible to follow the same "catch all =
in category" approach, which would catch all exceptions of type Foo<T>=
;::custom_exception, regardless of T. Again, this could be solved by making=
them share the same base class, declared outside the class definition, pro=
bably in some namespace (say, ::std). This obviously defeats the purpose of=
not polluting the namespace. This is why I though of something like this:<=
/div><div><br></div><div><div style=3D"border:1px solid rgb(187,187,187);wo=
rd-wrap:break-word;background-color:rgb(250,250,250)"><code><div><font colo=
r=3D"#660066"><span style=3D"color:#008">try</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><b=
r> </span><span style=3D"color:#800">/* Code that might throw *=
/</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:#008">=
catch</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(=
</span><span style=3D"color:#606">Foo</span><span style=3D"color:#080"><=
int></span><span style=3D"color:#660">::</span><span style=3D"color:#000=
">custom_exception </span><span style=3D"color:#660">&</span><span styl=
e=3D"color:#000"> ex</span><span style=3D"color:#660">)</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#800">/* Handle exceptions for int =
instances of Foo */</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">}</span><span style=3D"color:#000"><br></span><span style=3D"c=
olor:#008">catch</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#008">template</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660"><</span><span style=3D"co=
lor:#008">class</span><span style=3D"color:#000"> T</span><span style=3D"co=
lor:#660">></span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">Foo</span><span style=3D"color:#660"><</span><span style=3D"colo=
r:#000">T</span><span style=3D"color:#660">>::</span><span style=3D"colo=
r:#000">custom_exception </span><span style=3D"color:#660">&</span><spa=
n style=3D"color:#000"> ex</span><span style=3D"color:#660">)</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#800">/* Handle exceptions for=
all other instances of Foo */</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br></span></fon=
t></div></code></div><div><br></div><div>I believe this could be trivially =
implemented by the compiler: when a template expression of this kind is fou=
nd it generates a base class for all instances of Foo<T>::custom_exce=
ption and replaces the catch expression with the base class. This does not =
pollute the namespace and allows defining something like this in a trivial =
manner, instead of going through the hassle of having to define a custom ba=
se class.</div><div><br></div>To be honest, I haven't given much though to =
how this would be useful in other situations, but maybe you guys can help w=
ith that. Does something like this exist? Do you think it could be useful?<=
br></div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
xAOsIHueHQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';ret=
urn true;" onclick=3D"this.href=3D'javascript:';return true;">std-proposal.=
...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"xAOsIHueHQAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:=
';return true;">std-pr...@isocpp.org</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.hre=
f=3D'https://groups.google.com/a/isocpp.org/group/std-proposals/';return tr=
ue;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp.org/group/s=
td-proposals/';return true;">https://groups.google.com/a/<wbr>isocpp.org/gr=
oup/std-<wbr>proposals/</a>.<br>
<br></div></div>
</blockquote></div></div>
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br>
<br><!--end of _originalContent --></div></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 7 Feb 2016 17:53:29 -0800 (PST)
Raw View
------=_Part_8429_1503608586.1454896409933
Content-Type: multipart/alternative;
boundary="----=_Part_8430_1033981958.1454896409942"
------=_Part_8430_1033981958.1454896409942
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, February 7, 2016 at 6:16:44 PM UTC-5, Andr=C3=A9 wrote:
>
> Hello,
>
> The term expression template=20
> <https://en.wikipedia.org/wiki/Expression_templates> has been coined to=
=20
> mean the use of templates for computations at compile time, but that's no=
t=20
> to be confused with *template expressions*, the topic I'm bringing to=20
> discussion. As these two terms can be confused, I've also considered *inl=
ine=20
> template expressions* as an alternative.
>
> The idea comes from scoping exceptions, although it can be relaxed to mea=
n=20
> other stuff. Lets start by analysing this code:
>
> class custom_exception=20
> : public std::exception=20
> { /* whatever */ };
>
> class Foo
> {
> public:
>
> void foo()
> {
> throw custom_exception();
> }
> };
>
> This is pretty standard, not fancy at all. A paradigm that I use often an=
d borrowed=20
> from python's django=20
> <https://docs.djangoproject.com/es/1.9/ref/models/instances/#django.db.mo=
dels.Model.DoesNotExist> is=20
> to inline the exception in the class definition, like this:
>
> class Foo
> {
> public:
>
> class custom_exception : public std::exception { /* ... */ }
>
> void foo()
> {
> throw custom_exception();
> }
> };
>
> Why does this help? For starters it helps preventing the pollution of the=
=20
> namespace where the exception is being defined.
>
Right. Because C++ is totally running out of names.
=20
> Instead, the exception is referred to as Foo::custom_exception, which=20
> allows to have Bar::custom_exception (the same name) meaning something=20
> different.
>
.... can you give a concrete example of when that would be a good idea? For=
=20
two exception classes in the same namespace (and therefore general project)=
=20
to have the same name, yet mean wildly different things?
=20
> Secondly, it allows to catch exceptions with respect to the class they ar=
e=20
> inserted in, such as the following:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo::custom_exception & ex) {}
> catch (Bar::custom_exception & ex) {}
>
> These two exceptions may or may not be related. If they are, a common bas=
e=20
> class can also be used for a "catch all in category" approach. This also=
=20
> works with templates:
>
> template <class T>
> class Foo
> {
> public:
>
> class custom_exception : public std::exception { /* ... */ }
> };
>
> Each Foo template instantiation also results in a different instance of=
=20
> custom exception, so this is possible:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int=20
> instances of Foo */ }
> catch (Foo<float>::custom_exception & ex) { /* Handle exceptions for=20
> float instances of Foo */ }
>
> This is useful, but it's not possible to follow the same "catch all in=20
> category" approach, which would catch all exceptions of type=20
> Foo<T>::custom_exception, regardless of T. Again, this could be solved by=
=20
> making them share the same base class, declared outside the class=20
> definition, probably in some namespace (say, ::std). This obviously defea=
ts=20
> the purpose of not polluting the namespace. This is why I though of=20
> something like this:
>
> try {
> /* Code that might throw */
> }
>
> catch (Foo<int>::custom_exception & ex) { /* Handle exceptions for int=20
> instances of Foo */ }
> catch (template <class T> Foo<T>::custom_exception & ex) { /* Handle=20
> exceptions for all other instances of Foo */ }
>
>
Except that's not what this would have to do. You forget that C++ is a=20
statically typed language, and `Foo` is not a type; it's a template.=20
`Foo<T>` is a type, but only for a specific type T.
After all, the compiler doesn't know that `typename=20
Foo<T>::custom_exception` will have the same behavior for all `T`s.=20
Specializations can radically change the interface of `Foo` and therefore=
=20
`Foo<T>::custom_exception`.
Normally, template code would be instantiated for every T that is=20
statically used with `Foo`. But you're in a catch block. The compiler must=
=20
*statically* generate code for the catch possibilities. The only way for it=
=20
to do that is to know which kinds of exceptions could possibly be thrown,=
=20
which `T`s will be used to generate `Foo<T>::custom_exception`.
This would require the compiler to introspect into every possible function=
=20
that could be called by the `try` block to see which `Foo<T>` it=20
instantiates, so that the compiler can instantiate a corresponding catch=20
block here. And what about virtual calls or other function pointer-based=20
calls? How do you know that someone won't pass in a `std::function` that=20
fires off some new `Foo<T>::custom_exception`?
That's not a trivial thing to implement.
I cordially dislike attempts by people to encode their own programming=20
habits into the language. You don't like declaring your exceptions at=20
namespace scope; I get that. I don't agree, and I certainly don't agree=20
that we need to add language features to make that easier for you to do.
Especially when there's a trivial solution for you: create an appropriate=
=20
base class. And if it takes up a namespace scoped name... so be it.
=20
> I believe this could be trivially implemented by the compiler: when a=20
> template expression of this kind is found it generates a base class for a=
ll=20
> instances of Foo<T>::custom_exception and replaces the catch expression=
=20
> with the base class. This does not pollute the namespace and allows=20
> defining something like this in a trivial manner, instead of going throug=
h=20
> the hassle of having to define a custom base class.
>
> To be honest, I haven't given much though to how this would be useful in=
=20
> other situations, but maybe you guys can help with that. Does something=
=20
> like this exist? Do you think it could be useful?
>
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_8430_1033981958.1454896409942
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, February 7, 2016 at 6:16:44 PM UTC-5, A=
ndr=C3=A9 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">Hello,<div><br></div><div>The term=C2=A0<a href=3D"https://en.wikipedia.=
org/wiki/Expression_templates" target=3D"_blank" rel=3D"nofollow" onmousedo=
wn=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fen.wiki=
pedia.org%2Fwiki%2FExpression_templates\46sa\75D\46sntz\0751\46usg\75AFQjCN=
EZUiMNB6cFVK26BIDr4Woup3QdTA';return true;" onclick=3D"this.href=3D'=
;https://www.google.com/url?q\75https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FExp=
ression_templates\46sa\75D\46sntz\0751\46usg\75AFQjCNEZUiMNB6cFVK26BIDr4Wou=
p3QdTA';return true;">expression template</a>=C2=A0has been coined to m=
ean the use of templates for computations at compile time, but that's n=
ot to be confused with <i>template expressions</i>, the topic I'm bring=
ing to discussion. As these two terms can be confused, I've also consid=
ered <i>inline template expressions</i>=C2=A0as an alternative.</div><div><=
br></div><div>The idea comes from scoping exceptions, although it can be re=
laxed to mean other stuff. Lets start by analysing this code:</div><div><br=
></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><span style=3D"color:#0=
08">class</span><span style=3D"color:#000"> custom_exception <br>=C2=A0 =C2=
=A0</span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">public</span><span style=3D"color:#000"> st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">exce=
ption <br></span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#800">/* whatever */</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">};</span><span style=3D"colo=
r:#000"><br><br></span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Foo</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"c=
olor:#000"><br></span><span style=3D"color:#008">public</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0</s=
pan><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"><br>=C2=
=A0 =C2=A0</span><span style=3D"color:#660">{</span><span style=3D"color:#0=
00"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">throw</span>=
<span style=3D"color:#000"> custom_exception</span><span style=3D"color:#66=
0">();</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=
=3D"color:#660">}</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">};</span></div></code></div><br>This is pretty standard, no=
t fancy at all. A paradigm that I use often and <a href=3D"https://docs.dja=
ngoproject.com/es/1.9/ref/models/instances/#django.db.models.Model.DoesNotE=
xist" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'ht=
tps://www.google.com/url?q\75https%3A%2F%2Fdocs.djangoproject.com%2Fes%2F1.=
9%2Fref%2Fmodels%2Finstances%2F%23django.db.models.Model.DoesNotExist\46sa\=
75D\46sntz\0751\46usg\75AFQjCNH9srWjeRThDcht9nkYwGhNnrRYjA';return true=
;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A%2F%2=
Fdocs.djangoproject.com%2Fes%2F1.9%2Fref%2Fmodels%2Finstances%2F%23django.d=
b.models.Model.DoesNotExist\46sa\75D\46sntz\0751\46usg\75AFQjCNH9srWjeRThDc=
ht9nkYwGhNnrRYjA';return true;">borrowed from python's django</a>=
=C2=A0is to inline the exception in the class definition, like this:</div><=
div><br></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wra=
p:break-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#=
660066"><span style=3D"color:#008">class</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Foo</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></=
span><span style=3D"color:#008">public</span><span style=3D"color:#660">:</=
span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#008">class</span><span style=3D"color:#000"> custom_exception </spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">public</span><span style=3D"color:#000"> std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">exception </=
span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#800">/* ... */</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">void</span><span style=3D"c=
olor:#000"> foo</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span=
style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"=
color:#008">throw</span><span style=3D"color:#000"> custom_exception</span>=
<span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"color:#000"=
><br></span><span style=3D"color:#660">};</span></font></div></code></div><=
br>Why does this help? For starters it helps preventing the pollution of th=
e namespace where the exception is being defined.</div></div></blockquote><=
div><br>Right. Because C++ is totally running out of names.<br>=C2=A0</div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Instead,=
the exception is referred to as Foo::custom_exception, which allows to hav=
e Bar::custom_exception (the same name) meaning something different.</div><=
/div></blockquote><div><br>... can you give a concrete example of when that=
would be a good idea? For two exception classes in the same namespace (and=
therefore general project) to have the same name, yet mean wildly differen=
t things?<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr"><div>Secondly, it allows to catch exceptions with respect to th=
e class they are inserted in, such as the following:</div><div><br></div><d=
iv><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;bac=
kground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">try</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span>=
<span style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#80=
0">/* Code that might throw */</span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#008">catch</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">(</span><span style=3D"color:#606">Foo</span><s=
pan style=3D"color:#660">::</span><font color=3D"#000000"><span style=3D"co=
lor:#000">custom_exception </span><span style=3D"color:#660">&</span><s=
pan style=3D"color:#000"> ex</span><span style=3D"color:#660">)</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">{}</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#008">catch</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=
=3D"color:#606">Bar</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">custom_exception </span><span style=3D"color:#660">&</s=
pan><span style=3D"color:#000"> ex</span><span style=3D"color:#660">)</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">{}</span></f=
ont></div></code></div><br>These two exceptions may or may not be related. =
If they are, a common base class can also be used for a "catch all in =
category" approach. This also works with templates:</div><div><br></di=
v><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:#008">t=
emplate</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
><</span><span style=3D"color:#008">class</span><span style=3D"color:#00=
0"> T</span><span style=3D"color:#660">></span><span style=3D"color:#000=
"><br></span><span style=3D"color:#008">class</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">Foo</span><span style=3D"color:#000"=
><br></span><span style=3D"color:#660">{</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#008">public</span><span style=3D"color:#660=
">:</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color:#008">class</span><span style=3D"color:#000"> custom_exception =
</span><span style=3D"color:#660">:</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">public</span><span style=3D"color:#000"> std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#000">excepti=
on </span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#800">/* ... */</span><span style=3D"color:#000">=
</span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span></div></code></div><br>Each Foo t=
emplate instantiation also results in a different instance of custom except=
ion, so this is possible:</div><div><br></div><div><div style=3D"border:1px=
solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,2=
50)"><code><div><font color=3D"#660066"><span style=3D"color:#008">try</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#800">=
/* Code that might throw */</span><span style=3D"color:#000"><br></span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><=
span style=3D"color:#008">catch</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#606">Foo</span><span=
style=3D"color:#080"><int></span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">custom_exception </span><span style=3D"color:#6=
60">&</span><span style=3D"color:#000"> ex</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:#800">/* Ha=
ndle exceptions for int instances of Foo */</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#008">catch</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">(</span><span style=3D"color:#606">Foo</s=
pan><span style=3D"color:#080"><float></span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">custom_exception </span><span style=
=3D"color:#660">&</span><span style=3D"color:#000"> ex</span><span styl=
e=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=
:#800">/* Handle exceptions for float instances of Foo */</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">}</span></font></div></c=
ode></div><br>This is useful, but it's not possible to follow the same =
"catch all in category" approach, which would catch all exception=
s of type Foo<T>::custom_exception, regardless of T. Again, this coul=
d be solved by making them share the same base class, declared outside the =
class definition, probably in some namespace (say, ::std). This obviously d=
efeats the purpose of not polluting the namespace. This is why I though of =
something like this:</div><div><br></div><div><div style=3D"border:1px soli=
d rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)">=
<code><div><font color=3D"#660066"><span style=3D"color:#008">try</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#800">/* Co=
de that might throw */</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><span =
style=3D"color:#008">catch</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">(</span><span style=3D"color:#606">Foo</span><span styl=
e=3D"color:#080"><int></span><span style=3D"color:#660">::</span><spa=
n style=3D"color:#000">custom_exception </span><span style=3D"color:#660">&=
amp;</span><span style=3D"color:#000"> ex</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"> </span><span style=3D"color:#800">/* Handle =
exceptions for int instances of Foo */</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#008">catch</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#008">template</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#008">class</span><span style=3D"color:#000"> T</spa=
n><span style=3D"color:#660">></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">T</span><span style=3D"color:#660">>::</span>=
<span style=3D"color:#000">custom_exception </span><span style=3D"color:#66=
0">&</span><span style=3D"color:#000"> ex</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:#800">/* Han=
dle exceptions for all other instances of Foo */</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">}</span><span style=3D"color:#000=
"><br></span></font></div></code></div><div><br></div></div></div></blockqu=
ote><div><br>Except that's not what this would have to do. You forget t=
hat C++ is a statically typed language, and `Foo` is not a type; it's a=
template. `Foo<T>` is a type, but only for a specific type T.<br><br=
>After all, the compiler doesn't know that `typename Foo<T>::cust=
om_exception` will have the same behavior for all `T`s. Specializations can=
radically change the interface of `Foo` and therefore `Foo<T>::custo=
m_exception`.<br><br>Normally, template code would be instantiated for ever=
y T that is statically used with `Foo`. But you're in a catch block. Th=
e compiler must <i>statically</i> generate code for the catch possibilities=
.. The only way for it to do that is to know which kinds of exceptions could=
possibly be thrown, which `T`s will be used to generate `Foo<T>::cus=
tom_exception`.<br><br>This would require the compiler to introspect into e=
very possible function that could be called by the `try` block to see which=
`Foo<T>` it instantiates, so that the compiler can instantiate a cor=
responding catch block here. And what about virtual calls or other function=
pointer-based calls? How do you know that someone won't pass in a `std=
::function` that fires off some new `Foo<T>::custom_exception`?<br><b=
r>That's not a trivial thing to implement.<br><br>I cordially dislike a=
ttempts by people to encode their own programming habits into the language.=
You don't like declaring your exceptions at namespace scope; I get tha=
t. I don't agree, and I certainly don't agree that we need to add l=
anguage features to make that easier for you to do.<br><br>Especially when =
there's a trivial solution for you: create an appropriate base class. A=
nd if it takes up a namespace scoped name... so be it.<br>=C2=A0</div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div></div><d=
iv>I believe this could be trivially implemented by the compiler: when a te=
mplate expression of this kind is found it generates a base class for all i=
nstances of Foo<T>::custom_exception and replaces the catch expressio=
n with the base class. This does not pollute the namespace and allows defin=
ing something like this in a trivial manner, instead of going through the h=
assle of having to define a custom base class.</div><div><br></div>To be ho=
nest, I haven't given much though to how this would be useful in other =
situations, but maybe you guys can help with that. Does something like this=
exist? Do you think it could be useful?<br></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" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_8430_1033981958.1454896409942--
------=_Part_8429_1503608586.1454896409933--
.
Author: =?UTF-8?Q?Andr=C3=A9?= <andre.francisco@tryhype.co>
Date: Sun, 7 Feb 2016 19:03:39 -0800 (PST)
Raw View
------=_Part_8790_419849791.1454900619673
Content-Type: multipart/alternative;
boundary="----=_Part_8791_1733509499.1454900619673"
------=_Part_8791_1733509499.1454900619673
Content-Type: text/plain; charset=UTF-8
>
> Right. Because C++ is totally running out of names.
No, but that's not the problem with namespace pollution.
.... can you give a concrete example of when that would be a good idea? For
> two exception classes in the same namespace (and therefore general project)
> to have the same name, yet mean wildly different things?
Sure. An exception named *bad_access* used for files and for smart
pointers, or *not_found *for array lookups or files. Heck, *invalid_channel* for
a remote control app with interprocess communication. Should these really
be handled the same way? I usually find it useful to write *file::not_found*
vs *array::not_found *instead of just *not_found* and trying to figure out
what happened there.
The only way for it to do that is to know which kinds of exceptions could
> possibly be thrown, which `T`s will be used to generate
> `Foo<T>::custom_exception`.
Maybe, but the *only way* is quite strong phrasing. Take for instance the
suggestion made by Tony V E to use pattern matching. Will it be simple? I
don't know (as I said I don't), but for sure inspecting the whole tree of
calls doesn't seem like the *only* solution. Besides, for now I'm just
trying to get feedback on the idea and making sure whether it's worth
pursuing.
I cordially dislike attempts by people to encode their own programming
> habits into the language. You don't like declaring your exceptions at
> namespace scope; I get that. I don't agree, and I certainly don't agree
> that we need to add language features to make that easier for you to do.
Am I misinterpreting the purpose of this forum? Isn't this forum also to
get feedback *before *you submit a proposal? The isocpp
<https://isocpp.org/std/submit-a-proposal> website does recommend floating
the idea first and links here, so I'm not trying to make anything standard
yet. Disconsider whether this is a programming habit of mine because,
actually, it isn't. Commonly I don't use this pattern in C++ (if I though
it worked well as C++ currently exists we wouldn't be having this
discussion), although I've used it intensively in python and find it quite
useful. It's a pattern; some patterns are good, some are bad; some work
well in C++, some don't. I'm hoping to get more feedback on this issue and
then we'll see what happens.
I absolutely agree that it shouldn't make it to the standard just to make
it easy for me, which is why I'm asking for feedback. You don't agree:
noted. But if features shouldn't be accepted to make me happy, they
shouldn't be rejected to make you happy either, should they? Please don't
take me the wrong way, but I really missed the point with that observation.
I mean, C++ was born out of paradigms brought from other languages (i.e.
classes) so it can't be that wrong to make suggestions like this one.
I appreciate your feedback, nonetheless.
Best regards!
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_8791_1733509499.1454900619673
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px=
0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); =
border-left-style: solid; padding-left: 1ex;">Right. Because C++ is totally=
running out of names.</blockquote><div><br></div><div>No, but that's n=
ot the problem with namespace pollution.</div><div><br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: =
1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; paddi=
ng-left: 1ex;">... can you give a concrete example of when that would be a =
good idea? For two exception classes in the same namespace (and therefore g=
eneral project) to have the same name, yet mean wildly different things?</b=
lockquote><div><br></div><div>=C2=A0Sure. An exception named <i>bad_access<=
/i>=C2=A0used for files and for smart pointers, or <i>not_found </i>for arr=
ay lookups or files. Heck, <i>invalid_channel</i>=C2=A0for a remote control=
app with interprocess communication.=C2=A0Should these really be handled t=
he same way? I usually find it useful to write <i>file::not_found</i> vs <i=
>array::not_found </i>instead of just <i>not_found</i>=C2=A0and trying to f=
igure out what happened there.</div><div><br></div><blockquote class=3D"gma=
il_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; borde=
r-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1=
ex;">The only way for it to do that is to know which kinds of exceptions co=
uld possibly be thrown, which `T`s will be used to generate `Foo<T>::=
custom_exception`.</blockquote><div><br></div><div>Maybe, but the <u>only=
=C2=A0way</u>=C2=A0is quite strong phrasing. Take for instance the suggesti=
on made by Tony V E to use pattern matching. Will it be simple? I don't=
know (as I said I don't), but for sure inspecting the whole tree of ca=
lls doesn't seem like the <i>only</i>=C2=A0solution. Besides, for now I=
'm just trying to get feedback on the idea and making sure whether it&#=
39;s worth pursuing.</div><div><br></div><blockquote class=3D"gmail_quote" =
style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-col=
or: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">I cor=
dially dislike attempts by people to encode their own programming habits in=
to the language. You don't like declaring your exceptions at namespace =
scope; I get that. I don't agree, and I certainly don't agree that =
we need to add language features to make that easier for you to do.</blockq=
uote><div><br></div><div>Am I misinterpreting the purpose of this forum? Is=
n't this forum also to get feedback <i>before </i>you submit a proposal=
? The <a href=3D"https://isocpp.org/std/submit-a-proposal">isocpp</a>=C2=A0=
website does recommend floating the idea first and links here, so I'm n=
ot trying to make anything standard yet. Disconsider whether this is a prog=
ramming habit of mine because, actually, it isn't. Commonly I don't=
use this pattern in C++ (if I though it worked well as C++ currently exist=
s we wouldn't be having this discussion), although I've used it int=
ensively in python and find it quite useful. It's a pattern; some patte=
rns are good, some are bad; some work well in C++, some don't. I'm =
hoping to get more feedback on this issue and then we'll see what happe=
ns.</div><div><br></div><div>I absolutely agree that it shouldn't make =
it to the standard just to make it easy for me, which is why I'm asking=
for feedback. You don't agree: noted. But if features shouldn't be=
accepted to make me happy, they shouldn't be rejected to make you happ=
y either, should they? Please don't take me the wrong way, but I really=
missed the point with that observation. I mean, C++ was born out of paradi=
gms brought from other languages (i.e. classes) so it can't be that wro=
ng to make suggestions like this one.</div><div><br></div><div>I appreciate=
your feedback, nonetheless.</div><div>Best regards!</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_8791_1733509499.1454900619673--
------=_Part_8790_419849791.1454900619673--
.
Author: David Krauss <potswa@gmail.com>
Date: Mon, 8 Feb 2016 11:34:56 +0800
Raw View
--Apple-Mail=_D6EF1FE0-30F9-4F82-BA12-7F08C17F6CD5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2016=E2=80=9302=E2=80=9308, at 11:03 AM, Andr=C3=A9 <andre.francisco@t=
ryhype.co> wrote:
>=20
> Right. Because C++ is totally running out of names.
>=20
> No, but that's not the problem with namespace pollution.
Namespace pollution is bad, but you can always find a name somewhere. You=
=E2=80=99re proposing a complex template-oriented solution for the simple p=
roblem of having to declare something outside the immediate class.
There can always be a nested namespace impl where pollution isn=E2=80=99t a=
n issue.
> Sure. An exception named bad_access used for files and for smart pointer=
s, or not_found for array lookups or files. Heck, invalid_channel for a rem=
ote control app with interprocess communication. Should these really be han=
dled the same way? I usually find it useful to write file::not_found vs arr=
ay::not_found instead of just not_found and trying to figure out what happe=
ned there.
Such names can be added as typedefs without affecting the type of the excep=
tion.
You wouldn=E2=80=99t want array<int, 10>::not_found and array<int, 11>::not=
_found to be different types. This essentially demands that the actual type=
is declared at namespace scope.
In your example, does anything inside Foo<T>::custom_exception depend on T?=
If not, some experts will disagree with the motivating case.
> Maybe, but the only way is quite strong phrasing. Take for instance the s=
uggestion made by Tony V E to use pattern matching. Will it be simple? I do=
n't know (as I said I don't), but for sure inspecting the whole tree of cal=
ls doesn't seem like the only solution. Besides, for now I'm just trying to=
get feedback on the idea and making sure whether it's worth pursuing.
Not only should you prove that the proposal is implementable, you should qu=
antify when it=E2=80=99s better than the obvious solutions of adding a base=
class and/or hoisting functionality out of the template, and how much bett=
er.
> I cordially dislike attempts by people to encode their own programming ha=
bits into the language. You don't like declaring your exceptions at namespa=
ce scope; I get that. I don't agree, and I certainly don't agree that we ne=
ed to add language features to make that easier for you to do.
>=20
> Am I misinterpreting the purpose of this forum? Isn't this forum also to =
get feedback before you submit a proposal? The isocpp <https://isocpp.org/s=
td/submit-a-proposal> website does recommend floating the idea first and li=
nks here, so I'm not trying to make anything standard yet.
No worries. You=E2=80=99re in the right place, doing the right thing. Note =
that he said =E2=80=9Ccordially=E2=80=9D :v) .
> I absolutely agree that it shouldn't make it to the standard just to make=
it easy for me, which is why I'm asking for feedback. You don't agree: not=
ed. But if features shouldn't be accepted to make me happy, they shouldn't =
be rejected to make you happy either, should they?
To be ultimately accepted, a proposal needs to be correct and popular. On t=
he other hand, one person=E2=80=99s opinion which is expressed vehemently i=
s still just one opinion. It=E2=80=99s up to you to judge the climate.
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
--Apple-Mail=_D6EF1FE0-30F9-4F82-BA12-7F08C17F6CD5
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2016=E2=80=9302=
=E2=80=9308, at 11:03 AM, Andr=C3=A9 <<a href=3D"mailto:andre.francisco@=
tryhype.co" class=3D"">andre.francisco@tryhype.co</a>> wrote:</div><br c=
lass=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=
=3D""><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex;=
border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left=
-style: solid; padding-left: 1ex;">Right. Because C++ is totally running ou=
t of names.</blockquote><div class=3D""><br class=3D""></div><div class=3D"=
">No, but that's not the problem with namespace pollution.</div><div class=
=3D""></div></div></div></blockquote><div><br class=3D""></div><div>Namespa=
ce pollution is bad, but you can always find a name somewhere. You=E2=80=99=
re proposing a complex template-oriented solution for the simple problem of=
having to declare something outside the immediate class.</div><div><br cla=
ss=3D""></div><div>There can always be a nested <font face=3D"Courier"=
class=3D"">namespace impl</font> where pollution isn=E2=80=99t an issue.</=
div><div><br class=3D""></div><blockquote type=3D"cite" class=3D""><div cla=
ss=3D""><div dir=3D"ltr" class=3D""><div class=3D""> Sure. An exceptio=
n named <i class=3D"">bad_access</i> used for files and for smart poin=
ters, or <i class=3D"">not_found </i>for array lookups or files. Heck, <i c=
lass=3D"">invalid_channel</i> for a remote control app with interproce=
ss communication. Should these really be handled the same way? I usual=
ly find it useful to write <i class=3D"">file::not_found</i> vs <i class=3D=
"">array::not_found </i>instead of just <i class=3D"">not_found</i> an=
d trying to figure out what happened there.</div><div class=3D""></div></di=
v></div></blockquote><div><br class=3D""></div><div>Such names can be added=
as typedefs without affecting the type of the exception.</div><div><br cla=
ss=3D""></div><div>You wouldn=E2=80=99t want <font face=3D"Courier" class=
=3D"">array<int, 10>::not_found</font> and <font face=3D"Courier" cla=
ss=3D"">array<int, 11>::not_found</font> to be different types. This =
essentially demands that the actual type is declared at namespace scope.</d=
iv><div><br class=3D""></div><div>In your example, does anything inside&nbs=
p;<font face=3D"Courier" class=3D"">Foo<T>::custom_exception</font> d=
epend on <font face=3D"Courier" class=3D"">T</font>? If not, some experts w=
ill disagree with the motivating case.</div><div><br class=3D""></div><bloc=
kquote type=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D""=
><div class=3D"">Maybe, but the <u class=3D"">only way</u> is qui=
te strong phrasing. Take for instance the suggestion made by Tony V E to us=
e pattern matching. Will it be simple? I don't know (as I said I don't), bu=
t for sure inspecting the whole tree of calls doesn't seem like the <i clas=
s=3D"">only</i> solution. Besides, for now I'm just trying to get feed=
back on the idea and making sure whether it's worth pursuing.</div><div cla=
ss=3D""></div></div></div></blockquote><div><br class=3D""></div><div>Not o=
nly should you prove that the proposal is implementable, you should quantif=
y when it=E2=80=99s better than the obvious solutions of adding a base clas=
s and/or hoisting functionality out of the template, and how much better.</=
div><br class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><di=
v dir=3D"ltr" class=3D""><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204=
, 204); border-left-style: solid; padding-left: 1ex;">I cordially dislike a=
ttempts by people to encode their own programming habits into the language.=
You don't like declaring your exceptions at namespace scope; I get that. I=
don't agree, and I certainly don't agree that we need to add language feat=
ures to make that easier for you to do.</blockquote><div class=3D""><br cla=
ss=3D""></div><div class=3D"">Am I misinterpreting the purpose of this foru=
m? Isn't this forum also to get feedback <i class=3D"">before </i>you submi=
t a proposal? The <a href=3D"https://isocpp.org/std/submit-a-proposal" clas=
s=3D"">isocpp</a> website does recommend floating the idea first and l=
inks here, so I'm not trying to make anything standard yet. </div></div></d=
iv></blockquote><div><br class=3D""></div><div>No worries. You=E2=80=99re i=
n the right place, doing the right thing. Note that he said =E2=80=9Ccordia=
lly=E2=80=9D :v) .</div><br class=3D""><blockquote type=3D"cite" class=3D""=
><div dir=3D"ltr" class=3D""><div class=3D"">I absolutely agree that it sho=
uldn't make it to the standard just to make it easy for me, which is why I'=
m asking for feedback. You don't agree: noted. But if features shouldn't be=
accepted to make me happy, they shouldn't be rejected to make you happy ei=
ther, should they?</div></div></blockquote><div><br class=3D""></div><div>T=
o be ultimately accepted, a proposal needs to be correct <i class=3D"">and<=
/i> popular. On the other hand, one person=E2=80=99s opinion which is =
expressed vehemently is still just one opinion. It=E2=80=99s up to you to j=
udge the climate.</div></div><br class=3D""></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
--Apple-Mail=_D6EF1FE0-30F9-4F82-BA12-7F08C17F6CD5--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 7 Feb 2016 19:43:09 -0800 (PST)
Raw View
------=_Part_8786_964710782.1454902989453
Content-Type: multipart/alternative;
boundary="----=_Part_8787_386717378.1454902989453"
------=_Part_8787_386717378.1454902989453
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, February 7, 2016 at 10:03:40 PM UTC-5, Andr=C3=A9 wrote:
>
> Right. Because C++ is totally running out of names.
>
>
> No, but that's not the problem with namespace pollution.
>
> ... can you give a concrete example of when that would be a good idea? Fo=
r=20
>> two exception classes in the same namespace (and therefore general proje=
ct)=20
>> to have the same name, yet mean wildly different things?
>
>
> Sure. An exception named *bad_access* used for files and for smart=20
> pointers, or *not_found *for array lookups or files.
>
Heck, *invalid_channel* for a remote control app with interprocess=20
> communication. Should these really be handled the same way? I usually fin=
d=20
> it useful to write *file::not_found* vs *array::not_found *instead of=20
> just *not_found* and trying to figure out what happened there.
>
Perhaps you misunderstood my question. I put "in the same namespace (and=20
therefore general project)" in there for a reason. Filesystems would be in=
=20
a different namespace from smart pointers, so your namespace pollution=20
argument doesn't hold water. Same goes for whatever you're doing array=20
lookup into and filesystems. Same goes for your interprocess communication=
=20
system.
Also quite frankly, "not_found" is a terrible name for array indexing=20
failure. At least for an actual array. You're not *searching* for something=
=20
with array indexing. You said "index X", and the array said, "that's not=20
within the array bounds." This is why the exception the standard library=20
has is called `std::out_of_range`.
=20
>
> The only way for it to do that is to know which kinds of exceptions could=
=20
>> possibly be thrown, which `T`s will be used to generate=20
>> `Foo<T>::custom_exception`.
>
>
> Maybe, but the *only way* is quite strong phrasing. Take for instance the=
=20
> suggestion made by Tony V E to use pattern matching. Will it be simple? I=
=20
> don't know (as I said I don't), but for sure inspecting the whole tree of=
=20
> calls doesn't seem like the *only* solution. Besides, for now I'm just=20
> trying to get feedback on the idea and making sure whether it's worth=20
> pursuing.
>
The term "pattern matching" means different things to different people. And=
=20
I'm not sure it applies to template instantiation, as most of the times=20
I've seen it discussed, it is used for runtime operations (doing things=20
based on the state of a variant, etc) not compile-time ones.
As far as I know, pattern matching cannot break static typing. What you're=
=20
wanting does.
I cordially dislike attempts by people to encode their own programming=20
>> habits into the language. You don't like declaring your exceptions at=20
>> namespace scope; I get that. I don't agree, and I certainly don't agree=
=20
>> that we need to add language features to make that easier for you to do.
>
>
> Am I misinterpreting the purpose of this forum? Isn't this forum also to=
=20
> get feedback *before *you submit a proposal?
>
Yes. And I gave you feedback: what you want is generally impossible in C++=
=20
due to static typing, and even if it were possible, it wouldn't be=20
worthwhile.
You can disregard that feedback if you like. But it's there.
Also, if everyone posted their own little pet language features to this=20
forum, we would be inundated by micro-features that aren't generally=20
useful. That's not a good thing.
=20
> The isocpp <https://isocpp.org/std/submit-a-proposal> website does=20
> recommend floating the idea first and links here, so I'm not trying to ma=
ke=20
> anything standard yet. Disconsider whether this is a programming habit of=
=20
> mine because, actually, it isn't. Commonly I don't use this pattern in C+=
+=20
> (if I though it worked well as C++ currently exists we wouldn't be having=
=20
> this discussion), although I've used it intensively in python and find it=
=20
> quite useful. It's a pattern; some patterns are good, some are bad; some=
=20
> work well in C++, some don't. I'm hoping to get more feedback on this iss=
ue=20
> and then we'll see what happens.
>
There's a difference between "a pattern I use" and "a pattern that many C++=
=20
programmers use and I happen to be one".
Macros were a pattern that C programmers used; templates were an attempt to=
=20
make many kinds of macros a fundamental part of the language (it expanded=
=20
from that genesis obviously). Concepts is a pattern that many C++=20
programmers use today. Well, we use a Godawful version of it (`enable_if`).=
=20
The actual Concepts TS makes it a real feature that's easy to use and=20
exceedingly powerful. Many C++ programmers use `std::tie` to uncouple=20
values from a tuple; structured binding as a first-class language feature=
=20
will alleviate the problems in that pattern.
Not every language feature needs to be world-shaking. But a micro-feature=
=20
like this, which serves the needs of a very few users? No.
That's the point of the motivation section of a proposal: to prove that=20
there is a need and that need is significant. My point is that your=20
motivation is *lacking*.
=20
> I absolutely agree that it shouldn't make it to the standard just to make=
=20
> it easy for me, which is why I'm asking for feedback. You don't agree:=20
> noted. But if features shouldn't be accepted to make me happy, they=20
> shouldn't be rejected to make you happy either, should they?
>
No, but you asked for feedback. Why is it wrong for that feedback to be=20
"No, this doesn't help enough people to be worth doing"?
=20
> Please don't take me the wrong way, but I really missed the point with=20
> that observation. I mean, C++ was born out of paradigms brought from othe=
r=20
> languages (i.e. classes) so it can't be that wrong to make suggestions li=
ke=20
> this one.
>
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_8787_386717378.1454902989453
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, February 7, 2016 at 10:03:40 PM UTC-5, Andr=C3=
=A9 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-lef=
t-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padd=
ing-left:1ex">Right. Because C++ is totally running out of names.</blockquo=
te><div><br></div><div>No, but that's not the problem with namespace po=
llution.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,2=
04);border-left-style:solid;padding-left:1ex">... can you give a concrete e=
xample of when that would be a good idea? For two exception classes in the =
same namespace (and therefore general project) to have the same name, yet m=
ean wildly different things?</blockquote><div><br></div><div>=C2=A0Sure. An=
exception named <i>bad_access</i>=C2=A0used for files and for smart pointe=
rs, or <i>not_found </i>for array lookups or files.<br></div></div></blockq=
uote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div> He=
ck, <i>invalid_channel</i>=C2=A0for a remote control app with interprocess =
communication.=C2=A0Should these really be handled the same way? I usually =
find it useful to write <i>file::not_found</i> vs <i>array::not_found </i>i=
nstead of just <i>not_found</i>=C2=A0and trying to figure out what happened=
there.</div></div></blockquote><div><br>Perhaps you misunderstood my quest=
ion. I put "in the same namespace (and
therefore general project)" in there for a reason. Filesystems would =
be
in a different namespace from smart pointers, so your namespace=20
pollution argument doesn't hold water. Same goes for whatever you'r=
e=20
doing array lookup into and filesystems. Same goes for your interprocess co=
mmunication system.<br><br>Also quite frankly, "not_found" is a t=
errible name for array indexing failure. At least for an actual array. You&=
#39;re not <i>searching</i> for something with array indexing. You said &qu=
ot;index X", and the array said, "that's not within the array=
bounds." This is why the exception the standard library has is called=
`std::out_of_range`.<br>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
1ex;"><div dir=3D"ltr"><div><br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb=
(204,204,204);border-left-style:solid;padding-left:1ex">The only way for it=
to do that is to know which kinds of exceptions could possibly be thrown, =
which `T`s will be used to generate `Foo<T>::custom_exception`.</bloc=
kquote><div><br></div><div>Maybe, but the <u>only=C2=A0way</u>=C2=A0is quit=
e strong phrasing. Take for instance the suggestion made by Tony V E to use=
pattern matching. Will it be simple? I don't know (as I said I don'=
;t), but for sure inspecting the whole tree of calls doesn't seem like =
the <i>only</i>=C2=A0solution. Besides, for now I'm just trying to get =
feedback on the idea and making sure whether it's worth pursuing.</div>=
</div></blockquote><div><br>The term "pattern matching" means dif=
ferent things to different people. And I'm not sure it applies to templ=
ate instantiation, as most of the times I've seen it discussed, it is u=
sed for runtime operations (doing things based on the state of a variant, e=
tc) not compile-time ones.<br><br>As far as I know, pattern matching cannot=
break static typing. What you're wanting does.<br><br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><blockquote =
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1=
px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:=
1ex">I cordially dislike attempts by people to encode their own programming=
habits into the language. You don't like declaring your exceptions at =
namespace scope; I get that. I don't agree, and I certainly don't a=
gree that we need to add language features to make that easier for you to d=
o.</blockquote><div><br></div><div>Am I misinterpreting the purpose of this=
forum? Isn't this forum also to get feedback <i>before </i>you submit =
a proposal?</div></div></blockquote><div><br>Yes. And I gave you feedback: =
what you want is generally impossible in C++ due to static typing, and even=
if it were possible, it wouldn't be worthwhile.<br><br>You can disrega=
rd that feedback if you like. But it's there.<br><br>Also, if everyone =
posted their own little pet language features to this forum, we would be in=
undated by micro-features that aren't generally useful. That's not =
a good thing.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr"><div> The <a href=3D"https://isocpp.org/std/submit-a-propos=
al" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http=
s://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Fstd%2Fsubmit-a-propos=
al\46sa\75D\46sntz\0751\46usg\75AFQjCNGlLyCIYYQUZNTTJdUEpCYxvwG8Ig';ret=
urn true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https=
%3A%2F%2Fisocpp.org%2Fstd%2Fsubmit-a-proposal\46sa\75D\46sntz\0751\46usg\75=
AFQjCNGlLyCIYYQUZNTTJdUEpCYxvwG8Ig';return true;">isocpp</a>=C2=A0websi=
te does recommend floating the idea first and links here, so I'm not tr=
ying to make anything standard yet. Disconsider whether this is a programmi=
ng habit of mine because, actually, it isn't. Commonly I don't use =
this pattern in C++ (if I though it worked well as C++ currently exists we =
wouldn't be having this discussion), although I've used it intensiv=
ely in python and find it quite useful. It's a pattern; some patterns a=
re good, some are bad; some work well in C++, some don't. I'm hopin=
g to get more feedback on this issue and then we'll see what happens.</=
div></div></blockquote><div><br>There's a difference between "a pa=
ttern I use" and "a pattern that many C++ programmers use and I h=
appen to be one".<br><br>Macros were a pattern that C programmers used=
; templates were an attempt to make many kinds of macros a fundamental part=
of the language (it expanded from that genesis obviously). Concepts is a p=
attern that many C++ programmers use today. Well, we use a Godawful version=
of it (`enable_if`). The actual Concepts TS makes it a real feature that&#=
39;s easy to use and exceedingly powerful. Many C++ programmers use `std::t=
ie` to uncouple values from a tuple; structured binding as a first-class la=
nguage feature will alleviate the problems in that pattern.<br><br>Not ever=
y language feature needs to be world-shaking. But a micro-feature like this=
, which serves the needs of a very few users? No.<br><br>That's the poi=
nt of the motivation section of a proposal: to prove that there is a need a=
nd that need is significant. My point is that your motivation is <i>lacking=
</i>.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div></div><div>I absolutely agree that it shouldn't make it t=
o the standard just to make it easy for me, which is why I'm asking for=
feedback. You don't agree: noted. But if features shouldn't be acc=
epted to make me happy, they shouldn't be rejected to make you happy ei=
ther, should they?</div></div></blockquote><div><br>No, but you asked for f=
eedback. Why is it wrong for that feedback to be "No, this doesn't=
help enough people to be worth doing"?<br>=C2=A0</div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Please don't take m=
e the wrong way, but I really missed the point with that observation. I mea=
n, C++ was born out of paradigms brought from other languages (i.e. classes=
) so it can't be that wrong to make suggestions like this one.</div></d=
iv></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_8787_386717378.1454902989453--
------=_Part_8786_964710782.1454902989453--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sun, 07 Feb 2016 22:16:38 -0800
Raw View
Em domingo, 7 de fevereiro de 2016, =C3=A0s 15:16:43 PST, Andr=C3=A9 escrev=
eu:
> I believe this could be trivially implemented by the compiler
You're wrong.
> when a
> template expression of this kind is found it generates a base class for a=
ll
> instances of Foo<T>::custom_exception and replaces the catch expression
> with the base class.
After the fact? How is it going to modify classes defined elsewhere, which=
=20
previously had no base class?
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
.
Author: =?UTF-8?Q?Andr=C3=A9?= <andre.francisco@tryhype.co>
Date: Mon, 8 Feb 2016 07:16:51 -0800 (PST)
Raw View
------=_Part_11361_230325548.1454944611302
Content-Type: multipart/alternative;
boundary="----=_Part_11362_615726443.1454944611302"
------=_Part_11362_615726443.1454944611302
Content-Type: text/plain; charset=UTF-8
>
> Perhaps you misunderstood my question. I put "in the same namespace (and
> therefore general project)" in there for a reason. Filesystems would be in
> a different namespace from smart pointers, so your namespace pollution
> argument doesn't hold water. Same goes for whatever you're doing array
> lookup into and filesystems. Same goes for your interprocess communication
> system.
Although your argument makes sense, I think there are situations in which
this is not true. Take STL for instance, in which everything lives in the
::std namespace. I've seen projects living in a single namespace. Whether
that's right or wrong is, of course, a new discussion, but it happens.
Besides, this has been seen put into practice in the actual standard
through ios_base::failure
<http://www.cplusplus.com/reference/ios/ios_base/failure/>, so it has been
used in C++. But I get your argument: namespaces *can* solve this, but so
do name prefixes. Please note, again, this is just a paradigm. It doesn't
harm code and I think that (arguably, as you have stated yourself) it makes
code cleaner.
Also quite frankly, "not_found" is a terrible name for array indexing
> failure. At least for an actual array. You're not *searching* for
> something with array indexing. You said "index X", and the array said,
> "that's not within the array bounds." This is why the exception the
> standard library has is called `std::out_of_range`.
I didn't say indexing, I said lookup. It's quite different and *not_found* seems
appropriate for lookups.
Yes. And I gave you feedback: what you want is generally impossible in C++
> due to static typing, and even if it were possible, it wouldn't be
> worthwhile.
> You can disregard that feedback if you like. But it's there.
I will absolutely not disregard your feedback. It's the best
feedback (quality wise) I've got on this issue so far and I honestly thank
you for it. I also tend to agree that if this is the only problem that my
suggestion solves then it's definitely not worth; as I said myself, a base
class can trivially solve this. It's an idea, and if it doesn't validate,
oh well :)
Also, if everyone posted their own little pet language features to this
> forum, we would be inundated by micro-features that aren't generally
> useful. That's not a good thing.
Again, maybe the ioscpp <https://isocpp.org/std/submit-a-proposal> should
say so, then. It really gives the idea that this is a forum for floating
ideas. If it's not, could you please indicate a more appropriate forum?
That's the point of the motivation section of a proposal: to prove that
> there is a need and that need is significant. My point is that your
> motivation is *lacking*.
>
So far, agreed :)
@Thiago It's not. This has already been discussed and disregard. It was a
poor solution and it's not being considered.
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_11362_615726443.1454944611302
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px=
0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); =
border-left-style: solid; padding-left: 1ex;">Perhaps you misunderstood my =
question. I put "in the same namespace (and therefore general project)=
" in there for a reason. Filesystems would be in a different namespace=
from smart pointers, so your namespace pollution argument doesn't hold=
water. Same goes for whatever you're doing array lookup into and files=
ystems. Same goes for your interprocess communication system.</blockquote><=
div><br></div><div>Although your argument makes sense, I think there are si=
tuations in which this is not true. Take STL for instance, in which everyth=
ing lives in the ::std namespace. I've seen projects living in a single=
namespace. Whether that's right or wrong is, of course, a new discussi=
on, but it happens. Besides, this has been seen put into practice in the ac=
tual standard through <a href=3D"http://www.cplusplus.com/reference/ios/ios=
_base/failure/">ios_base::failure</a>, so it has been used in C++. But I ge=
t your argument: namespaces <i>can</i>=C2=A0solve this, but so do name pref=
ixes. Please note, again, this is just a paradigm. It doesn't harm code=
and I think that (arguably, as you have stated yourself) it makes code cle=
aner.</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin=
: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 20=
4, 204); border-left-style: solid; padding-left: 1ex;">Also quite frankly, =
"not_found" is a terrible name for array indexing failure. At lea=
st for an actual array. You're not=C2=A0<i>searching</i>=C2=A0for somet=
hing with array indexing. You said "index X", and the array said,=
"that's not within the array bounds." This is why the except=
ion the standard library has is called `std::out_of_range`.</blockquote><di=
v><br></div><div>I didn't say indexing, I said lookup. It's quite d=
ifferent and <i>not_found</i>=C2=A0seems appropriate for lookups.</div><div=
><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0=
..8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border=
-left-style: solid; padding-left: 1ex;">Yes. And I gave you feedback: what =
you want is generally impossible in C++ due to static typing, and even if i=
t were possible, it wouldn't be worthwhile.<br>You can disregard that f=
eedback if you like. But it's there.</blockquote><div><br></div><div>I =
will absolutely not disregard your feedback. It's the best feedback=C2=
=A0(quality wise)=C2=A0I've got on this issue so far and I honestly tha=
nk you for it. I also tend to agree that if this is the only problem that m=
y suggestion solves then it's definitely not worth; as I said myself, a=
base class can trivially solve this. It's an idea, and if it doesn'=
;t validate, oh well :)</div><div><br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-=
color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Al=
so, if everyone posted their own little pet language features to this forum=
, we would be inundated by micro-features that aren't generally useful.=
That's not a good thing.</blockquote><div><br></div><div>Again, maybe =
the <a href=3D"https://isocpp.org/std/submit-a-proposal">ioscpp</a>=C2=A0sh=
ould say so, then. It really gives the idea that this is a forum for floati=
ng ideas. If it's not, could you please indicate a more appropriate for=
um?</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin: =
0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204,=
204); border-left-style: solid; padding-left: 1ex;"><div>That's the po=
int of the motivation section of a proposal: to prove that there is a need =
and that need is significant. My point is that your motivation is=C2=A0<i>l=
acking</i>.<br></div></blockquote><div>=C2=A0</div><div>So far, agreed :)</=
div><div><br></div><div>=C2=A0@Thiago It's not. This has already been d=
iscussed and disregard. It was a poor solution and it's not being consi=
dered.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_11362_615726443.1454944611302--
------=_Part_11361_230325548.1454944611302--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 8 Feb 2016 09:17:55 -0800 (PST)
Raw View
------=_Part_971_991389585.1454951875394
Content-Type: multipart/alternative;
boundary="----=_Part_972_730152046.1454951875400"
------=_Part_972_730152046.1454951875400
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, February 8, 2016 at 10:16:51 AM UTC-5, Andr=C3=A9 wrote:
>
> Also, if everyone posted their own little pet language features to this=
=20
>> forum, we would be inundated by micro-features that aren't generally=20
>> useful. That's not a good thing.
>
>
> Again, maybe the ioscpp <https://isocpp.org/std/submit-a-proposal> should=
=20
> say so, then. It really gives the idea that this is a forum for floating=
=20
> ideas. If it's not, could you please indicate a more appropriate forum?
>
Yes, this is a place for "floating ideas". Which you did. And we basically=
=20
said "no" and gave reasons for that.
That's the forum *working*.
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_972_730152046.1454951875400
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, February 8, 2016 at 10:16:51 AM UTC-5, Andr=C3=
=A9 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><di=
v></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style=
:solid;padding-left:1ex">Also, if everyone posted their own little pet lang=
uage features to this forum, we would be inundated by micro-features that a=
ren't generally useful. That's not a good thing.</blockquote><div><=
br></div><div>Again, maybe the <a href=3D"https://isocpp.org/std/submit-a-p=
roposal" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;https://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Fstd%2Fsubmit-a-p=
roposal\46sa\75D\46sntz\0751\46usg\75AFQjCNGlLyCIYYQUZNTTJdUEpCYxvwG8Ig'=
;;return true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75=
https%3A%2F%2Fisocpp.org%2Fstd%2Fsubmit-a-proposal\46sa\75D\46sntz\0751\46u=
sg\75AFQjCNGlLyCIYYQUZNTTJdUEpCYxvwG8Ig';return true;">ioscpp</a>=C2=A0=
should say so, then. It really gives the idea that this is a forum for floa=
ting ideas. If it's not, could you please indicate a more appropriate f=
orum?</div></div></blockquote><div><br>Yes, this is a place for "float=
ing ideas". Which you did. And we basically said "no" and ga=
ve reasons for that.<br><br>That's the forum <i>working</i>.</div></div=
>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_972_730152046.1454951875400--
------=_Part_971_991389585.1454951875394--
.
Author: =?UTF-8?Q?Andr=C3=A9?= <andre.francisco@tryhype.co>
Date: Mon, 8 Feb 2016 09:28:32 -0800 (PST)
Raw View
------=_Part_364_694224969.1454952512752
Content-Type: multipart/alternative;
boundary="----=_Part_365_33360100.1454952512752"
------=_Part_365_33360100.1454952512752
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I'm OK with "no"s, but what you said is that this is not the place to post=
=20
this, now you are saying it is. It's confusing. But I get it: no.
Best regards.
segunda-feira, 8 de Fevereiro de 2016 =C3=A0s 17:17:55 UTC, Nicol Bolas esc=
reveu:
>
> On Monday, February 8, 2016 at 10:16:51 AM UTC-5, Andr=C3=A9 wrote:
>>
>> Also, if everyone posted their own little pet language features to this=
=20
>>> forum, we would be inundated by micro-features that aren't generally=20
>>> useful. That's not a good thing.
>>
>>
>> Again, maybe the ioscpp <https://isocpp.org/std/submit-a-proposal> shoul=
d=20
>> say so, then. It really gives the idea that this is a forum for floating=
=20
>> ideas. If it's not, could you please indicate a more appropriate forum?
>>
>
> Yes, this is a place for "floating ideas". Which you did. And we basicall=
y=20
> said "no" and gave reasons for that.
>
> That's the forum *working*.
>
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_365_33360100.1454952512752
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm OK with "no"s, but what you said is that=
this is not the place to post this, now you are saying it is. It's con=
fusing. But I get it: no.<div><br></div><div>Best regards.<br><br>segunda-f=
eira, 8 de Fevereiro de 2016 =C3=A0s 17:17:55 UTC, Nicol Bolas escreveu:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Monday, Febru=
ary 8, 2016 at 10:16:51 AM UTC-5, Andr=C3=A9 wrote:<blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><div></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-colo=
r:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Also, if every=
one posted their own little pet language features to this forum, we would b=
e inundated by micro-features that aren't generally useful. That's =
not a good thing.</blockquote><div><br></div><div>Again, maybe the <a href=
=3D"https://isocpp.org/std/submit-a-proposal" rel=3D"nofollow" target=3D"_b=
lank" onmousedown=3D"this.href=3D'https://www.google.com/url?q\75https%=
3A%2F%2Fisocpp.org%2Fstd%2Fsubmit-a-proposal\46sa\75D\46sntz\0751\46usg\75A=
FQjCNGlLyCIYYQUZNTTJdUEpCYxvwG8Ig';return true;" onclick=3D"this.href=
=3D'https://www.google.com/url?q\75https%3A%2F%2Fisocpp.org%2Fstd%2Fsub=
mit-a-proposal\46sa\75D\46sntz\0751\46usg\75AFQjCNGlLyCIYYQUZNTTJdUEpCYxvwG=
8Ig';return true;">ioscpp</a>=C2=A0should say so, then. It really gives=
the idea that this is a forum for floating ideas. If it's not, could y=
ou please indicate a more appropriate forum?</div></div></blockquote><div><=
br>Yes, this is a place for "floating ideas". Which you did. And =
we basically said "no" and gave reasons for that.<br><br>That'=
;s the forum <i>working</i>.</div></div></blockquote></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_365_33360100.1454952512752--
------=_Part_364_694224969.1454952512752--
.