Topic: Unnamed LValues
Author: Brent Friedman <fourthgeek@gmail.com>
Date: Fri, 4 Oct 2013 20:01:29 -0500
Raw View
--047d7b11191589bf8a04e7f3f572
Content-Type: text/plain; charset=ISO-8859-1
When using RAII, the need to give the variable an explicit name is
cumbersome and often not useful. I'll use the example of freezing and
thawing in WxWidgets, but the problem is applicable to most any RAII
scenario.
class WxScopeFreeze; //Freeze() in constructor, Thaw() in destructor
WxScopeFreeze Freeze(this);
Later on, I want to freeze an additional widget. I should probably update
and maintain these variable names now.
WxScopeFreeze FreezeThis(this);
WxScopeFreeze FreezeOther(Other);
Unfortunately, omitting the name is no good here. Without a name, the
object lifetime ends at the end of the full expression and we don't get our
scope freezing behavior.
WxScopeFreeze(this); //doesn't live for the full scope
If your object is generated as the result of a function call (esp. for
template argument deduction) then the syntax grows yet still.
auto&& FreezeThis = ScopeFreeze(this);
auto&& FreezeOther = ScopeFreeze(Other);
Let's consider ways to get around this issue. The obvious one would be a
macro.
#define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);
This hides the noise to some extent; you no longer have to think about what
to name this RAII object and there won't be any name clashes as long as you
don't declare multiples on the same line of code. The __COUNTER__ extension
supported by some compilers would give you some alternative. __COUNTER__
would be quite unsafe to use in the name of a variable which you declare in
a header though.
There are more downsides to the macro approach.
* It requires the existence of the macro for every RAII type helper you
want.
* For our safer __LINE__ solution, names can still clash if they were
defined in a separate file (eg, header). These may not generate compilation
errors, but could generate spurious static analysis warnings and confusion
when debugging.
* In a debugger window, you'll see variable names that you never created
and that may be difficult to refer back to.
* Its a macro
Instead of macro invention, how about adding some syntax for unnamed
variables?
You could repurpose auto when used as the name of a variable.
WxScopeFreeze auto(this);
WxScopeFreeze auto(Other);
auto auto{WxScopeFreeze(this)};
In that last example we use type deduction on an unnamed variable. It would
be nice to standardize that idea a bit more, but I'm not sure what the
syntax should be.
We could consider some other keyword to identify unnamed variables.
Unfortunately, the obvious syntax of providing no name is taken as I
mentioned.
= is almost appealing, but wouldn't work well with lambdas. Ideally we can
bind logic to the lifetime of a lambda with unnamed variable syntax.
WxScopeFreeze =(this);
WxScopeFreeze ={Other};
[ ==WxScopeFreeze(this) ](){}; //weird?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--047d7b11191589bf8a04e7f3f572
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">When using RAII, the need to give the variable an explicit=
name is cumbersome and often not useful. I'll use the example of freez=
ing and thawing in WxWidgets, but the problem is applicable to most any RAI=
I scenario.<div>
<br></div><div>class WxScopeFreeze; //Freeze() in constructor, Thaw() in de=
structor=A0</div><div><br></div><div>WxScopeFreeze Freeze(this);</div><div>=
<br></div><div>Later on, I want to freeze an additional widget. I should pr=
obably update and maintain these variable names now.</div>
<div><br></div><div>WxScopeFreeze FreezeThis(this);</div><div>WxScopeFreeze=
FreezeOther(Other);</div><div><br></div><div>Unfortunately, omitting the n=
ame is no good here. Without a name, the object lifetime ends at the end of=
the full expression and we don't get our scope freezing behavior.</div=
>
<div><br></div><div>WxScopeFreeze(this); //doesn't live for the full sc=
ope</div><div><br></div><div>If your object is generated as the result of a=
function call (esp. for template argument deduction) then the syntax grows=
yet still.</div>
<div><br></div><div>auto&& FreezeThis =3D ScopeFreeze(this);</div><=
div>auto&& FreezeOther =3D ScopeFreeze(Other);</div><div><br></div>=
<div><br></div><div>Let's consider ways to get around this issue. The o=
bvious one would be a macro.</div>
<div>#define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);</di=
v><div><br></div><div>This hides the noise to some extent; you no longer ha=
ve to think about what to name this RAII object and there won't be any =
name clashes as long as you don't declare multiples on the same line of=
code. The __COUNTER__ extension supported by some compilers would give you=
some alternative. __COUNTER__ would be quite unsafe to use in the name of =
a variable which you declare in a header though.</div>
<div><br></div><div>There are more downsides to the macro approach.=A0</div=
><div><div>* It requires the existence of the macro for every RAII type hel=
per you want.</div><div>* For our safer __LINE__ solution, names can still =
clash if they were defined in a separate file (eg, header). These may not g=
enerate compilation errors, but could generate spurious static analysis war=
nings and confusion when debugging.</div>
</div><div>* In a debugger window, you'll see variable names that you n=
ever created and that may be difficult to refer back to.</div><div>* Its a =
macro</div><div><br></div><div>Instead of macro invention, how about adding=
some syntax for unnamed variables?</div>
<div><br></div><div>You could repurpose auto when used as the name of a var=
iable.</div><div>WxScopeFreeze auto(this);</div><div>WxScopeFreeze auto(Oth=
er);</div><div>auto auto{WxScopeFreeze(this)};</div><div><br></div><div>
In that last example we use type deduction on an unnamed variable. It would=
be nice to standardize that idea a bit more, but I'm not sure what the=
syntax should be.</div><div><br></div><div><br></div><div>We could conside=
r some other keyword to identify unnamed variables. Unfortunately, the obvi=
ous syntax of providing no name is taken as I mentioned.</div>
<div><br></div><div>=3D is almost appealing, but wouldn't work well wit=
h lambdas. Ideally we can bind logic to the lifetime of a lambda with unnam=
ed variable syntax.</div><div>WxScopeFreeze =3D(this);</div><div>WxScopeFre=
eze =3D{Other};</div>
<div>[ =3D=3DWxScopeFreeze(this) ](){}; //weird?</div><div><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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7b11191589bf8a04e7f3f572--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Fri, 4 Oct 2013 18:33:43 -0700
Raw View
--047d7bf0f67ad78a0804e7f468d5
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Oct 4, 2013 at 6:01 PM, Brent Friedman <fourthgeek@gmail.com> wrote:
> When using RAII, the need to give the variable an explicit name is
> cumbersome and often not useful. I'll use the example of freezing and
> thawing in WxWidgets, but the problem is applicable to most any RAII
> scenario.
>
> class WxScopeFreeze; //Freeze() in constructor, Thaw() in destructor
>
> WxScopeFreeze Freeze(this);
>
> Later on, I want to freeze an additional widget. I should probably update
> and maintain these variable names now.
>
> WxScopeFreeze FreezeThis(this);
> WxScopeFreeze FreezeOther(Other);
>
> Unfortunately, omitting the name is no good here. Without a name, the
> object lifetime ends at the end of the full expression and we don't get our
> scope freezing behavior.
>
> WxScopeFreeze(this); //doesn't live for the full scope
>
> If your object is generated as the result of a function call (esp. for
> template argument deduction) then the syntax grows yet still.
>
> auto&& FreezeThis = ScopeFreeze(this);
> auto&& FreezeOther = ScopeFreeze(Other);
>
>
> Let's consider ways to get around this issue. The obvious one would be a
> macro.
> #define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);
>
> This hides the noise to some extent; you no longer have to think about
> what to name this RAII object and there won't be any name clashes as long
> as you don't declare multiples on the same line of code. The __COUNTER__
> extension supported by some compilers would give you some alternative.
> __COUNTER__ would be quite unsafe to use in the name of a variable which
> you declare in a header though.
>
> There are more downsides to the macro approach.
> * It requires the existence of the macro for every RAII type helper you
> want.
> * For our safer __LINE__ solution, names can still clash if they were
> defined in a separate file (eg, header). These may not generate compilation
> errors, but could generate spurious static analysis warnings and confusion
> when debugging.
> * In a debugger window, you'll see variable names that you never created
> and that may be difficult to refer back to.
> * Its a macro
>
> Instead of macro invention, how about adding some syntax for unnamed
> variables?
>
> You could repurpose auto when used as the name of a variable.
> WxScopeFreeze auto(this);
> WxScopeFreeze auto(Other);
> auto auto{WxScopeFreeze(this)};
>
> In that last example we use type deduction on an unnamed variable. It
> would be nice to standardize that idea a bit more, but I'm not sure what
> the syntax should be.
>
>
> We could consider some other keyword to identify unnamed variables.
> Unfortunately, the obvious syntax of providing no name is taken as I
> mentioned.
>
> = is almost appealing, but wouldn't work well with lambdas. Ideally we can
> bind logic to the lifetime of a lambda with unnamed variable syntax.
> WxScopeFreeze =(this);
> WxScopeFreeze ={Other};
> [ ==WxScopeFreeze(this) ](){}; //weird?
>
The important part in such a construct is the point at which the RAII
object is destroyed. Perhaps the syntax should make that more explicit. How
about:
WxScopeFreeze(this) {
// ...
} // dtor invoked here.
.... or ...
/*template<typename Mutex> std::lock_guard<Mutex> locked(Mutex &);*/
locked(my_mutex) {
}
You can get that effect currently with:
WxScopeFreeze(this), [&]{
// ...
}();
.... although this use of the comma operator is unfamiliar to most, and this
doesn't support control flow leaving the block.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--047d7bf0f67ad78a0804e7f468d5
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Fri, Oct 4, 2013 at 6:01 PM, Brent Friedman <span dir=
=3D"ltr"><<a href=3D"mailto:fourthgeek@gmail.com" target=3D"_blank">four=
thgeek@gmail.com</a>></span> wrote:<br><div class=3D"gmail_extra"><div c=
lass=3D"gmail_quote">
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">When using RAII, the need t=
o give the variable an explicit name is cumbersome and often not useful. I&=
#39;ll use the example of freezing and thawing in WxWidgets, but the proble=
m is applicable to most any RAII scenario.<div>
<br></div><div>class WxScopeFreeze; //Freeze() in constructor, Thaw() in de=
structor=A0</div><div><br></div><div>WxScopeFreeze Freeze(this);</div><div>=
<br></div><div>Later on, I want to freeze an additional widget. I should pr=
obably update and maintain these variable names now.</div>
<div><br></div><div>WxScopeFreeze FreezeThis(this);</div><div>WxScopeFreeze=
FreezeOther(Other);</div><div><br></div><div>Unfortunately, omitting the n=
ame is no good here. Without a name, the object lifetime ends at the end of=
the full expression and we don't get our scope freezing behavior.</div=
>
<div><br></div><div>WxScopeFreeze(this); //doesn't live for the full sc=
ope</div><div><br></div><div>If your object is generated as the result of a=
function call (esp. for template argument deduction) then the syntax grows=
yet still.</div>
<div><br></div><div>auto&& FreezeThis =3D ScopeFreeze(this);</div><=
div>auto&& FreezeOther =3D ScopeFreeze(Other);</div><div><br></div>=
<div><br></div><div>Let's consider ways to get around this issue. The o=
bvious one would be a macro.</div>
<div>#define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);</di=
v><div><br></div><div>This hides the noise to some extent; you no longer ha=
ve to think about what to name this RAII object and there won't be any =
name clashes as long as you don't declare multiples on the same line of=
code. The __COUNTER__ extension supported by some compilers would give you=
some alternative. __COUNTER__ would be quite unsafe to use in the name of =
a variable which you declare in a header though.</div>
<div><br></div><div>There are more downsides to the macro approach.=A0</div=
><div><div>* It requires the existence of the macro for every RAII type hel=
per you want.</div><div>* For our safer __LINE__ solution, names can still =
clash if they were defined in a separate file (eg, header). These may not g=
enerate compilation errors, but could generate spurious static analysis war=
nings and confusion when debugging.</div>
</div><div>* In a debugger window, you'll see variable names that you n=
ever created and that may be difficult to refer back to.</div><div>* Its a =
macro</div><div><br></div><div>Instead of macro invention, how about adding=
some syntax for unnamed variables?</div>
<div><br></div><div>You could repurpose auto when used as the name of a var=
iable.</div><div>WxScopeFreeze auto(this);</div><div>WxScopeFreeze auto(Oth=
er);</div><div>auto auto{WxScopeFreeze(this)};</div><div><br></div><div>
In that last example we use type deduction on an unnamed variable. It would=
be nice to standardize that idea a bit more, but I'm not sure what the=
syntax should be.</div><div><br></div><div><br></div><div>We could conside=
r some other keyword to identify unnamed variables. Unfortunately, the obvi=
ous syntax of providing no name is taken as I mentioned.</div>
<div><br></div><div>=3D is almost appealing, but wouldn't work well wit=
h lambdas. Ideally we can bind logic to the lifetime of a lambda with unnam=
ed variable syntax.</div><div>WxScopeFreeze =3D(this);</div><div>WxScopeFre=
eze =3D{Other};</div>
<div>[ =3D=3DWxScopeFreeze(this) ](){}; //weird?</div></div></blockquote><d=
iv><br></div><div>The important part in such a construct is the point at wh=
ich the RAII object is destroyed. Perhaps the syntax should make that more =
explicit. How about:</div>
<div><br></div><div>=A0 WxScopeFreeze(this) {</div><div>=A0 =A0 // ...</div=
><div>=A0 } // dtor invoked here.</div><div><br></div><div>... or ...</div>=
<div><br></div><div>=A0 /*template<typename Mutex> std::lock_guard<=
;Mutex> locked(Mutex &);*/</div>
<div><br></div><div>=A0 locked(my_mutex) {</div><div>=A0 }</div><div><br></=
div><div>You can get that effect currently with:</div><div><br></div><div>=
=A0 WxScopeFreeze(this), [&]{</div><div>=A0 =A0 // ...</div><div>=A0 }(=
);</div><div>
<br></div><div>... although this use of the comma operator is unfamiliar to=
most, and this doesn't support control flow leaving the block.</div></=
div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7bf0f67ad78a0804e7f468d5--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Fri, 4 Oct 2013 22:06:34 -0400
Raw View
On Fri, Oct 4, 2013 at 9:33 PM, Richard Smith <richard@metafoo.co.uk> wrote:
> /*template<typename Mutex> std::lock_guard<Mutex> locked(Mutex &);*/
>
> locked(my_mutex) {
> }
This reminds me Python's with statement. In C++, it may
look like:
with (expr) {
// ...
}
If you need a name,
with (auto name = expr) {
}
And I can further imagine that this requires a
_compound-statement_, so that we can have
struct A {
A() with (expr) {
}
};
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Fri, 4 Oct 2013 19:16:43 -0700
Raw View
--047d7b677efa9d52de04e7f502a3
Content-Type: text/plain; charset=ISO-8859-1
On Fri, Oct 4, 2013 at 7:06 PM, Zhihao Yuan <zy@miator.net> wrote:
> On Fri, Oct 4, 2013 at 9:33 PM, Richard Smith <richard@metafoo.co.uk>
> wrote:
> > /*template<typename Mutex> std::lock_guard<Mutex> locked(Mutex &);*/
> >
> > locked(my_mutex) {
> > }
>
> This reminds me Python's with statement. In C++, it may
> look like:
>
> with (expr) {
>
The 'using' keyword would be unambiguous here.
> // ...
> }
>
> If you need a name,
>
> with (auto name = expr) {
> }
>
Would this be exactly identical to
{
auto name = expr;
// ...
}
?
> And I can further imagine that this requires a
> _compound-statement_, so that we can have
>
> struct A {
> A() with (expr) {
> }
> };
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--047d7b677efa9d52de04e7f502a3
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Fri, Oct 4, 2013 at 7:06 PM, Zhihao Yuan <span dir=3D"l=
tr"><<a href=3D"mailto:zy@miator.net" target=3D"_blank">zy@miator.net</a=
>></span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">
<div class=3D"im">On Fri, Oct 4, 2013 at 9:33 PM, Richard Smith <<a href=
=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
> =A0 /*template<typename Mutex> std::lock_guard<Mutex> lock=
ed(Mutex &);*/<br>
><br>
> =A0 locked(my_mutex) {<br>
> =A0 }<br>
<br>
</div>This reminds me Python's with statement. =A0In C++, it may<br>
look like:<br>
<br>
=A0 with (expr) {<br></blockquote><div><br></div><div>The 'using' k=
eyword would be unambiguous here.</div><div>=A0</div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">
=A0 =A0 // ...<br>
=A0 }<br>
<br>
=A0 If you need a name,<br>
<br>
=A0 with (auto name =3D expr) {<br>
=A0 }<br></blockquote><div><br></div><div>Would this be exactly identical t=
o</div><div><br></div><div>{</div><div>=A0 auto name =3D expr;</div><div>=
=A0 // ...</div><div>}</div><div><br></div><div>?</div><div>=A0</div><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
solid;padding-left:1ex">
And I can further imagine that this requires a<br>
_compound-statement_, so that we can have<br>
<br>
=A0 struct A {<br>
=A0 =A0 A() with (expr) {<br>
=A0 =A0 }<br>
=A0 };</blockquote></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7b677efa9d52de04e7f502a3--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 09:27:44 +0300
Raw View
--f46d043d6557552af504e7f88467
Content-Type: text/plain; charset=ISO-8859-1
On 5 October 2013 04:01, Brent Friedman <fourthgeek@gmail.com> wrote:
> When using RAII, the need to give the variable an explicit name is
> cumbersome and often not useful. I'll use the
>
Please take a look at
http://cplusplus.github.io/EWG/ewg-active.html#35
It might be a good idea to contact Jeffrey and work with him towards a
solution.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--f46d043d6557552af504e7f88467
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 04:01, Brent Friedman <span dir=3D"ltr"><<a hr=
ef=3D"mailto:fourthgeek@gmail.com" target=3D"_blank">fourthgeek@gmail.com</=
a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">When usi=
ng RAII, the need to give the variable an explicit name is cumbersome and o=
ften not useful. I'll use the </div>
</blockquote><div><br></div><div>Please take a look at<br><a href=3D"http:/=
/cplusplus.github.io/EWG/ewg-active.html#35">http://cplusplus.github.io/EWG=
/ewg-active.html#35</a><br><br></div><div>It might be a good idea to contac=
t Jeffrey and work with him towards a solution.<br>
</div><div><br></div></div><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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--f46d043d6557552af504e7f88467--
.
Author: Brent Friedman <fourthgeek@gmail.com>
Date: Sat, 5 Oct 2013 08:33:14 -0500
Raw View
--047d7b16348dff72a404e7fe7553
Content-Type: text/plain; charset=ISO-8859-1
Neat, thanks Ville.
On Sat, Oct 5, 2013 at 1:27 AM, Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:
>
>
>
> On 5 October 2013 04:01, Brent Friedman <fourthgeek@gmail.com> wrote:
>
>> When using RAII, the need to give the variable an explicit name is
>> cumbersome and often not useful. I'll use the
>>
>
> Please take a look at
> http://cplusplus.github.io/EWG/ewg-active.html#35
>
> It might be a good idea to contact Jeffrey and work with him towards a
> solution.
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--047d7b16348dff72a404e7fe7553
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Neat, thanks Ville.</div><div class=3D"gmail_extra"><br><b=
r><div class=3D"gmail_quote">On Sat, Oct 5, 2013 at 1:27 AM, Ville Voutilai=
nen <span dir=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" ta=
rget=3D"_blank">ville.voutilainen@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><div class=3D"gmail_ext=
ra"><br><br><div class=3D"gmail_quote"><div class=3D"im">On 5 October 2013 =
04:01, Brent Friedman <span dir=3D"ltr"><<a href=3D"mailto:fourthgeek@gm=
ail.com" target=3D"_blank">fourthgeek@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">When usi=
ng RAII, the need to give the variable an explicit name is cumbersome and o=
ften not useful. I'll use the </div>
</blockquote><div><br></div></div><div>Please take a look at<br><a href=3D"=
http://cplusplus.github.io/EWG/ewg-active.html#35" target=3D"_blank">http:/=
/cplusplus.github.io/EWG/ewg-active.html#35</a><br><br></div><div>It might =
be a good idea to contact Jeffrey and work with him towards a solution.<br>
</div><div><br></div></div><br></div></div><div class=3D"HOEnZb"><div class=
=3D"h5">
<p></p>
-- <br>
=A0<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7b16348dff72a404e7fe7553--
.
Author: snk_kid <korcan.hussein@googlemail.com>
Date: Sat, 5 Oct 2013 07:43:31 -0700 (PDT)
Raw View
------=_Part_1061_10966967.1380984211255
Content-Type: text/plain; charset=ISO-8859-1
A simpler solution would be to use plain higher-order functions,
with-function patterns are very common in functional languages, something
like:
template < typename Function >
auto with_freeze(SomeWxWidgetClass* w, Function&& fn) -> decltype(fn())
{
WxScopeFreeze scoped_freeze(w);
return fn();
}
example usage:
with_freeze(this, [&]() -> void
{
with_freeze(other, [&]() -> void
{
// do stuff.
});
});
If you don't like the nesting you may be able to generalize this in various
ways like using variadic templates so it may look more like this:
with_freeze(this, other, [&]() -> void
{
// do stuff.
});
On Saturday, October 5, 2013 2:01:29 AM UTC+1, Brent Friedman wrote:
>
> When using RAII, the need to give the variable an explicit name is
> cumbersome and often not useful. I'll use the example of freezing and
> thawing in WxWidgets, but the problem is applicable to most any RAII
> scenario.
>
> class WxScopeFreeze; //Freeze() in constructor, Thaw() in destructor
>
> WxScopeFreeze Freeze(this);
>
> Later on, I want to freeze an additional widget. I should probably update
> and maintain these variable names now.
>
> WxScopeFreeze FreezeThis(this);
> WxScopeFreeze FreezeOther(Other);
>
> Unfortunately, omitting the name is no good here. Without a name, the
> object lifetime ends at the end of the full expression and we don't get our
> scope freezing behavior.
>
> WxScopeFreeze(this); //doesn't live for the full scope
>
> If your object is generated as the result of a function call (esp. for
> template argument deduction) then the syntax grows yet still.
>
> auto&& FreezeThis = ScopeFreeze(this);
> auto&& FreezeOther = ScopeFreeze(Other);
>
>
> Let's consider ways to get around this issue. The obvious one would be a
> macro.
> #define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);
>
> This hides the noise to some extent; you no longer have to think about
> what to name this RAII object and there won't be any name clashes as long
> as you don't declare multiples on the same line of code. The __COUNTER__
> extension supported by some compilers would give you some alternative.
> __COUNTER__ would be quite unsafe to use in the name of a variable which
> you declare in a header though.
>
> There are more downsides to the macro approach.
> * It requires the existence of the macro for every RAII type helper you
> want.
> * For our safer __LINE__ solution, names can still clash if they were
> defined in a separate file (eg, header). These may not generate compilation
> errors, but could generate spurious static analysis warnings and confusion
> when debugging.
> * In a debugger window, you'll see variable names that you never created
> and that may be difficult to refer back to.
> * Its a macro
>
> Instead of macro invention, how about adding some syntax for unnamed
> variables?
>
> You could repurpose auto when used as the name of a variable.
> WxScopeFreeze auto(this);
> WxScopeFreeze auto(Other);
> auto auto{WxScopeFreeze(this)};
>
> In that last example we use type deduction on an unnamed variable. It
> would be nice to standardize that idea a bit more, but I'm not sure what
> the syntax should be.
>
>
> We could consider some other keyword to identify unnamed variables.
> Unfortunately, the obvious syntax of providing no name is taken as I
> mentioned.
>
> = is almost appealing, but wouldn't work well with lambdas. Ideally we can
> bind logic to the lifetime of a lambda with unnamed variable syntax.
> WxScopeFreeze =(this);
> WxScopeFreeze ={Other};
> [ ==WxScopeFreeze(this) ](){}; //weird?
>
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1061_10966967.1380984211255
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">A simpler solution would be to use plain higher-order func=
tions,=20
with-function patterns are very common in functional languages,=20
something like:<br><br><div class=3D"prettyprint" style=3D"background-color=
: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid=
; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">template</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Function</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: #008;" cla=
ss=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> with_freeze</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">SomeWxWidgetClass</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> w</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">Function</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&&</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> fn</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: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">decltype</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">fn</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">())</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &nbs=
p; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">WxScope=
Freeze</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> sco=
ped_freeze</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">w</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> fn</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></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></span></div></code></div><br>example usage:<b=
r><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpr=
ettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">with_f=
reeze</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">this</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: #660;" c=
lass=3D"styled-by-prettify">-></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; with_freeze</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">other</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: #660;" class=3D"styled-by-prettify">[&]()</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br> </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">// do stuff.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">});</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">});</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>I=
f
you don't like the nesting you may be able to generalize this in=20
various ways like using variadic templates so it may look more like=20
this:<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250,=
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-w=
idth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><code class=3D"prettyprint"><span style=3D"color: #000;=
" class=3D"styled-by-prettify">with_freeze</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">this</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">, </span></code><code class=3D"prettyprint"><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><code class=3D"prettyprint">=
<code class=3D"prettyprint"><span class=3D"styled-by-prettify"></span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">other</span><span clas=
s=3D"styled-by-prettify">,</span></code></code></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;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">-></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></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: #000;" class=3D"styled-by-prettify"></span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">// do stuff.</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></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></code><span style=
=3D"color: #660;" class=3D"styled-by-prettify"></span></div></code></div><b=
r>On Saturday, October 5, 2013 2:01:29 AM UTC+1, Brent Friedman wrote:<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">When using RAII, t=
he need to give the variable an explicit name is cumbersome and often not u=
seful. I'll use the example of freezing and thawing in WxWidgets, but the p=
roblem is applicable to most any RAII scenario.<div>
<br></div><div>class WxScopeFreeze; //Freeze() in constructor, Thaw() in de=
structor </div><div><br></div><div>WxScopeFreeze Freeze(this);</div><d=
iv><br></div><div>Later on, I want to freeze an additional widget. I should=
probably update and maintain these variable names now.</div>
<div><br></div><div>WxScopeFreeze FreezeThis(this);</div><div>WxScopeFreeze=
FreezeOther(Other);</div><div><br></div><div>Unfortunately, omitting the n=
ame is no good here. Without a name, the object lifetime ends at the end of=
the full expression and we don't get our scope freezing behavior.</div>
<div><br></div><div>WxScopeFreeze(this); //doesn't live for the full scope<=
/div><div><br></div><div>If your object is generated as the result of a fun=
ction call (esp. for template argument deduction) then the syntax grows yet=
still.</div>
<div><br></div><div>auto&& FreezeThis =3D ScopeFreeze(this);</div><=
div>auto&& FreezeOther =3D ScopeFreeze(Other);</div><div><br></div>=
<div><br></div><div>Let's consider ways to get around this issue. The obvio=
us one would be a macro.</div>
<div>#define SCOPE_FREEZE(expr) WxScopeFreeze Freeze##__LINE__##(expr);</di=
v><div><br></div><div>This hides the noise to some extent; you no longer ha=
ve to think about what to name this RAII object and there won't be any name=
clashes as long as you don't declare multiples on the same line of code. T=
he __COUNTER__ extension supported by some compilers would give you some al=
ternative. __COUNTER__ would be quite unsafe to use in the name of a variab=
le which you declare in a header though.</div>
<div><br></div><div>There are more downsides to the macro approach. </=
div><div><div>* It requires the existence of the macro for every RAII type =
helper you want.</div><div>* For our safer __LINE__ solution, names can sti=
ll clash if they were defined in a separate file (eg, header). These may no=
t generate compilation errors, but could generate spurious static analysis =
warnings and confusion when debugging.</div>
</div><div>* In a debugger window, you'll see variable names that you never=
created and that may be difficult to refer back to.</div><div>* Its a macr=
o</div><div><br></div><div>Instead of macro invention, how about adding som=
e syntax for unnamed variables?</div>
<div><br></div><div>You could repurpose auto when used as the name of a var=
iable.</div><div>WxScopeFreeze auto(this);</div><div>WxScopeFreeze auto(Oth=
er);</div><div>auto auto{WxScopeFreeze(this)};</div><div><br></div><div>
In that last example we use type deduction on an unnamed variable. It would=
be nice to standardize that idea a bit more, but I'm not sure what the syn=
tax should be.</div><div><br></div><div><br></div><div>We could consider so=
me other keyword to identify unnamed variables. Unfortunately, the obvious =
syntax of providing no name is taken as I mentioned.</div>
<div><br></div><div>=3D is almost appealing, but wouldn't work well with la=
mbdas. Ideally we can bind logic to the lifetime of a lambda with unnamed v=
ariable syntax.</div><div>WxScopeFreeze =3D(this);</div><div>WxScopeFreeze =
=3D{Other};</div>
<div>[ =3D=3DWxScopeFreeze(this) ](){}; //weird?</div><div><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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1061_10966967.1380984211255--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 05 Oct 2013 17:35:17 +0200
Raw View
This is a multi-part message in MIME format.
--------------060309030001090105030400
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 05/10/13 16:43, snk_kid a =E9crit :
> A simpler solution would be to use plain higher-order functions,=20
> with-function patterns are very common in functional languages,=20
> something like:
>
> |
> template<typenameFunction>
> autowith_freeze(SomeWxWidgetClass*w,Function&&fn)->decltype(fn())
> {
> WxScopeFreezescoped_freeze(w);
> returnfn();
> }
> |
>
> example usage:
>
> |
> with_freeze(this,[&]()->void
> {
> with_freeze(other,[&]()->void
> {
> // do stuff.
> });
> });
> |
>
> If you don't like the nesting you may be able to generalize this in=20
> various ways like using variadic templates so it may look more like this:
>
> |
> |with_freeze(this, ||||other,||[&]()->void
> {
> // do stuff.
> });
> |
> |
>
>
All this is useful, but this doesn't support control flow leaving the block=
..
I proposed in [1] let-in statement and anonymous variable. With this=20
extension your PO could write it as
WxScopeFreeze auto(this) *:* WxScopeFreeze auto(Other) *:* {
}
Whether ':' is appropriated to introduce the new variables could be=20
discussed.
if the user has a Freeze function it could be even clearer
auto=3DFreeze(this) : auto=3DFreeze(Other) : {
}
Best,
Vicente
[1] let-in statements and anonymous variables -=20
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/BfAtczj8=
1Kg
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--------------060309030001090105030400
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 05/10/13 16:43, snk_kid a écrit :<br>
</div>
<blockquote
cite="mid:0d9b268f-cd3a-4048-a0a3-50cff02b28ce@isocpp.org"
type="cite">
<div dir="ltr">A simpler solution would be to use plain
higher-order functions, with-function patterns are very common
in functional languages, something like:<br>
<br>
<div class="prettyprint" style="background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">template</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">typename</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Function</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">auto</span><span
style="color: #000;" class="styled-by-prettify">
with_freeze</span><span style="color: #660;"
class="styled-by-prettify">(</span><span style="color:
#606;" class="styled-by-prettify">SomeWxWidgetClass</span><span
style="color: #660;" class="styled-by-prettify">*</span><span
style="color: #000;" class="styled-by-prettify"> w</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Function</span><span
style="color: #660;" class="styled-by-prettify">&&</span><span
style="color: #000;" class="styled-by-prettify"> fn</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">decltype</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">fn</span><span
style="color: #660;" class="styled-by-prettify">())</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #606;"
class="styled-by-prettify">WxScopeFreeze</span><span
style="color: #000;" class="styled-by-prettify">
scoped_freeze</span><span style="color: #660;"
class="styled-by-prettify">(</span><span style="color:
#000;" class="styled-by-prettify">w</span><span
style="color: #660;" class="styled-by-prettify">);</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">return</span><span
style="color: #000;" class="styled-by-prettify"> fn</span><span
style="color: #660;" class="styled-by-prettify">();</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">}</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span></div>
</code></div>
<br>
example usage:<br>
<br>
<div class="prettyprint" style="background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #000;"
class="styled-by-prettify">with_freeze</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #008;" class="styled-by-prettify">this</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">[&]()</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">void</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
with_freeze</span><span style="color: #660;"
class="styled-by-prettify">(</span><span style="color:
#000;" class="styled-by-prettify">other</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">[&]()</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">void</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #800;"
class="styled-by-prettify">// do stuff.</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">});</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">});</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span></div>
</code></div>
<br>
If you don't like the nesting you may be able to generalize this
in various ways like using variadic templates so it may look
more like this:<br>
<br>
<div class="prettyprint" style="background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class="prettyprint">
<div class="subprettyprint"><code class="prettyprint"><span
style="color: #000;" class="styled-by-prettify">with_freeze</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #008;" class="styled-by-prettify">this</span><span
style="color: #660;" class="styled-by-prettify">, </span></code><code
class="prettyprint"><span style="color: #660;"
class="styled-by-prettify"><code class="prettyprint"><code
class="prettyprint"><span
class="styled-by-prettify"></span><span
style="color: #000;" class="styled-by-prettify">other</span><span
class="styled-by-prettify">,</span></code></code></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">[&]()</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">-></span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">void</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #000;"
class="styled-by-prettify"></span><span style="color:
#800;" class="styled-by-prettify">// do stuff.</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">});</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span></code><span style="color: #660;"
class="styled-by-prettify"></span></div>
</code></div>
<br>
</div>
<br>
</blockquote>
All this is useful, but this doesn't support control flow leaving
the block.<br>
<br>
I proposed in [1] let-in statement and anonymous variable. With this
extension your PO could write it as<br>
<br>
<div>WxScopeFreeze auto(this) <b>:</b> WxScopeFreeze auto(Other) <b>:</b>
{<br>
}<br>
</div>
<br>
Whether ':' is appropriated to introduce the new variables could be
discussed.<br>
<br>
if the user has a Freeze function it could be even clearer<br>
<br>
auto=Freeze(this) : auto=Freeze(Other) : { <br>
}<br>
<br>
<br>
Best,<br>
Vicente<br>
<br>
[1]
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<span id="t-t" class="GJHYW0UCIXB">let-in statements and anonymous
variables - </span><a class="moz-txt-link-freetext" href="https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/BfAtczj81Kg">https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/BfAtczj81Kg</a><br>
<br>
</body>
</html>
<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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--------------060309030001090105030400--
.
Author: snk_kid <korcan.hussein@googlemail.com>
Date: Sat, 5 Oct 2013 09:12:13 -0700 (PDT)
Raw View
------=_Part_135_23245467.1380989533643
Content-Type: text/plain; charset=ISO-8859-1
>
> All this is useful, but this doesn't support control flow leaving the
> block.
>
Well you can still use return statements for early exits (at particular
level) and throw exceptions.
You wouldn't be able to jump/goto labels in different scopes and a nesting
of with-functions and/or lambda expressions would make early outs more
difficult/ugly but you get can those back again functionality-wise with
continuations or co-routines for which we may be getting one of those (and
they are both equivalent to each other).
Once you have higher-order functions and Continuation Moands you can
implement (almost) any kind of control flow possible with just functions &
lamdba expressions.
Even without this, this should be more than enough in most cases and like I
was saying earlier, if the nesting of with-functions is too cumbersome you
maybe able to generalize a version with variadic
templates/initializer-lists that lets you write a single with-expression
and only have a single lambda "scope". This was my in my second example.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_135_23245467.1380989533643
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div bgcolor=
=3D"#FFFFFF" text=3D"#000000"><blockquote type=3D"cite">
</blockquote>
All this is useful, but this doesn't support control flow leaving
the block.<br></div></blockquote><div><br>Well you can still use return=
statements for early exits (at particular level) and throw exceptions.<br>=
<br>You wouldn't be able to jump/goto labels in different scopes and a nest=
ing of with-functions and/or lambda expressions would make early outs more =
difficult/ugly but you get can those back again functionality-wise with con=
tinuations or co-routines for which we may be getting one of those (and the=
y are both equivalent to each other).<br><br>Once you have higher-order fun=
ctions and Continuation Moands you can implement (almost) any kind of contr=
ol flow possible with just functions & lamdba expressions.<br><br>Even =
without this, this should be more than enough in most cases and like I was =
saying earlier, if the nesting of with-functions is too cumbersome you may=
be able to generalize a version with variadic templates/initializer-lists t=
hat lets you write a single with-expression and only have a single lambda "=
scope". This was my in my second example.<br><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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_135_23245467.1380989533643--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 05 Oct 2013 18:33:11 +0200
Raw View
This is a multi-part message in MIME format.
--------------080109070501010300010405
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 05/10/13 18:12, snk_kid a =E9crit :
>
> All this is useful, but this doesn't support control flow leaving
> the block.
>
>
> Well you can still use return statements for early exits (at=20
> particular level) and throw exceptions.
>
No return statements will return from the lambda, not from the function=20
calling with.
Vicente
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--------------080109070501010300010405
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 05/10/13 18:12, snk_kid a écrit :<br>
</div>
<blockquote
cite="mid:06e15a1f-0f12-408f-b0cd-077669caeb31@isocpp.org"
type="cite">
<div dir="ltr">
<blockquote class="gmail_quote" style="margin: 0;margin-left:
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<div bgcolor="#FFFFFF" text="#000000">
<blockquote type="cite"> </blockquote>
All this is useful, but this doesn't support control flow
leaving the block.<br>
</div>
</blockquote>
<div><br>
Well you can still use return statements for early exits (at
particular level) and throw exceptions.<br>
<br>
</div>
</div>
</blockquote>
No return statements will return from the lambda, not from the
function calling with.<br>
<br>
Vicente<br>
</body>
</html>
<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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--------------080109070501010300010405--
.
Author: Brent Friedman <fourthgeek@gmail.com>
Date: Sat, 5 Oct 2013 12:06:08 -0500
Raw View
--047d7bdc93ca6c18f304e8016f59
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
What functionality do we get by adding new block statements versus the
original proposal? Presumably adding new block statements carries much more
language risk and implementation time, so what are we getting for that
extra effort? Unless there's a way to attach with/using to an object
lifetime, it would seem to be even less powerful.
I'll use ? as the identifier since auto auto isn't very clear.
int reentry_count;
class SignalScope
{
auto ? =3D scope_increment(reentry_count);
SignalScope();
~SignalScope();
};
This wouldn't naturally extend to using/with without adding yet some new
language construct. RAII should be inherently composable. Of course, the
two ideas aren't completely mutually exclusive.
An additional use case for unnamed lvalues would be to standardize the idea
of an unused parameter. Many projects have to use some sort of macro or
annotation to suppress compiler warnings for unused variables. Often, this
is a cast-to-void.
void f(int p)
{
UNUSED(p);
}
By explicitly stating that the parameter has no name, the compiler can
suppress such warnings. Of course you don't use the variable; it's name is
unfathomable.
void f(int ?)
{
}
On Sat, Oct 5, 2013 at 11:33 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> Le 05/10/13 18:12, snk_kid a =E9crit :
>
> All this is useful, but this doesn't support control flow leaving the
>> block.
>>
>
> Well you can still use return statements for early exits (at particular
> level) and throw exceptions.
>
> No return statements will return from the lambda, not from the function
> calling with.
>
> Vicente
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--047d7bdc93ca6c18f304e8016f59
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>What functionality do we get by adding new block stat=
ements versus the original proposal? Presumably adding new block statements=
carries much more language risk and implementation time, so what are we ge=
tting for that extra effort? Unless there's a way to attach with/using =
to an object lifetime, it would seem to be even less powerful.</div>
<div><div><br></div><div>I'll use ? as the identifier since auto auto i=
sn't very clear.</div><div><br></div><div>int reentry_count;</div><div>=
<br></div><div>class SignalScope</div><div>{</div><div>=A0auto ? =3D scope_=
increment(reentry_count);</div>
<div>=A0SignalScope();</div><div>=A0~SignalScope();</div><div>};</div><div>=
<br></div></div><div>This wouldn't naturally extend to using/with witho=
ut adding yet some new language construct. RAII should be inherently compos=
able. Of course, the two ideas aren't completely mutually exclusive.</d=
iv>
<div><br></div><div>An additional use case for unnamed lvalues would be to =
standardize the idea of an unused parameter. Many projects have to use some=
sort of macro or annotation to suppress compiler warnings for unused varia=
bles. Often, this is a cast-to-void.</div>
<div>void f(int p)<br></div><div>{</div><div>=A0UNUSED(p);</div><div>}</div=
><div><br></div><div>By explicitly stating that the parameter has no name, =
the compiler can suppress such warnings. Of course you don't use the va=
riable; it's name is unfathomable.</div>
<div><br></div><div>void f(int ?)</div><div>{</div><div>}</div><div><br></d=
iv></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On S=
at, Oct 5, 2013 at 11:33 AM, Vicente J. Botet Escriba <span dir=3D"ltr"><=
;<a href=3D"mailto:vicente.botet@wanadoo.fr" target=3D"_blank">vicente.bote=
t@wanadoo.fr</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 05/10/13 18:12, snk_kid a =E9crit=A0:<br>
</div><div class=3D"im">
<blockquote type=3D"cite">
<div dir=3D"ltr">
<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<blockquote type=3D"cite"> </blockquote>
All this is useful, but this doesn't support control flow
leaving the block.<br>
</div>
</blockquote>
<div><br>
Well you can still use return statements for early exits (at
particular level) and throw exceptions.<br>
<br>
</div>
</div>
</blockquote></div>
No return statements will return from the lambda, not from the
function calling with.<span class=3D"HOEnZb"><font color=3D"#888888"><b=
r>
<br>
Vicente<br>
</font></span></div><div class=3D"HOEnZb"><div class=3D"h5">
<p></p>
-- <br>
=A0<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--047d7bdc93ca6c18f304e8016f59--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 05 Oct 2013 20:05:17 +0200
Raw View
Le 05/10/13 19:06, Brent Friedman a =E9crit :
> What functionality do we get by adding new block statements versus the=20
> original proposal? Presumably adding new block statements carries much=20
> more language risk and implementation time, so what are we getting for=20
> that extra effort? Unless there's a way to attach with/using to an=20
> object lifetime, it would seem to be even less powerful.
My post contained two proposals. let-in and anonymous variables.
I find somewhere unfortunately to be forced to add an scope
{
RAI r(...)
return f();
} // ~RAI
With a let-in statement we ca have just
// LET RAI r(...) IN return f();
RAI r(...) : return f();
Vicente
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Sat, 5 Oct 2013 11:35:01 -0700 (PDT)
Raw View
------=_Part_1166_13028468.1380998101584
Content-Type: text/plain; charset=ISO-8859-1
On Saturday, 5 October 2013 19:06:08 UTC+2, Brent Friedman wrote:
>
> An additional use case for unnamed lvalues would be to standardize the
> idea of an unused parameter. Many projects have to use some sort of macro
> or annotation to suppress compiler warnings for unused variables. Often,
> this is a cast-to-void.
> void f(int p)
> {
> UNUSED(p);
> }
>
> By explicitly stating that the parameter has no name, the compiler can
> suppress such warnings. Of course you don't use the variable; it's name is
> unfathomable.
>
> void f(int ?)
> {
> }
>
There's a very easy fix for the unused parameter warning appearing when the
argument is part of the API, but is not used anywhere in the body: just
don't give it a name, as simple as that.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1166_13028468.1380998101584
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, 5 October 2013 19:06:08 UTC+2, Brent =
Friedman 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"><div>An additional use case for unnamed lvalues would be to standardize =
the idea of an unused parameter. Many projects have to use some sort of mac=
ro or annotation to suppress compiler warnings for unused variables. Often,=
this is a cast-to-void.<br></div>
<div>void f(int p)<br></div><div>{</div><div> UNUSED(p);</div><div>}</=
div><div><br></div><div>By explicitly stating that the parameter has no nam=
e, the compiler can suppress such warnings. Of course you don't use the var=
iable; it's name is unfathomable.</div>
<div><br></div><div>void f(int ?)</div><div>{</div><div>}</div></div></bloc=
kquote><div><br></div><div>There's a very easy fix for the unused parameter=
warning appearing when the argument is part of the API, but is not used an=
ywhere in the body: just don't give it a name, as simple as that. </di=
v></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1166_13028468.1380998101584--
.
Author: Jeremiah Willcock <jewillco@crest.iu.edu>
Date: Sat, 5 Oct 2013 15:56:55 -0400 (EDT)
Raw View
On Sat, 5 Oct 2013, Vicente J. Botet Escriba wrote:
> Le 05/10/13 19:06, Brent Friedman a =E9crit :
>> What functionality do we get by adding new block statements versus the=
=20
>> original proposal? Presumably adding new block statements carries much m=
ore=20
>> language risk and implementation time, so what are we getting for that=
=20
>> extra effort? Unless there's a way to attach with/using to an object=20
>> lifetime, it would seem to be even less powerful.
> My post contained two proposals. let-in and anonymous variables.
> I find somewhere unfortunately to be forced to add an scope
>
> {
> RAI r(...)
> return f();
> } // ~RAI
>
> With a let-in statement we ca have just
>
> // LET RAI r(...) IN return f();
> RAI r(...) : return f();
>
> Vicente
The other advantage of a scope statement is for macros that define new=20
variables (think of BOOST_FOREACH, even though that has been replaced by a=
=20
language feature now). The alternative techniques using single-iteration=
=20
for loops (often nested, and that prevent "break" and "continue" inside=20
the declaration block) are much more complicated than having a let-in=20
statement.
-- Jeremiah Willcock
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.